Below you can find an example of dynamically creating source-code.
For my example, I created a program that allows you to fill in a tablename and that removes all the content of the table that you've filled in.
Don't try this @ home, unless you know what you are doing.
REPORT ZHR_DELETE_TABLE_CONTENT.
DATA: lt_code(100) TYPE c OCCURS 0 WITH HEADER LINE,
lv_repid LIKE sy-repid,
mess TYPE string,
sid TYPE string.
PARAMETERS: p_table TYPE string OBLIGATORY.
INITIALIZATION.
IF sy-uname NE 'VERSTOCT'.
MESSAGE 'PROGRAM NOT ALLOWED FOR THIS USER' TYPE 'E'.
ENDIF.
IF sy-sysid NE 'DEV'.
MESSAGE 'PROGRAM NOT ALLOWED ON THIS SYSTEM' TYPE 'E'.
ENDIF.
START-OF-SELECTION.
REFRESH lt_code.
lt_code = 'PROGRAM TEMP.'.
APPEND lt_code.
lt_code = 'FORM DELETE_TAB.'.
APPEND lt_code.
CONCATENATE 'DELETE FROM' p_table '.' INTO lt_code SEPARATED BY space.
APPEND lt_code.
MOVE 'COMMIT WORK.' TO lt_code.
APPEND lt_code.
lt_code = 'ENDFORM.'.
APPEND lt_code.
GENERATE SUBROUTINE POOL lt_code NAME lv_repid
MESSAGE mess
SHORTDUMP-ID sid.
PERFORM ('DELETE_TAB') IN PROGRAM (lv_repid).
WRITE: / 'The content of table <', p_table, '> is gone.'.
Geen opmerkingen:
Een reactie posten