"Non-generic type
DATA ref_int TYPE REF TO i.
ref_int = NEW #( ).
ref_int->* = 123.
"Generic type
DATA ref_generic TYPE REF TO data.
ref_generic = NEW i( ). "Syntax in modern ABAP
CREATE DATA ref_generic TYPE i. "Syntax for older ABAP releases
"As mentioned above, the content of anonymous data objects can only be
"accessed using dereferenced data variables and field symbols.
"The only option to access the variable in older releases was via field symbols.
ASSIGN ref_generic->* TO FIELD-SYMBOL(<fs_generic>).
<fs_generic> = 123.
"An access as the following, as it is possible in modern ABAP, was not possible.
ref_generic->* = 123.
"In modern ABAP, variables and field symbols of the generic types
"'any' and 'data' can be used directly, for example, in LOOP and READ statements.
DATA dref TYPE REF TO data.
CREATE DATA dref TYPE TABLE OF zdemo_abap_carr.
SELECT *
FROM zdemo_abap_carr
INTO TABLE @dref->*.
"Note: In case of a fully generic type, an explicit or implicit index operation
"is not possible (indicated by the examples commented out).
LOOP AT dref->* ASSIGNING FIELD-SYMBOL(<loop>).
...
ENDLOOP.
"LOOP AT dref->* ASSIGNING FIELD-SYMBOL(<loop2>) FROM 1 TO 4.
"ENDLOOP.
"The following examples use a dynamic key specification.
"See more syntax examples below.
READ TABLE dref->* ASSIGNING FIELD-SYMBOL(<read>) WITH KEY ('CARRID') = 'AA'.
"READ TABLE dref->* INDEX 1 ASSIGNING FIELD-SYMBOL(<read2>).
"Table expressions
DATA(line) = CONV zdemo_abap_carr( dref->*[ ('CARRID') = 'AA' ] ).
dref->*[ ('CARRID') = 'AA' ] = VALUE zdemo_abap_carr( BASE dref->*[ ('CARRID') = 'AA' ] carrid = 'XY' ).
dref->*[ ('CARRID') = 'XY' ]-('CARRID') = 'ZZ'.
"Note: As the example uses a fully generic type, explicit or implicit index
"operations are not allowed.
"dref->*[ 1 ]-('CARRID') = 'ZZ'.
"Table functions
DATA(num_tab_lines) = lines( dref->* ).
DATA(idx) = line_index( dref->*[ ('CARRID') = 'LH' ] ).
Serkan AKKAVAK
Computer Engineer BSc
Head of SAP & Software Department
Contact : serkurumsal@yandex.com
0 Comments