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

Populating data into internal table created dynamically

Former Member
0 Likes
628

Hi all,

I have created an internal table dynamically using the method

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_FIELDCAT2[]

IMPORTING

EP_TABLE = L_TABLE.

ASSIGN L_TABLE->* TO <IT_TABLE>.

CREATE DATA wa_table LIKE LINE OF <it_table>.

ASSIGN wa_table->* TO <wa_table1>.

when I tried to append data into the internal table <it_table>

as below

ex : <wa_table1>-prueflos = wa_item-prueflos.

it is giving the error as 'The data object <wa_table1> has no structure therefore no component called prueflos'.

can anybody tell me how to append data into a dynamically created internal table.

Thanks,

Sudheer

5 REPLIES 5
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
599

FAQ. You have to use [ASSIGN COMPONENT OF STRUCTURE|http://help.sap.com/abapdocu_70/en/ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ.htm#!ABAP_ALTERNATIVE_4@4@] to populate data to the dynamic internal table.

Read only

Former Member
0 Likes
599

Hi Sudheer,

You need to use the ASSIGN COMPONENT command for this purpose. Check this code:


 FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  u201C Dynamic internal table name 
               <fs_dyntable>,                     u201C Field symbol to create work area 
               <fs_fldval> type any.              u201C Field symbol to assign values  

* ***....
* ***....
* ***....
* ***....

* Assume your internal table has fields COL1, COL2, COL3 etc
  DO p_cols TIMES.  

    index = sy-index. 

    MOVE sy-index TO wa_colno. 

    CONCATENATE 'COL' 

                wa_colno 

           INTO wa_flname.  

* Set up fieldvalue 

    CONCATENATE 'VALUE' index INTO 

                fieldvalue. 

    CONDENSE    fieldvalue NO-GAPS.  

    ASSIGN COMPONENT  wa_flname 

        OF STRUCTURE <fs_dyntable> TO <fs_fldval>. 

    <fs_fldval> =  fieldvalue.  

  ENDDO.  

Hope this solves your problem!

Cheers,

Shailesh.

Read only

0 Likes
599

Hi,

Actually my data is in another internal table.

Based on some conditions I have to move the data into my dynamic internal table.

Can you tell me how to move the data from one internal table to dynamic internal table.

Thanks,

Sudheer

Read only

0 Likes
599

Hi Sudheer,

I have exact requirement as before: kindly see the resolved thread: [ How to insert a header string to a DYNAMIC Internal Table|;

Please let me know if I can provide more info or you need the actual code. Thanks.

Jun

Read only

Former Member
0 Likes
599

Please check this example.............


FIELD-SYMBOLS: <t> TYPE STANDARD TABLE,
                            <wa_t>  TYPE ANY,
                            <field> TYPE ANY.

TYPES : BEGIN OF t_tab,
                test1 TYPE c,
                test2 TYPE c,
              END OF t_tab.
 
DATA : table     TYPE STANDARD TABLE OF t_tab,
            wa_table  TYPE t_tab,
            table1    TYPE STANDARD TABLE OF t_tab,
            wa_table1 TYPE t_tab.

ASSIGN ('WA_TABLE') TO <wa_t>.
ASSIGN ('TABLE')    TO <t>.

wa_table1-test1 = '1'.
wa_table1-test2 = '2'.
APPEND wa_table1 TO table1.

LOOP AT table1 INTO wa_table1.
  ASSIGN COMPONENT 'TEST1' OF STRUCTURE <wa_t> TO <field>.  "Refer a particular field
  <FIELD> = wa_table1-test1.

  ASSIGN COMPONENT 'TEST2' OF STRUCTURE <wa_t> TO <field>.  "Refer a particular field
  <FIELD> = wa_table1-test2.

  APPEND <wa_t> TO <t>.
ENDLOOP.