Skip to Content
author's profile photo Former Member
Former Member

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:

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?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jun 29, 2007 at 06: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.