Essential for data references is the addition REF TO after TYPE.
Dynamic Creation of Structures
If the type of a structure should be decided on runtime, we can define our target structure as reference to the generic type data.
DATA wa TYPE REF TO data.
To give wa a type we use the statement CREATE DATA. The addition TYPE can be specified by:
Reference:
CREATE DATA wa TYPE kna1
- Static checks are active so it's not possible to create an unknown type
Name:
CREATE DATA wa TYPE (lw_name_as_string)
- The parentheses are needed and
lw_name_as_stringcontains the types name as string.- If the type was not found, an exception of type
CX_SY_CREATE_DATA_ERRORwill be thrown
For instancing dynamically created types the HANDLE addition can be specified. HANDLE receives an object which inherits from CL_ABAP_DATADESCR.
CREATE DATA dref TYPE HANDLE obj
objcan be created using the RunTime Type Services- because
drefis still a datareference, it has to be dereferenced (->*) to be used as datacontainer (normally done via Field-Symbols)