01-20-2014 10:46 AM
Hello,
I have a program with a structure which is defined as following:
TYPES:
BEGIN OF test,
0vtype(3) TYPE n,
0calmonth2(2) TYPE n,
0calyear(4) TYPE n,
END OF test.
I'd like to create this structure dynamically. I have a table test_table which contains the objects. How could I create the structure dynamically by using the table?
Thanks in advance.
Best regards
Ella
01-22-2014 7:41 AM
Use CL_ABAP_TYPEDESCR->DESCRIBE_BY_NAME or similar method to get every component description from your itab, then use CL_ABAP_STRUCTDESCR->CREATE to create the structure. There are already some threads and wiki with sample, use search tool.
Regards,
Raymond
01-20-2014 11:03 AM
Hi Ella,
Search on google , Dynamic table using RTTS, there are a lot of example to do it.
Thanks
Deependra
01-20-2014 11:05 AM
data : it_tabdescr type abap_compdescr_tab,
wa_tabdescr type abap_compdescr.
data : ref_table_descr type ref to cl_abap_structdescr.
* Return structure of the table.
ref_table_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_tabdescr[] = ref_table_descr->components[].
01-20-2014 1:30 PM
Hi,
If you have the table then you can create a dynamic structure using that as follows.
FIELD-SYMBOLS: <lfs_rslt> TYPE any,
CREATE DATA lv_ref TYPE Line of Table_name.
ASSIGN lv_ref->* To <lfs_rslt>.
Regards
01-22-2014 7:33 AM
Hello,
but the the table is an internal table. And I get a short dump that the typ is not valid.
Best regards
Ella
01-22-2014 7:41 AM
Use CL_ABAP_TYPEDESCR->DESCRIBE_BY_NAME or similar method to get every component description from your itab, then use CL_ABAP_STRUCTDESCR->CREATE to create the structure. There are already some threads and wiki with sample, use search tool.
Regards,
Raymond