‎2009 Jul 20 6:57 AM
Hi, sorry if this question is too basic because I just started with ABAP and not familiar with the way it operates.
Objective :
Put the data fields from it_table into it_files with different field name.
it_files contains key1, field1, field2, field3, field4, field5 --> data retrieved from data file
it_table contains key1a, field1, field2a, field3a --> data retrieved from table
it_files and it_table can be linked using key1 and key1a.
Using the standard modify function it doesn't allow me to match key1 to key1a.
In this situation, normally how you do it in ABAP ?
If it allow me to match key by key and then column to column, it will be much easier, however it is not something I can figure out.
Thanks for any assistance.
‎2009 Jul 20 7:01 AM
Hi David,
Are you transporting only FIELD1? if yes, you can do it like this:
Loop at t_tab1 into w_tab1.
read table t_tab2 into w_tab2 with key key1a = w_tab1-key1.
v_tabix = sy-tabix.
modify t_tab2 index v_tabix from w_tab1 transporting field1.
Endloop.
Fieldnames should be the same if you want to modify the table data.
Hope this helps.
Benedict
Added the read statement.
‎2009 Jul 20 7:01 AM
Hi David,
Are you transporting only FIELD1? if yes, you can do it like this:
Loop at t_tab1 into w_tab1.
read table t_tab2 into w_tab2 with key key1a = w_tab1-key1.
v_tabix = sy-tabix.
modify t_tab2 index v_tabix from w_tab1 transporting field1.
Endloop.
Fieldnames should be the same if you want to modify the table data.
Hope this helps.
Benedict
Added the read statement.
‎2009 Jul 20 7:03 AM
Sorry, I am not clear in my question.
it_files --> data retrieved from data file into this internal table
key1
field1
field2
field3
field4
field5
it_table --> data retrieved from table
key1a
field1
field2a
field3a
I need to update field1, field2a, field3a from it_table to it_files matching key1 and key1a.
Final, all data must be in it_files.
Take note, the field name in both internal table may not be the same.
Edited by: davidku1 on Jul 20, 2009 8:05 AM
‎2009 Jul 20 7:08 AM
Hi david,
If the fields,
field1, filed2a, filed3a are of the same type as that of it_table, then you can use move-corresponding and modify it. Else you can try the following,
loop at it_table.
read table it_files with key key1 = it_tables-key1a.
if sy-subrc = 0.
it_files-field1 = it_tables-field1.
it_files-field2a = it_tables-field2.
it_files-field3a = it_tables-field3.
modify it_files.
clear: it_files-field1, it_files-field2a, it_files-field3a.
modify it_files.
eendif.
endloop.
Edited by: vikred on Jul 20, 2009 8:08 AM
‎2009 Jul 20 7:16 AM
Hi,
Check this.
loop at it_files into wa_files.
read table it_table into wa_table with key key1a eq wa_files-key1.
if sy-subrc eq 0.
wa_files-field1 = wa_table-field1.
wa_files-field2 = wa_table-field2a.
wa_files-field3 = wa_table-field3a.
modify it_files from wa_files.
endif.
endloop.
‎2009 Jul 20 10:21 AM
Thank you all for your assistance.
I will try it out and provide credit accordingly. Appreciate your expertise.
‎2009 Jul 20 7:02 AM
Hi David,
you can try the following code
loop at it_table.
read table it_files with key key1 = it_tables-key1a.
if sy-subrc = 0.
move-corresponding it_table to it_files.
modify it_files.
eendif.
endloop.
Regards,
Vik
‎2009 Jul 20 7:04 AM
hi
the following code will make your doubts clear.
loop at it_files into wa_files.
read table it_table into wa_table with key1a eq wa_files-key1.
if sy-subrc eq 0.
wa_files-field3 = wa_table-field3.
modify it_files from wa_files.
endif.
endloop.Regards
Sajid
‎2009 Jul 20 7:09 AM
Hi David,
Try the below code,
field-symbols : <FS_table > type X_table.
data: it_table type standard table of x_table.
loop at it_files into w_files .
read table it_table ASSIGNING <FS_table > with key key1a = w_files-key1.
if sy-subrc = 0.
<FS_table > -key2a = 'XYZ' -
> Here your key2a value will be changed directly in the table
endif.
endloop.
otherwise try the below code.
loop at it_files into w_files .
read table it_table ASSIGNING w_table with key key1a = key1.
if sy-subrc = 0.
w_table-key2a = 'XYZ'.
w_table-key3a = 'ABC''.
modify it_table from w_table transporting key2a
key3a
where key1a = w_files-key1.
endif.
endloop.
but the first solution will give you a better performance.