Application Development 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: 

Distinguish between TABLE and REF TO DATA

Former Member
0 Kudos

Hello all,

we have a datafield defined as ANY. This datafield can contain a REF TO DATA to an internal table or a TABLE. Is there a way in ABAP to distinguish at runtime what is in this field?

Thanks in advance

Best regards Dominik

Edited by: Dominik Deimling on Jan 16, 2009 3:00 PM

4 REPLIES 4

Sm1tje
Active Contributor
0 Kudos

For this the Runtime type services are available.

Superclass CL_ABAP_TYPEDESCR and all of its subclasses.

Former Member
0 Kudos

Thanks Micky.

I found an ugly solution like this:

Here field itab1 will be tested.

DATA: abap_desc    TYPE REF TO cl_abap_tabledescr,
        is_data      TYPE abap_bool,
        is_reference type abap_bool.
  TRY .
      abap_desc ?= cl_abap_typedescr=>describe_by_data( itab1 ).
      is_data = abap_desc->applies_to_data( itab1 ).
    CATCH cx_root.
      TRY .
          abap_desc ?= cl_abap_typedescr=>describe_by_data_ref( itab1 ).
      is_reference = abap_desc->APPLIES_TO_DATA_REF( itab1 ).
        CATCH cx_root.
          EXIT.
      ENDTRY.

  ENDTRY.

Is there a more elegant way to do this?

Edited by: Dominik Deimling on Jan 16, 2009 3:32 PM

Sm1tje
Active Contributor
0 Kudos

this was / is kind of what I had in mind as well. Not sure though if there is a more elegant way to do this using the classes mentioned. Unfortunately I do not have the time to figure this out.

But can't you just check the attributes of the CL_ABAP_TYPEDESCR to determine in one step the ABAP_TYPEKIND via instance attribute TYPE_KIND?

Just a suggestion not sure if this will work.

Former Member
0 Kudos

Thanks Micky, I used CL_ABAP_TYPEDESCR as suggested.