‎2007 Jun 29 7:10 AM
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:
1
2
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.
http://help.sap.com/saphelp_nw2004s/helpdata/en/16/0dce0a0cf711d3b9360000e8353423/frameset.htm
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?
Q3 ] WHAT IS DEREFERENCING?
‎2007 Jun 29 7:20 AM
Hi.
Q1] In the GET REFERENCE statement are we assigning twice, as dref2 has already been assigned in the statement.
Here you are asigning the memory address of <fs1>->col2. You are just replacing the memory address it was previously reffering to with a new memory addrress.
Q2] What is CASTING?
With the addition CASTING you are saying that assign the TYPE of the data that is there in the dref2->* to the FIELD-SYMBOL <fs2>.
Q3 ] WHAT IS DEREFERENCING?
Dereferencing is getting the value from the Memory address to which we have reference it is done using ->* operator.
Regards,
Sesh
‎2007 Jun 29 7:20 AM
Hi.
Q1] In the GET REFERENCE statement are we assigning twice, as dref2 has already been assigned in the statement.
Here you are asigning the memory address of <fs1>->col2. You are just replacing the memory address it was previously reffering to with a new memory addrress.
Q2] What is CASTING?
With the addition CASTING you are saying that assign the TYPE of the data that is there in the dref2->* to the FIELD-SYMBOL <fs2>.
Q3 ] WHAT IS DEREFERENCING?
Dereferencing is getting the value from the Memory address to which we have reference it is done using ->* operator.
Regards,
Sesh