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

How to identify a data reference

Former Member
0 Likes
851

Hi,

Probably a very simple question, but i was not able to find the answer (yet). Hopefully you can help me.

I have a data reference, which is a TYPE REF TO data

In some cases the reference can point to a table and in the other cases it points to a structure.

Now i want to know how i can identify the DATA reference if it is a table or structure?

Regards,

/Peter

In the expample below, how to i know LR_DATATAB is refering to a table and LR_DATASTRUC is refering to a structure?

====example===

REPORT zpval_test01.

TYPES ty_t_t001 TYPE STANDARD TABLE OF t001.

DATA lt_t001 TYPE STANDARD TABLE OF t001.

DATA ls_t001 LIKE LINE OF lt_t001.

DATA lr_datatab TYPE REF TO data.

DATA lr_datastruc TYPE REF TO data.

START-OF-SELECTION.

SELECT *

FROM t001

INTO TABLE lt_t001.

READ TABLE lt_t001 INTO ls_t001

INDEX 1.

CREATE DATA lr_datatab TYPE ty_t_t001.

GET REFERENCE OF lt_t001 INTO lr_datatab.

CREATE DATA lr_datastruc TYPE t001.

GET REFERENCE OF ls_t001 INTO lr_datastruc.

1 ACCEPTED SOLUTION
Read only

AlexanderOv
Product and Topic Expert
Product and Topic Expert
0 Likes
801

Hi,

You can see the example in [documentation|http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]

3 REPLIES 3
Read only

brad_bohn
Active Contributor
0 Likes
801

You can use the RTTI classes to identify the type of reference. For example, using cl_abap_typedescr=>describe_by_data_ref, you would pass either data reference to the call. The received object is declared generally as TYPE REF TO cl_abap_typedescr, but the reference you get back is either an instance of class CL_ABAP_STRUCTDESCR or CL_ABAP_TABLEDESCR.

Read only

AlexanderOv
Product and Topic Expert
Product and Topic Expert
0 Likes
802

Hi,

You can see the example in [documentation|http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3145358411d1829f0000e829fbfe/frameset.htm]

Read only

Former Member
0 Likes
801

Hi all,

DESCRIBE FIELD <l_tab> TYPE l_type. does the thing.

For a table TYPE = h and for a structure TYPE = u.

Thanks all,

Peter