Ansicht
Dokumentation
ABAPGENERATE_SUBROUTINE_POOL - GENERATE SUBROUTINE POOL
General Material Data ROGBILLS - Synchronize billing plansThis documentation is copyright by SAP AG.
GENERATE SUBROUTINE POOL
GENERATE SUBROUTINE POOL itab NAME prog $[error_handling$].
Effect
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 session. The eight-character name of the temporary subroutine pool is assigned to the variable prog. The following can be specified for prog:
- An existing character-like variable
- An inline declaration DATA(var) or FINAL(var), where a variable of type PROGNAME is declared.
For itab, only a standard table without secondary table keys is allowed. The line type of itab must be character-like. A line of source code in itab can have no more than 255 characters. For line types with a fixed length, trailing blanks are ignored. In an internal session, a maximum of 36 temporary subroutine pools can be created.
If the source code in itab has a syntax error, the subroutine pool is not generated and prog is initialized. The addition error_handling can be used to analyze syntax errors and generation errors. For the syntax check, the switch configuration of Switch Framework is used as it was when the current transaction was called.
If an exception is raised when the subroutine pool is generated, the runtime error is handled internally so that no programs are terminated and sy-subrc is set to the value 8 instead. However, there is still a database rollback and the corresponding short dump is saved as regular. The addition SHORTDUMP-ID can be used to determine the ID of the runtime error.
Subroutines defined in the source code of the subroutine pool can be called from all programs that are
loaded in the same internal session by specifying the program name prog using the statement
PERFORM. When a subroutine is called for the first time in the subroutine pool, this is loaded
into the internal session, and the event LOAD-OF-PROGRAM is raised.
System Fields
sy-subrc | Meaning |
0 | Generation was successful. |
4 | The source code contains a syntax error. |
8 | A generation error occurred. The resulting runtime error was handled internally. |
If a runtime error occurs during the generation process (sy-subrc has the value 8), a database rollback is executed as usual.
Generic Programming See ABAP Command Injections.
Notes
- Since subroutines are now obsolete as a method of program modularization, a temporary subroutine pool created using 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.
- The syntax rules of the ABAP language version of the creating program also apply to the subroutine pool created.
- Using the switch configuration available when the transaction was called for the syntax check ensures that the entire 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 program-initiating statement.
- In a temporary subroutine pool, the same global declarations and processing blocks can be defined as in the static subroutine pool of the repository (see table of program types).
- The addition REDUCED FUNCTIONALITY of the statement that introduces the program PROGRAM also works in temporary subroutine pools and its use is recommended in order to reduce their resource consumption.
- Temporarily created subroutine pools can be executed in the ABAP Debugger in single steps.
- A temporary subroutine pool created for an internal session cannot be deleted explicitly. It remains available from the time it is created up to the point where the internal session is closed.
- The eight-character internal name of a temporary subroutine pool begins with "%_T". This prefix is reserved for temporary subroutine pools.
- 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
Creates and dynamically generates 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.
Example
Creates and dynamically generates 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.
Example
Creates and dynamically generates 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.
Exceptions
Catchable Exceptions
- Cause: No further temporary subroutine pools can be generated.
Runtime Error: GENERATE_SUBPOOL_DIR_FULL
- Cause: The source code is in a table consisting of strings and the table contains lines with more than 255 characters.
Runtime Error: GEN_SOURCE_TOO_WIDE
Vendor Master (General Section) ROGBILLS - Synchronize billing plans
This documentation is copyright by SAP AG.
Length: 9164 Date: 20240426 Time: 165538 sap01-206 ( 116 ms )