‎2009 Nov 03 3:57 PM
hi
i have two internal tables
itab1 with feilds partner, vbeln. cmgst ( SO status)
itab2 - vbeln, posnr(item no ), kwmeng(qunatity) , cmpre ( credit price )
now i need to get the sum of (cmpre * kwmeng) for each partner and SO status combination into another internal table itab3.
so itab3 will have partner, cmgst (so status ) , total amount
is it possible to achieve this with out using loop inside a loop.
thanks
‎2009 Nov 04 4:36 AM
Hi,
itab1 with feilds partner, vbeln. cmgst ( SO status)
itab2 - vbeln, posnr(item no ), kwmeng(qunatity) , cmpre ( credit price )
so itab3 will have partner, cmgst (so status ) , total amount
take third Internal table with fields partner cmgst cmpre kwmeng(if required)
loop itab2.
read table itab1 with key vbeln = itab2-vbeln.
if sy-subrc is initial.
move itab1-partner to itab3-partner.
move itab1-cmgst to itab3-cmgst.
move itab2-cmpre to itab3-cmpre.
move itab2-kwmeng to itab3-kwmeng.
* If you want to multiply quantity with price you can do that operation here and move it to the third itab
append itab3. "--> at the end all required data is available in this internal table
endif.
endloop.
data : temp_price type wears.
sort itab3 by partner cmgst.
loop at itab3.
on change of parnter.
clear temp_price.
endon.
at new partnrer.
sum
temp_price = iteb3-cmpre.
endat.
itab3-cmpre = temp_price.
modify itab3 index sy-tabix.
endloop.now hopefully your itab3 will contain sum of price at the first record against each partner.
if required you can do delete adjacent duplicates comparing partner.
Cheers
Ram
‎2009 Nov 03 4:49 PM
Hi,
Is it not possible to add the partner and so fields in itab2 itself?
regards,
nilesh.
‎2009 Nov 04 3:38 AM
Hi Sudhakar,
Check below code sample. Change it according to ur need.
DATA: BEGIN OF itab1 OCCURS 0,
partner TYPE string,
vbeln TYPE vbeln,
cmgst TYPE cmgst,
END OF itab1,
wa1 LIKE itab1.
DATA: BEGIN OF itab2 OCCURS 0,
vbeln TYPE vbeln,
posnr TYPE posnr,
kwmeng TYPE kwmeng,
cmpre TYPE cmpre,
END OF itab2,
wa2 LIKE itab2.
DATA: BEGIN OF itab3 OCCURS 0,
partner TYPE string,
cmgst TYPE cmgst,
amt TYPE p DECIMALS 2,
END OF itab3,
wa3 LIKE itab3.
wa1-partner = 'Test1'. wa1-vbeln = '0000000001'. wa1-cmgst = 'X'.
APPEND wa1 TO itab1. CLEAR wa1.
wa1-partner = 'Test2'. wa1-vbeln = '0000000002'. wa1-cmgst = 'X'.
APPEND wa1 TO itab1. CLEAR wa1.
wa2-vbeln = '0000000001'. wa2-posnr = '000001'. wa2-kwmeng = 10. wa2-cmpre = 100.
APPEND wa2 TO itab2. CLEAR wa2.
wa2-vbeln = '0000000002'. wa2-posnr = '000002'. wa2-kwmeng = 20. wa2-cmpre = 200.
APPEND wa2 TO itab2. CLEAR wa2.
LOOP AT itab1 INTO wa1.
READ TABLE itab2 INTO wa2 WITH KEY vbeln = wa1-vbeln.
IF sy-subrc = 0.
wa3-partner = wa1-partner.
wa3-cmgst = wa1-cmgst.
wa3-amt = wa2-kwmeng * wa2-cmpre.
APPEND wa3 TO itab3.
CLEAR wa3.
ENDIF.
ENDLOOP.
Thanks,
‎2009 Nov 04 4:24 AM
hi
itab2 will have multiple lines for a given vbeln, so i think read table won't solve the problem.
‎2009 Nov 04 3:54 AM
Hi,
Within one loop read other table, if sy-subrc = 0 perform the calculation part.
loop at it1.
read it2 with key abc = it1-abc.
if sy-subrc = 0.
*---perform calculation.
endif.
endloop.
Thanks,
Krishna
‎2009 Nov 04 4:22 AM
hi
the problem here is in it2 there are mutiple values for a given vbeln.
‎2009 Nov 04 4:25 AM
Off course you can do it.
loop at itab1.
read itab2
if sy-subrc eq 0.
total = cmpre * kwmeng.
endif.
copy all fields into itab3.
endloop.
cheers
‎2009 Nov 04 4:32 AM
you mena i can use read statements to read multiple lines from a internal table. can u give the code
‎2009 Nov 04 4:36 AM
Hi,
itab1 with feilds partner, vbeln. cmgst ( SO status)
itab2 - vbeln, posnr(item no ), kwmeng(qunatity) , cmpre ( credit price )
so itab3 will have partner, cmgst (so status ) , total amount
take third Internal table with fields partner cmgst cmpre kwmeng(if required)
loop itab2.
read table itab1 with key vbeln = itab2-vbeln.
if sy-subrc is initial.
move itab1-partner to itab3-partner.
move itab1-cmgst to itab3-cmgst.
move itab2-cmpre to itab3-cmpre.
move itab2-kwmeng to itab3-kwmeng.
* If you want to multiply quantity with price you can do that operation here and move it to the third itab
append itab3. "--> at the end all required data is available in this internal table
endif.
endloop.
data : temp_price type wears.
sort itab3 by partner cmgst.
loop at itab3.
on change of parnter.
clear temp_price.
endon.
at new partnrer.
sum
temp_price = iteb3-cmpre.
endat.
itab3-cmpre = temp_price.
modify itab3 index sy-tabix.
endloop.now hopefully your itab3 will contain sum of price at the first record against each partner.
if required you can do delete adjacent duplicates comparing partner.
Cheers
Ram