Академический Документы
Профессиональный Документы
Культура Документы
************************************************************************
*Internal tables
************************************************************************
DATA: i_tmp(100) OCCURS 0 WITH HEADER LINE. "Split internal table
DATA : i_fields LIKE dd03l OCCURS 0 WITH HEADER LINE.
DATA : i_data(1000) TYPE c OCCURS 0 WITH HEADER LINE.
************************************************************************
*Selection Screen
************************************************************************
PARAMETER : p_table LIKE dd03l-tabname OBLIGATORY.
PARAMETERS: p_file TYPE rlgrap-filename
DEFAULT '/usr/sap/shared/'
OBLIGATORY .
*-----------------------------------------------------------------------
* INCLUDES
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
* At selection-screen
*-----------------------------------------------------------------------
AT SELECTION-SCREEN.
PERFORM validate_app_filename.
perform validate_table.
************************************************************************
*Start-of-selection
************************************************************************
START-OF-SELECTION.
PERFORM open_file.
PERFORM dynamic_table_load.
*---------------------------------------------------------------------*
* FORM open_file *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM open_file.
REFRESH i_data.
OPEN DATASET P_file FOR INPUT IN TEXT MODE.
IF SY-SUBRC <> 0.
MESSAGE I000 WITH 'No file found'.
STOP.
ELSE.
DO.
READ DATASET P_FILE INTO I_DATA.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
APPEND I_DATA.
CLEAR I_DATA.
ENDIF.
ENDDO.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM dynamic_table_load *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM dynamic_table_load.
*---Create a new data object of table specified in parameter (p_table)
*---Reference is stored in dref variable. dref now contains a pointer
*---to newly created object.
CREATE DATA dref TYPE (p_table).
*--Asssign the reference to field-symbol
ASSIGN dref->* TO <fs1>.
LOOP AT i_data.
REFRESH i_tmp.
*--Split each input row data into tokens with Tab delimiter
SPLIT i_data AT v_hex INTO TABLE i_tmp.
* CLEAR .
*---Assign each field of table to field-symbol
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs1> TO <fs2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
READ TABLE i_tmp INDEX sy-index.
IF sy-subrc EQ 0.
<fs2> = i_tmp.
ENDIF.
ENDDO.
*--Now will have all the data - Modify the table
MODIFY (p_table) FROM <fs1>.
ENDLOOP.
clear sy-tfill.
describe table i_data lines sy-tfill.
Write: /'Total number of records loaded from file ',
p_table no-gap, ' are : ', sy-tfill.
ENDFORM. " LOAD_TABLES
*&---------------------------------------------------------------------*
*& Form validate_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM validate_table.
if p_table+0(1) <> 'Y' and
p_table+0(1) <> 'Z'.
message e000(ZF_0) with
'Only custom tables allowed with this utility'.
endif.
ENDFORM. " validate_table
*&---------------------------------------------------------------------*
*& Form validate_app_filename
*&---------------------------------------------------------------------*
* This subroutine is used to validate the application file name
* entered on the selection screen
*----------------------------------------------------------------------*
form validate_app_filename.
data : v_len type i. " To get the length of the file name