Register Login

Subroutine pools - Dynamic program generation

Updated May 18, 2018

This report generates a dynamic program with a form routine called
MY_SUBPOOL. Subroutine polls can not be called directly, you have to call
form routine in the program.

REPORT z_test.

TYPES:
source_line(72).


DATA:
gi_source TYPE STANDARD TABLE OF source_line,
l_prog_name(30) TYPE c,
l_msg(120) TYPE c,
l_line(10) TYPE c,
l_word(10) TYPE c,
l_off(3) TYPE c.

APPEND 'PROGRAM MY_SUBPOOL.' TO gi_source.
APPEND 'FORM WRITE_HALLO.' TO gi_source.
APPEND ' DO 10 TIMES.' TO gi_source.
APPEND ' WRITE: / ''Hello world''.' TO gi_source.
APPEND ' ENDDO.' TO gi_source.

APPEND 'ENDFORM.' TO gi_source.

GENERATE SUBROUTINE POOL gi_source
NAME l_prog_name MESSAGE l_msg LINE l_line
WORD l_word OFFSET l_off.

IF sy-subrc 0.
WRITE : / 'Error', l_msg.
ELSE.
PERFORM write_hallo IN PROGRAM (l_prog_name).
ENDIF.


×