Entering content frameData References: Example Locate the document in its SAP Library structure


TYPES: BEGIN OF t_struct,
         col1 TYPE i,
         col2 TYPE i,
       END OF t_struct.

DATA: dref1 TYPE REF TO data,
      dref2 TYPE REF TO data.

FIELD-SYMBOLS: <fs1> TYPE t_struct,
               <fs2> TYPE i.

CREATE DATA dref1 TYPE t_struct.
ASSIGN dref1->* TO <fs1>.

<fs1>-col1 = 1.
<fs1>-col2 = 2.

dref2 = dref1.
ASSIGN dref2->* TO <fs2> CASTING.
WRITE / <fs2>.

GET REFERENCE OF <fs1>-col2 INTO dref2.
ASSIGN dref2->* TO <fs2>.
WRITE / <fs2>.

The output is:



This example declares two data reference variables dref1 and dref2. dref1 is used to create a structured dynamic data object. This is dereferenced with the field symbol <fs1>, and values are then assigned to it. dref1 is assigned to dref2. dref2 then points to the structured data object. When dref2 is dereferenced, it is cast to the elementary type i of field symbol <fs2>. Its first component is assigned to the field symbol. GET REFERENCE is then used to get a reference to the second component not the structured data object in dref2. It is dereferenced without casting.





Leaving content frame