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

building table dynamically

Hi folks!

Does anybody know whether it is possible to build an internal table from DDIC-structures dynamically?

I have a deep structured itab_upload(whose structure is defined in the DDIC), which contains 2 fields(Number Name) and a third field which contains itab_desc.

This itab_desc can contain either 2 fields(Number Name) and a third field which contains another itab_desc or 3 fields for numbers(without any other itab).If itab_desc contains another itab_desc, the second itab_desc contains only 3 fields for numbers and names...

help will be very appreciated and points will be rewarded!

Felix

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 09:06 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 09:09 AM

    Hi,

    Look bellow sample program

    report ytest.

    data: lt_fieldcatalog type lvc_t_fcat.

    data: ls_fieldcatalog type lvc_s_fcat.

    field-symbols: <fs_data> type ref to data.

    field-symbols: <fs_1>.

    field-symbols: <fs_2> type any table.

    field-symbols: <fs_3> type ypoll.

    data: lt_data type ref to data.

    assign lt_data to <fs_data>.

    ls_fieldcatalog-fieldname = 'MANDT'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'POLLID'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'TEAM'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'INITIATOR'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'DESCRIPTION'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'APPROVED'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'INITIATED_DATE'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'END_DATE'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    ls_fieldcatalog-fieldname = 'WINNER'.

    ls_fieldcatalog-tabname = 'LT_TAB'.

    append ls_fieldcatalog to lt_fieldcatalog.

    call method cl_alv_table_create=>create_dynamic_table

    exporting

    it_fieldcatalog = lt_fieldcatalog

    importing

    ep_table = <fs_data>

    exceptions

    generate_subpool_dir_full = 1

    others = 2

    .

    if sy-subrc <> 0.

    endif.

    assign <fs_data>->* to <fs_1>.

    assign <fs_1> to <fs_2>.

    loop at <fs_2> assigning <fs_3>.

    write: <fs_3>-pollid.

    endloop.

    Regards

    Gaurav

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 10, 2007 at 09:09 AM

    hi Felix ,

    Try the following blog:

    /people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

    Reward if helpful !

    Regards,

    Ranjita

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 09:10 AM

    Hi,

    hi,

    try this..

    =====================================

    REPORT zmaschl_create_data_dynamic .

    TYPE-POOLS: slis.

    DATA: it_fcat TYPE slis_t_fieldcat_alv,

    is_fcat LIKE LINE OF it_fcat.

    DATA: it_fieldcat TYPE lvc_t_fcat,

    is_fieldcat LIKE LINE OF it_fieldcat.

    DATA: new_table TYPE REF TO data.

    DATA: new_line TYPE REF TO data.

    FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,

    <l_line> TYPE ANY,

    <l_field> TYPE ANY.

    • Build fieldcat

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    i_structure_name = 'SYST'

    CHANGING

    ct_fieldcat = it_fcat[].

    LOOP AT it_fcat INTO is_fcat WHERE NOT reptext_ddic IS initial.

    MOVE-CORRESPONDING is_fcat TO is_fieldcat.

    is_fieldcat-fieldname = is_fcat-fieldname.

    is_fieldcat-ref_field = is_fcat-fieldname.

    is_fieldcat-ref_table = is_fcat-ref_tabname.

    APPEND is_fieldcat TO it_fieldcat.

    ENDLOOP.

    • Create a new Table

    CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING

    it_fieldcatalog = it_fieldcat

    IMPORTING

    ep_table = new_table.

    • Create a new Line with the same structure of the table.

    ASSIGN new_table->* TO <l_table>.

    CREATE DATA new_line LIKE LINE OF <l_table>.

    ASSIGN new_line->* TO <l_line>.

    • Test it...

    DO 30 TIMES.

    ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

    <l_field> = sy-index.

    INSERT <l_line> INTO TABLE <l_table>.

    ENDDO.

    LOOP AT <l_table> ASSIGNING <l_line>.

    ASSIGN COMPONENT 'SUBRC' OF STRUCTURE <l_line> TO <l_field>.

    WRITE <l_field>.

    ENDLOOP.

    <b>Reward points</b>

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 09:13 AM

    Hi,

    Check the following link:

    http://www.sap-img.com/ab030.htm

    Regards,

    Bhaskar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 09:14 AM

    Hi Felix,

    try this short example:

    PARAMETER: P_DBTAB LIKE DATABROWSE-TABLENAME DEFAULT 'MARA'.

    *

    DATA: GDO_DATA TYPE REF TO DATA.

    FIELD-SYMBOLS: <GT_ITAB> TYPE TABLE.

    *

    CREATE DATA GDO_DATA TYPE TABLE OF (P_DBTAB).

    ASSIGN GDO_DATA->* TO <GT_ITAB>.

    *

    SELECT * FROM (P_DBTAB) UP TO 100 ROWS INTO TABLE <GT_ITAB>.

    Regards, Dieter

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 11, 2007 at 08:27 AM

    Found a way to work around this....

    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.