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

Reference type in Data Element

prabukannans
Participant
0 Likes
4,460

Hi Experts,

I am having confusion about How to use the Reference type in Data Element? and when we have to use this Reference type?

Thanks in Advance,

6 REPLIES 6
Read only

FredericGirod
Active Contributor
3,518

When you declare data into a program, you could use two syntax: TYPE or TYPE REF TO ..

You screenshot is like if you are using TYPE REF TO

Most of the time, it is used, when you need to reference an instance of a class.

Read only

Sandra_Rossi
Active Contributor
3,518

frdric.girod This is worth an answer !

Read only

prabukannans
Participant
0 Likes
3,518

TYPE and TYPE REF TO in report program level. but in DDIC 'TYPE REF TO' how can we use?. I am using a class name in a data element but activating the database table is throwing an error.

Read only

matt
Active Contributor
0 Likes
3,518

In programs you might have something like:

DATA a_line_of_t100 TYPE REF TO t100.
LOOP AT t100_Records REFERENCE INTO a_line_of_t100.
   a_line_of_t100->text = to_upper( a_line_of_t100->text ).
ENDLOOP. 

You can define z_ref_to_a_line_of_t100 in the DBIC to be a reference to t100. Then you can use

DATA a_line_of_t100 TYPE z_ref_to_a_line_of_t100.

I use references to pass around data without copying it.

Read only

Sandra_Rossi
Active Contributor
3,518

You cannot use a Reference Type (TYPE REF TO) in a Database Table ! If you want to store a reference, one solution is to make the reference serializable (IF_SERIALIZABLE_OBJECT in its class), define a RAWSTRING column, and serialize the reference to the database column (CALL TRANSFORMATION), and deserialize it when you read it later (CALL TRANSFORMATION in the other direction). But you have other more simple workarounds.

Read only

ThorstenHoefer
Active Contributor
3,518

Ref Types itself doesn't contains data. It's only a pointer to a data object or class instance.

It's reference to the memory of a dataobject.

Therefore, it doesn't make sense to use reference types in database tables, because you want to persist data.

You can use references to modify variable (like an internal table) values indirectly.

For example :

loop at it_data references into r_data.

r_data->field1 = "new value".

endloop.

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abaploop_at_itab_result.htm

or similar to

loop at it_data assigning field-symbol(<wa_data>).

<wa_data>-field1 = "new value".

endloop

in both cases you modify the content in the table at the current row position.

For further information, please check the ABAP Help

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abendata_references.htm