Application Development and Automation 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: 
Read only

Create structure dynamically by using table

Former Member
0 Likes
1,514

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
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,249

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
Read only

deependra_shekhawat3
Contributor
0 Likes
1,249

Hi Ella,

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

Thanks

Deependra

Read only

Former Member
0 Likes
1,249

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

Read only

Former Member
0 Likes
1,249

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

Read only

0 Likes
1,249

Hello,

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

Best regards

Ella

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,250

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