2020 May 20 4:37 PM
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!
2020 May 20 5:21 PM
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 = ...)
2020 May 20 5:20 PM
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 )
2020 May 20 5:21 PM
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 = ...)
2020 May 20 6:09 PM