2007 Sep 04 2:30 PM
I want to move the contents of an internal table to another internal table by comparing the fields row by row.
Is this possible. I have tried using loops but it gets too complex. Is there another way.
2007 Sep 04 2:35 PM
2007 Sep 04 2:34 PM
Hi,
If the Fields names are smae in both internal tables then you can use the MOVE-CORRESPONDING.
if the 2 internal table structures are same then you can use
ITAB1[] = ITAB2[].
Regards
Sudheer
2007 Sep 04 2:34 PM
Hi Krish,
Do you mean that depending on a certain criteria, you want to modify the records in 2nd table with the data from 1st table?
LOOP AT tab1.
READ TABLE tab2 WITH KEY xxxx = tab1-xxxx .......
IF sy-subrc EQ 0.
tab2-field1 = tab1-field1..
tab2-field2 = ......
MODIFY tab2.
ENDIF.
ENDLOOP.
Thanks and Best Regards,
Vikas Bittera.
2007 Sep 04 2:35 PM
you can use
append lines of itab to itab1.
if you use above statement then you can't compare internal table.
best thing thing would be compare internal table within loop.
Thanks
Seshu
2007 Sep 04 2:35 PM
2007 Sep 04 2:47 PM
ok
I have 2 internal tables , itab1 and itab2. itab 1 and itab2 both have the field kunnr , Kunnr is can be repeated again and again in either of the table with other fields being different.
Now , if the fields of itab1 are
kunnr1 item1
kunnr1 itam2
kunnr2 item3
kunn4 item3
kunnr4 item5
and the contents of tab2 are
kunnr1 x1
kunnr1 x2
kunnr1 A
kunnr2 B
kunnr2 B
kunnr2 B
kunnr3 C
Then the final table should look like
kunnr1 item1 x1
kunnr1 item2 x2
kunnr1 A
kunnr2 item3 B
kunnr2 B
kunnr2 B
and so on.
2007 Sep 04 2:49 PM
Hello Krish,
You have to compare within loop ,there is no other way.
let me know if you need any help on sample code ..
Thanks
Seshu
2007 Sep 04 2:52 PM
2007 Sep 04 2:53 PM
Hi,
Do like this:
LOOP AT tab1.
LOOP AT tab2 WHERE kunnr = tab1-kunnr.
tab3-kunnr = tab1-kunnr.
tab3-field2 = tab1-field2.
tab3-field3 = tab2-field2.
APPEND tab3.
DELETE tab2.
ENDLOOP.
ENDLOOP.
IF NOT tab2[] IS INITIAL.
LOOP AT tab2.
tab3-kunnr = tab2-kunnr.
tab3-field2 = tab2-field2.
APPEND tab3.
ENDLOOP.
Thanks and Best Regards,
Vikas Bittera.
2007 Sep 04 2:59 PM
Check the below code :
REPORT YEDULOCK.
tables : vbak,
vbap.
Internal table for VBAK Table
data : begin of i_vbak occurs 0,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
kunnr like vbak-kunnr,
end of i_vbak.
Internal table for VBAP
data : begin of i_vbap occurs 0,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
matnr like vbap-matnr,
kwmeng like vbap-kwmeng,
netpr like vbap-netpr,
end of i_vbap.
internal table for output
data : begin of i_output occurs 0,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
kunnr like vbak-kunnr,
posnr like vbap-posnr,
matnr like vbap-matnr,
kwmeng like vbap-kwmeng,
netpr like vbap-netpr,
end of i_output.
select-options : s_vbeln for vbak-vbeln.
start-of-selection.
get the data from VBAK Table
select vbeln vkorg kunnr from vbak into table i_vbak
where vbeln in s_vbeln.
if sy-subrc eq 0.
select vbeln posnr matnr kwmeng netpr from vbap into table i_vbap
for all entries in i_vbak
where vbeln = i_vbak-vbeln.
endif.
loop at i_vbap.
read table i_vbak with key vbeln = i_vbap-vbeln.
if sy-subrc eq 0.
i_output-vbeln = i_vbak-vbeln.
i_output-vkorg = i_vbak-vkorg.
i_output-kunnr = i_vbak-kunnr.
i_output-posnr = i_vbap-posnr.
i_output-matnr = i_vbap-matnr.
i_output-kwmeng = i_vbap-kwmeng.
i_output-netpr = i_vbap-netpr.
append i_output. " Moving the data into output internal table
clear : i_vbap,
i_vbak,
i_output.
else.
clear : i_vbap,
i_vbak,
i_output.
continue.
endif.
endloop.
end-of-selection.
loop at i_output.
write:/ i_output-vbeln,i_output-vkorg,i_output-kunnr,i_output-posnr,
i_output-matnr,i_output-kwmeng,i_output-netpr.
endloop.
Thanks
Seshu
2007 Sep 04 3:10 PM