Skip to Content
Former Member
Jun 29, 2007 at 06:10 AM

data ref


Please read this code & answer the following questions

REPORT demo_data_reference.

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 list output is:



This example declares two data reference variables dref1 and dref2. dref1is 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. dref2then 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.

Q1] In the GET REFERENCE statement are we assigning twice, as “dref2” has already been assigned in the statement

“ DREF2 = DREF1 .”

Q2] What is CASTING?