‎2015 Apr 23 7:59 AM
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.
‎2015 Apr 23 10:04 AM
‎2015 Apr 23 10:58 AM
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.
‎2015 Apr 23 11:14 AM
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.
‎2015 Apr 23 12:18 PM
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.
‎2015 Apr 23 11:32 AM
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
‎2015 Apr 24 11:23 AM
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?
‎2015 Apr 24 12:43 PM
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
‎2015 Apr 23 12:14 PM