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

Dynamic Internal table creation using BDCDATA input structure

Former Member
0 Likes
1,261

Hi all,

         I got a requirement where I need to dynamically create an internal table ITAB2 and populate it with the data coming from

         another internal table  ITAB1.

         Both ITAB1 and ITAB2 are of different structures.

         I have created the Field Catalog and called the method cl_alv_table_create=>create_dynamic_table exporting Field Catalog and now my dynamic            internal table is ready.

         But the difficulty is that the input data in ITAB1 has 2 fields of BDCDATA structure FNAM and FVAL

         Now my dynamic internal table ITAB2 which was created have the fields whose names are ITAB1-FNAM.

         It means all different values of ITAB1-FNAM are ITAB2 column names.

         How do I populate ITAB2 here? I have tried using 'ASSIGN COMPONENT' of Fieldsymbols but it dint work.

         No hard-codings should be used. I need to do all these dynamic(meaning structures may keep changing)

         Please help me out with your ideas. Is there any other way through which I can acheieve this?

         For reference  i have attached screenshots of these 2 internal tables All your suggestions are appreciated.

Thanks,

Aravindh.

8 REPLIES 8
Read only

former_member206394
Active Participant
0 Likes
1,200

This message was moderated.

Read only

vinodkumar_thangavel
Participant
0 Likes
1,200

Hi,

Try the below code it woreked for me,

   FIELD-SYMBOLS: <t_table>     TYPE STANDARD TABLE.

CALL METHOD cl_alv_table_create=>create_dynamic_table

       EXPORTING

         it_fieldcatalog = lt_fcat

       IMPORTING

         ep_table        = gs_dyn_tab.

     ASSIGN gs_dyn_tab->* TO <t_table>.

Regards,

Vinodkumar.

Read only

0 Likes
1,200

Hi Vinod,

              Thanks for ur time. My problem is not the dynamic internal table creation. I have already created it. Its about updation of this internal table using another internal table data as I mentioned already.

Read only

0 Likes
1,200

Hi Aravindh,

Then u shall try using assign component ,

ASSIGN COMPONENT ls_fieldname OF STRUCTURE <s_dyntable> TO <s_field>.

<s_field> = 'your value '.


Regards,

Vinodkumar.

Read only

Former Member
0 Likes
1,200

Hi Aravindh,

Can you use the index 1, 2,3, etc., which I suppose is not hardcoding. Use them to read the fields of every entry..

Eg: ASSIGN COMPONENT sy-index OF STRUCTURE struc TO <fs>.

Thanks and Regards,

Rajesh

Read only

0 Likes
1,200

Hi Rajesh,

                Unfortunately index cannot be used as the internal table ITAB1 is a hashed internal table. #Hashed for handling large amount of data. Any other way?

Read only

0 Likes
1,200

Hi Aravindh,

You can do one thing..

For creating the dynamic internal table, you had the field catalog right.. which have the table and field name ...

For instance..

read it_fcat into wa_fcat index 1. <-get the first field details.. (hope this fieldcatlog internal table is not hashed table )

and then concatenate tabname and colname into a string which will be used as component name (COMPNAME) and use your Assign statement.. like i have mentioned below..

ASSIGN (compname) TO <f2>.

ASSIGN COMPONENT <F2> OF STRUCTURE struc TO <fs>.

Hope this help you out..

thanks in advance.

Regards,

Rajesh

Read only

Former Member
0 Likes
1,200

This message was moderated.