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: 

Dynamic table as parameter - checking type

emil_lazarski
Explorer

Hi,

I recently came across an interesting mind-boggling issue.

Let's assume, we have a method that as one of the parameters has a table type TABLE.

During the runtime, one can check the type of the Table passed to the method in a pretty straightforward way.

DATA(typedescr) = cl_abap_typedescr=>describe_by_data( it_table ).
DATA(outtype) = typedescr->absolute_name.

As a result we have the absolute type of it_table which is fine.

However, how can we check if the input table is of type f.ex. lty_ztype.

        TYPES: BEGIN OF lty_ztype ,
                    first TYPE CHAR12
        TYPES END OF lty_ztype.

In case of the classes and objects we have keywords IS INSTANCE OF.
The above case can happen if we have a generic method used to process different table types in specific ways.

How can we handle such case?

Thanks!

1 ACCEPTED SOLUTION

emil_lazarski
Explorer
0 Kudos

After some debugging I found a way:

DATA table_d type ref to cl_abap_tabledescr.
        table_d ?= CL_ABAP_TYPEDESCR=>describe_by_data( it_user_list ).
        DATA(line_descr) = table_d->get_table_line_type( ).


it is in ABSOLUTE_NAME (\TYPE = ...)

3 REPLIES 3

matt
Active Contributor
0 Kudos

Not on a system at the moment but wouldn't something like this work?

CREATE DATA line_of_table LIKE LINE OF it_table.
ASSIGN line_of_table TO FIELD-SYMBOL(<line>).

DATA(typedescr) = cl_abap_typedescr=>describe_by_data( <line> ).

But I do feel that there is a way directly from DATA(typedescr) = cl_abap_typedescr=>describe_by_data( it_table )

emil_lazarski
Explorer
0 Kudos

After some debugging I found a way:

DATA table_d type ref to cl_abap_tabledescr.
        table_d ?= CL_ABAP_TYPEDESCR=>describe_by_data( it_user_list ).
        DATA(line_descr) = table_d->get_table_line_type( ).


it is in ABSOLUTE_NAME (\TYPE = ...)

or in method GET_RELATIVE_NAME( ).