2008 Jan 29 8:29 AM
Hi All,
I have created a Dynamic internal table using field symbols. Now i need to copy that dynamic itab to another internal table, because I am not familiar with field symbols. Can anybody tell me how can i copy that dyn_itab to another itab.
code which I used to create dyn_table:
LS_FIELDCATALOG-FIELDNAME = 'CHINA_TOT'.
LS_FIELDCATALOG-INTTYPE = 'I'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
assign LT_DATA to <FS_DATA>.
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.
So <FS_1> now points to our dynamic internal table.
assign <FS_DATA>->* to <FS_1>.
HERE <FS_1> is a dynamic itab.
2008 Jan 29 9:22 AM
Hi,
you are almost done ok, except some assignments. just go thru the following code, it is perfectly apt.
Data: dy_table type ref to data.
Field-symbols: <fs_data> type standard table, <fs_wa>.
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = dy_table.
assign dy_table->* to <FS_DATA>.
Create data dy_line like line of <FS_DATA>.
assign dy_line->* TO <fs_wa>.
Now you can move the values from <fs_wa> into another itab.
with regards
Mahesh
2008 Jan 29 9:29 AM
Hai Mahesh,
Can u please send me some sample code, how can I assign this dyn_tab fields
example: I am giving like this <fs_wa>-field1 = 'Some value'.
but it is giving error. I am not using any assign statement.
Thanks,
Swapna
2008 Jan 29 9:39 AM
Swapna,
you can able to display the values on the list with the following. But in order to move
the records into another itab, you should have the same structure of itab as that of <dyn_tab>. you can do it by simply MOVE statement.
LOOP AT <fs_data> INTO <fs_wa>.
DO.
ASSIGN COMPONENT sy-index of structure <fs_wa> to <dyn_field>.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
ENDDO.
ENDLOOP.
regards
Mahesh
2008 Jan 29 10:03 AM
Hai Mahesh,
Can u please send me ur personal mail id, so that i can send u my code. I need to change an existing code. In present code all Organizational Units are hard coded and I need to pick the data dynamically from DB table. The final itab also given with specified fields as org units(hard coded fileds), so I am trying to create this dyn_tab as final table and after creating I need to change my code accordingly.
Regards,
Swapna
2008 Jan 29 9:45 AM
Hi,
Try with the following as well,
Loop at <fs_data> into <fs_wa>.
MOVE-CORRESPONDING <fs_wa> TO itab.
append itab.
Endloop.
regards
Mahesh
2013 Jul 29 12:30 PM
Swapna,
Did you try
Assign Local Copy Of <lt_tab1> to <lt_tab2>.
Check sy-subrc EQ 0.
Here <lt_tab2> is a copy of <lt_tab1> and changes made to <lt_tab2> will not be reflected in <lt_tab1>.
2013 Jul 29 12:54 PM
2013 Jul 29 1:51 PM
First you need to create another table with the structure that you have.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = <FS_DATA2>
exceptions
generate_subpool_dir_full = 1
others = 2
field-symbols : <fs_line1>, <fs_line2>, <fs_tmp1>, <fs_tmp2>.
assign <FS_DATA2->* to <FS_2>.
Now FS_1 and FS_2 are the tables.
Also create work areas for the tables.
CREATE DATA gw_line1 LIKE LINE OF <fs_1>
CREATE DATA gw_line2 LIKE LINE OF <fs_2>.
ASSIGN gw_line1->* TO <fs_line1>.
assign gw_line2->* to <fs_line2>.
With field symbols, you cannot move the rows directly, you will have to move it field by field.
Once all the values are populated in the first table, copy it with the following logic.
loop at <fs_1> into <fs_line1>
Loop at LT_FIELDCATALOG into LS_FIELDCATALOG.
ASSIGN COMPONENT ls_fieldcatalog-fieldname OF STRUCTURE <fs_line1> TO <fs_tmp1>.
ASSIGN COMPONENT ls_fieldcatalog-fieldname OF STRUCTURE <fs_line2> TO <fs_tmp2>.
<fs_tmp2> = <fs_tmp1>
endloop.
append <fs_line2> to <fs_2>
endloop.
2013 Jul 29 2:20 PM
You can go through this document to understand field symbols, data references and dynamic table.