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: 

Create structure dynamically by using table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

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

5 REPLIES 5

deependra_shekhawat3
Contributor
0 Kudos

Hi Ella,

Search on google , Dynamic table using RTTS, there are a lot of example to do it.

Thanks

Deependra

Former Member
0 Kudos

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[].

Former Member
0 Kudos

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

0 Kudos

Hello,

but the the table is an internal table. And I get a short dump that the typ is not valid.

Best regards

Ella

raymond_giuseppi
Active Contributor
0 Kudos

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