Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

need help on a simple sample of using type ref to

raffinkira
Participant
0 Likes
1,895

DATA: l_abc(10) type C.

l_abc = 'xxx'.

DATA dref1 TYPE REF TO data,

GET REFERENCE OF l_abc INTO dref1.

then how can I get the access of the content of 'dref1', namely 'xxx'?

I have tried many forms with 'dref' but didnt work it out.

I know I can assign it to a field-symbol and then use the field symbol.

but this goes for another question, why not use field-symbol directly instead of doing such a complicated thing?

1 ACCEPTED SOLUTION
Read only

former_member220538
Active Participant
0 Likes
1,461

Hi Ming,

dref is  data reference variable.The actual contents of a reference variable ie the value of a reference is not visible in an ABAP program.To access the contents of the data object to which a data reference is pointing, you must dereference it.

ASSIGN dref->* TO <fs> [CASTING ...].

DATA: l_abc(10) type C.

l_abc = 'xxx'.

DATA dref TYPE REF TO char10.

GET REFERENCE OF l_abc INTO dref.

WRITE / dref->*.

http://help.sap.com/abapdocu_702/en/abapget_reference.htm

6 REPLIES 6
Read only

raffinkira
Participant
0 Likes
1,461

OK, I think I found the answer on another website.

It is NOT allowed to get the access of the content of 'dref1' directly(if it refers to a simple data type),

we have to assign it into a FS.

So now who can explain the benefits of doing such a thing instead of using FS directly?

Read only

ramkumar007
Participant
0 Likes
1,461

        The field symbol <FS> can have data objects of any time assigned to it. When you assign a data object, the field symbol inherits its technical attributes. The data type of the assigned data object becomes the actual data type of the field symbol

Read only

Former Member
0 Likes
1,461

Use this:

DATA: dref TYPE REF TO data.

FIELD-SYMBOLS: <w_abcd>      TYPE ty_abcd.


CREATE DATA dref LIKE <w_abcd>.
ASSIGN dref->*   TO      <w_abcd>.

Regards

Vivek

Read only

Former Member
0 Likes
1,461

Hi Ming ,

You can actually look into this link for a idea ,

http://www.teamabap.com/2013/01/field-sym-and-data-references/

Regards ,

Shiv

Read only

former_member220538
Active Participant
0 Likes
1,462

Hi Ming,

dref is  data reference variable.The actual contents of a reference variable ie the value of a reference is not visible in an ABAP program.To access the contents of the data object to which a data reference is pointing, you must dereference it.

ASSIGN dref->* TO <fs> [CASTING ...].

DATA: l_abc(10) type C.

l_abc = 'xxx'.

DATA dref TYPE REF TO char10.

GET REFERENCE OF l_abc INTO dref.

WRITE / dref->*.

http://help.sap.com/abapdocu_702/en/abapget_reference.htm

Read only

0 Likes
1,461

Thanks, this is exactly what I want.

If you want to use dref->* directly, you need TYPE REF TO a specific type.