‎2006 Jul 03 11:17 AM
Hi All!
I have two int tables as below with the same columns and field names and values below..
Item quan
mfg03 50
mfg04 100
mfg05 20.
second IT have the same item numbers but different values.Now my requirement is to <u><b>SUBTRACT</b></u> the quantities into 3rd IT item wise.Please advise.
Regards
Pavan
‎2006 Jul 03 11:26 AM
Hi Kumar,
Take third interna table and do as follows.
<b>1)If you sure that you dont have more than one entry for each material in ITAB2 then do as follows.</b>
DATA ITAB3 TYPE ITAB OCCURS 0 WITH HEAEERLINE.
loop at itab1.
read table itab2 with key item = itab1-item.
wa_itab3-quan = itab1-quan - itab2-quan.
wa_itab3-item = itab1-item.
append wa_itab3 to itab3
endloop.
<b>2)If you more than one entry for each material in ITAB2 then do as follows.</b>
loop at itab1.
loop at itab2 where item = itab1-item.
wa_itab3-quan = itab1-quan - itab2-quan.
wa_itab3-item = itab1-item.
endloop.
append wa_itab3 to itab3
endloop.
Thanks,
Vinay
‎2006 Jul 03 11:20 AM
Loop at itab1.
Read table itab2 with key item = itab1-item.
If sy-subrc eq 0.
itab1-qty = itab1-qty - itab2-qty.
Modify itab1.
Endif.
Endloop.
‎2006 Jul 03 11:21 AM
loop at itab1.
read table itab2 with key item = itab-item.
wa_itab3-quan = itab1-quan - itab2-quan.
wa_itab3-item = itab1-item.
append wa_itab3 to itab3
endloop.
Regards,
Ravi
‎2006 Jul 03 11:21 AM
loop at itab1 into wa_itab1
read table itab2 into wa_itab2 with key item = wa_itabl-item.
wa_itab3-item = wa_itab1-item.
wa_itab3-quan = wa_itab1-quan - wa_itab2-quan.
append wa_itab3 to itab3.
clear wa_itab3.
endloop.
‎2006 Jul 03 11:24 AM
Hi,
sort itab2 by item.
loop at itab1 into wa_itab1
read table itab2
into wa_itab2
with key item = wa_itab1-item
binary search.
wa_itab3-item = wa_itab1-item.
wa_itab3-quan = wa_itab1-quan - wa_itab2-quan.
append wa_itab3 to itab3.
clear wa_itab3.
endloop.
‎2006 Jul 03 11:26 AM
Hi Kumar,
Take third interna table and do as follows.
<b>1)If you sure that you dont have more than one entry for each material in ITAB2 then do as follows.</b>
DATA ITAB3 TYPE ITAB OCCURS 0 WITH HEAEERLINE.
loop at itab1.
read table itab2 with key item = itab1-item.
wa_itab3-quan = itab1-quan - itab2-quan.
wa_itab3-item = itab1-item.
append wa_itab3 to itab3
endloop.
<b>2)If you more than one entry for each material in ITAB2 then do as follows.</b>
loop at itab1.
loop at itab2 where item = itab1-item.
wa_itab3-quan = itab1-quan - itab2-quan.
wa_itab3-item = itab1-item.
endloop.
append wa_itab3 to itab3
endloop.
Thanks,
Vinay
‎2006 Jul 03 11:49 AM
Hi,
You can subtract the field which you don't want like this here itab2 is that internal table where you move data form itab1 and sort itab2 by key and if there is any duplicate entry is there use delete adjacent.
LOOP AT itab1.
MOVE-CORRESPONDING itab1 TO itab2.
APPEND itab2.
Endloop .
SORT itab2 BY key.
DELETE ADJACENT DUPLICATES FROM itab2.