Skip to Content
author's profile photo Former Member
Former Member

Create structure dynamically by using table

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Jan 22, 2014 at 07: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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 20, 2014 at 11:03 AM

    Hi Ella,

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

    Thanks

    Deependra

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 20, 2014 at 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[].

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 20, 2014 at 01: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.