GENERATE
SUBROUTINE POOL should only contain a single initial subroutine that
calls a method of a local class and does not contain any other
functional code.
If the program that creates the subroutine pool is a
Unicode program , the corresponding
syntax rules apply for the generated subroutine pool.
Using the switch configuration from when the transaction was called
for the syntax check ensures that the whole transaction is executed
using the same switch configuration (guaranteed by Switch Framework).
The source code in the internal table itab must contain a
complete ABAP program, including the
statement that introduces the
program .
In a temporary subroutine pool, the same global declarations and
editing rules are defined as in the static subroutine pool of the r
epository (see table of program types ).
The addition REDUCED FUNCTIONALITY of the introductory program
statement PROGRAM also works in temporary
subroutine pools and is recommended to reduce their resource use.
Temporarily generated subroutine pools can be executed in ABAP
Debugger in single steps.
A temporary subroutine pool generated for an internal mode cannot be
deleted explicitly. It remains available from its generation up to the
point where the internal session is terminated.
GENERATE SUBROUTINE POOL should only be used in exceptional
cases in application programs. ABAP provides many other means of dynamic
programming, which generally make creating source code dynamically
unnecessary (see the list in dynamic
program processing ).
Example ABAP Coding Creates and generates (dynamically) a subroutine pool
that implements the event block LOAD-OF-PROGRAM and two
subroutines. Depending on the return code sy-subrc , a subroutine
is called or a message is issued.
DATA tab TYPE STANDARD TABLE OF string WITH EMPTY KEY.
tab = VALUE #(
( `PROGRAM subpool.` )
( `DATA spfli_tab TYPE TABLE OF spfli.` )
( `LOAD-OF-PROGRAM.` )
( ` SELECT *` <(> <)>
` FROM spfli` <(> <)>
` INTO TABLE spfli_tab.` )
( `FORM loop_at_tab.` )
( ` DATA spfli_wa TYPE spfli.` )
( ` LOOP AT spfli_tab INTO spfli_wa.` )
( ` PERFORM evaluate_wa USING spfli_wa.` )
( ` ENDLOOP.` )
( `ENDFORM.` )
( `FORM evaluate_wa USING l_wa TYPE spfli.` )
( ` cl_demo_output=>write_data( l_wa ).` )
( `ENDFORM.` ) ).
GENERATE SUBROUTINE POOL tab NAME DATA(prog)
MESSAGE DATA(mess)
SHORTDUMP-ID DATA(sid).
IF sy-subrc = 0.
PERFORM ('LOOP_AT_TAB') IN PROGRAM (prog) IF FOUND.
cl_demo_output=>display( ).
ELSEIF sy-subrc = 4.
MESSAGE mess TYPE 'I'.
ELSEIF sy-subrc = 8.
MESSAGE sid TYPE 'I'.
ENDIF.
Example ABAP Coding Creates and generates (dynamically) a subroutine pool
that implements a local class. The static method meth of the
class can be called using the absolute
type name of the class.
DATA itab TYPE TABLE OF 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 DATA(prog).
class = `\PROGRAM=` <(> <)><(> <)> prog <(> <)><(> <)> `\CLASS=MAIN`.
CALL METHOD (class)=>meth.
Example ABAP Coding Creates and generates (dynamically) a subroutine pool
that implements a local class. The class is instantiated using its
absolute type name , and the
instance method meth is called dynamically.
DATA itab TYPE TABLE OF 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 DATA(prog).
class = `\PROGRAM=` <(> <)><(> <)> prog <(> <)><(> <)> `\CLASS=MAIN`.
CREATE OBJECT oref TYPE (class).
CALL METHOD oref->('METH').
Example ABAP Coding See also Program
Generation .
Runtime Exceptions
Catchable Exceptions
CX_SY_GENERATE_SUBPOOL_FULL
Reason for error: No further temporary subroutine pools can be generated.
Runtime error: GENERATE_SUBPOOL_DIR_FULL
CX_SY_GEN_SOURCE_TOO_WIDE
Reason for error: The source code is in a table consisting of strings and
the table contains rows with more than 255 characters.
Runtime error: GEN_SOURCE_TOO_WIDE
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved