‎2009 Jan 16 5:26 AM
Hi All
I am having two internal tables and this is the first table itab1.
belnr quanity number
100 8
100 9
100 9
and here is my internal table 2.
belnr quantity index number1
100 9 2 101
100 9 3 102
100 8 4 103
i need to compare the above two tables and update the number from intebal table 2 to internal table 1
the probelm i am facing is i have coded like this.
loop at itab1 into wa_itab1
read table itab2 into wa_itab2 with key belnr eq wa_itab1-belnr
quantity eq wa_itab1-quantity.
if sy-subrc eq 0.
move wa_itab2-number to wa_itab1-number.
modify itab2 from itab1 transporting number.
endloop.
move itab
i am getting output like this
belnr quanity number
100 8 103
100 9 102
100 9 102
please suggest me to get a output like this.
belnr quanity number
100 8 103
100 9 102
100 9 101
thanks
‎2009 Jan 19 8:36 AM
Hi
Modify your read stmt as:
read table itab2 into wa_itab2 with key belnr eq wa_itab1-belnr quantity eq wa_itab1-quantity index eq sy-index.
This way it will read from itab2 where the index field matches the loop count of the outer itab.
Hope this helps
Regards,
Jayanthi.K
‎2009 Jan 16 7:01 AM
Hi,
try like this...
loop at itab1 into wa_itab1 where number is initial.
read table...
move...
modify itab1 from wa_itab1..
endloop.
‎2009 Jan 16 7:14 AM
i beleive,u wanted to pick different values for number present in itab2 to itab1(whereas currently u always get same number '102' for same belnr qty vslues)..(also ia ssume both itabs have smae num of records)
essy fix,once u read itab2 for number,delete that row from itab29so that it wont be available for next time)
or
trying using INDEX field in itab2 ...if it is unique ..increment it(after every data retrival) and pass it to read statement.(also u can introduce new field in itab2 which wud work as the incrementing unique factor)
‎2009 Jan 16 7:21 AM
Hi Arun,
Just add a delete statement for wa_itab2 in your code, delete the record from itab2
after you are moving and modify your first table that is
after wa_itab2-number to wa_itab1-number and
modify itab2 from itab1 transporting number.
Delete table itab2 from wa_itab2 with rtable key belnr = wa_itab2 -belnr
quantity = wa_itab2 -quantity
index = wa_itab2 -index
number = wa_itab2-number.
.belnr index number1
With luck,
Pritam.
‎2009 Jan 16 7:34 AM
Hi,
Try this way.
declare a third internal table itab3 which is like itab1.
loop at itab1.
loop at itab2 where belnr = itab1-belnr
and quantity = itab1-quantity.
itab3-belnr = itab1-belnr.
itab3-quantity = itab1-quantity.
itab3-number = itab2-number1.
append itab3.
clear itab3.
endloop.
endloop.
sort itab3 by belnr quantity number.
delete adjacent duplicates from itab3 comparing belnr quantity number.
if you want the result in itab1 then overwrite itab1 with itab3.
Hope this helps.
‎2009 Jan 19 8:36 AM
Hi
Modify your read stmt as:
read table itab2 into wa_itab2 with key belnr eq wa_itab1-belnr quantity eq wa_itab1-quantity index eq sy-index.
This way it will read from itab2 where the index field matches the loop count of the outer itab.
Hope this helps
Regards,
Jayanthi.K
‎2009 Jan 22 10:10 AM
‎2009 Jan 22 10:58 AM
Hi,
To achieve this create another table of structure itab2.
then use the below logic.
DATA:w_ind TYPE i.
...
MOVE itab2 TO itab3.
LOOP AT itab1 INTO wa_itab1.
READ TABLE itab3 INTO wa_itab2 WITH KEY "use itab3 here
belnr = wa_itab1-belnr
quantity = wa_itab1-quantity.
IF sy-subrc EQ 0.
w_ind = sy-tabix. "Index of last read row
MOVE wa_itab2-number TO wa_itab1-number.
MODIFY itab1 FROM wa_itab1 TRANSPORTING number.
DELETE itab3 INDEX w_ind. "delete the read row
ENDIF.
ENDLOOP.Hope this helps you.
Regards,
Manoj Kumar P
‎2009 Jan 22 9:34 PM