GENERATE SUBROUTINE POOL itab NAME prog [error_handling].
This statement generates a temporary subroutine pool. The source code of the subroutine pool is taken from the internal table itab. The generated subroutine pool is stored internally in the current internal mode. The eight-character name of the temporary subroutine pool is assigned to the variable prog.
The line type for itab must be character type (prior to Release 6.10 flat). A source code line in itab may contain a maximum of 255 characters. The data object prog must also be character type (prior to Release 6.10 flat). In an internal mode, a maximum of 36 temporary subroutine pools may be created.
If the source text contained in itab has a syntax error, the subroutine pool is not generated and initialized using prog. Using the addition error_handling, syntax and generation errors can be analyzed. Syntax errors can either occur in the source code specified in itab or in the include programs included using the statement INCLUDE. check. For the syntax check, the switch configuration of the Switch Framework in its current status when the transaction was called.
In the source code of the subroutine pool, subroutines can be called from all programs that are loaded
in the same internal mode by specifying the program name prog
using the statement PERFORM.
At the first call of a subroutine in the subroutine pool, this is loaded into internal mode, whereby
the event LOAD-OF-PROGRAM is initialized.
System Fields
sy-subrc | Meaning |
0 | Generation was successful. |
4 | Source code contains a syntax error. |
8 | A generation error occurred. |
Dynamic creation and generation of a subroutine pool that implements the event block LOAD-OF-PROGRAM and two subroutines. Depending on the return value sy-subrc, a subroutine is called or a message is issued.
DATA: prog TYPE string,
tab TYPE STANDARD TABLE OF string,
mess TYPE string,
sid TYPE string.
APPEND 'PROGRAM subpool.' TO tab.
APPEND `DATA spfli_tab TYPE TABLE OF spfli.` TO tab.
APPEND `LOAD-OF-PROGRAM.`
TO tab.
APPEND ` SELECT *` &
` FROM spfli` &
` INTO TABLE spfli_tab.` TO tab.
APPEND `FORM loop_at_tab.` TO tab.
APPEND ` DATA spfli_wa TYPE spfli.` TO tab.
APPEND ` LOOP AT spfli_tab INTO spfli_wa.` TO tab.
APPEND ` PERFORM evaluate_wa USING spfli_wa.` TO tab.
APPEND ` ENDLOOP.`
TO tab.
APPEND `ENDFORM.`
TO tab.
APPEND `FORM evaluate_wa USING l_wa TYPE spfli.` TO tab.
APPEND ` WRITE: / l_wa-carrid, l_wa-connid.` TO tab.
APPEND `ENDFORM.`
TO tab.
GENERATE SUBROUTINE POOL tab NAME prog
MESSAGE mess
SHORTDUMP-ID sid.
IF sy-subrc = 0.
PERFORM ('LOOP_AT_TAB') IN PROGRAM (prog) IF FOUND.
ELSEIF sy-subrc = 4.
MESSAGE mess TYPE 'I'.
ELSEIF sy-subrc = 8.
MESSAGE sid TYPE 'I'.
ENDIF.
Dynamic creation and generation of a subroutine pool that implements a local class. The static method meth of the class can be called with the absolute type name of the class.
DATA itab TYPE TABLE OF string.
DATA prog TYPE string.
DATA class TYPE string.
APPEND `program.` TO itab.
APPEND `class main definition.` TO itab.
APPEND ` public section.` TO itab.
APPEND ` class-methods meth.` TO itab.
APPEND `endclass.`
TO itab.
APPEND `class main implementation.` TO itab.
APPEND ` method meth.` TO itab.
APPEND ` message 'Test' type 'I'.` TO itab.
APPEND ` endmethod.`
TO itab.
APPEND `endclass.` TO itab.
GENERATE SUBROUTINE POOL itab NAME prog.
CONCATENATE `\PROGRAM=` prog `\CLASS=MAIN` INTO class.
CALL METHOD (class)=>meth.
Dynamic creation and generation of a subroutine pool that implements a local class. The class is instanced with its absolute type name, and the instance method meth is called dynamically.
DATA itab TYPE TABLE OF string.
DATA prog TYPE string.
DATA class TYPE string.
DATA oref TYPE REF TO object.
APPEND `program.` TO itab.
APPEND `class main definition.` TO itab.
APPEND ` public section.` TO itab.
APPEND ` methods meth.` TO itab.
APPEND `endclass.` TO itab.
APPEND `class main implementation.` TO itab.
APPEND ` method meth.` TO itab.
APPEND ` message 'Test' type 'I'.` TO itab.
APPEND ` endmethod.`
TO itab.
APPEND `endclass.` TO itab.
GENERATE SUBROUTINE POOL itab NAME prog.
CONCATENATE `\PROGRAM=` prog `\CLASS=MAIN` INTO class.
CREATE OBJECT oref TYPE (class).
CALL METHOD oref->('METH').
Catchable Exceptions
CX_SY_GENERATE_SUBPOOL_FULL
CX_SY_GEN_SOURCE_TOO_WIDE