
In ABAP, dynamic programming involves the use of incompletely typed or untyped data objects. This enables generic subroutines and methods to be created that run independently of the types of input data. RTTS (Runtime Type Services) make it possible to handle the properties of types in programs (RTTI Runtime Type Information). A related service is RTTC (Runtime Type Creation), which creates new types when programs are executed and generate corresponding data objects.
Further techniques used in dynamic programming are dynamically specified tokens and the fully generic creation of programs. Both of these techniques need to be applied with care, however, since they can easily raise exceptions in programs. They also present significant security risks when external input is used for dynamic program parts. Appropriate checks must be made, for example using the class cl_abap_dyn_prg, to prevent abuse.
Access to Generic Data Objects
Field symbols have an important task when using generic types. The command ASSIGN COMPONENT can be used with field symbols to access components of incompletely known structures.
Example
The method get_c2_structure of the class cl_my_class gets a reference to a structure that contains at least the integer component c2 but is otherwise unspecified.
DATA struc TYPE REF TO DATA.
FIELD-SYMBOLS: <struc> TYPE DATA,
<comp> TYPE i.
struc = cl_my_class=>get_c2_structure( ).
ASSIGN struc->* TO <struc> CASTING.
ASSIGN COMPONENT 'C2' OF <struc> TO <comp>.
RTTI
Gets data types during program runtime using description methods in type description classes.
Example
Creates an internal table components that contains information about the columns in database table T100.
DATA(components) =
CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name( 'T100' )
)->components.