09-15-2008 12:09 PM
hi,
i want to calculate the total stock of a material in a plant having more than storage location.
i am getting the values like this.
matnr lgort plant labst
x 1 100 100
x 2 100 25
y 1 100 30
y 3 100 67
i have used at end of matnr .
but i am not getting the desired o/p.
i have written the code like this :
LOOP AT it_mard.
st_mard = it_mard .
it_final-matnr = it_mard-matnr.
it_final-maktx = it_mard-maktx.
it_final-zmatsiz = it_mard-zmatsiz.
it_final-werks = it_mard-werks.
AT END OF matnr.
it_mard = st_mard.
v_sum = v_sum + it_mard-labst.
"it_final-labst = v_sum.
endat.
it_final-labst = v_sum.
09-15-2008 12:13 PM
just declare a itab with those fields.
loop at it_mard.
move-corresponding it_mard to itab_sum.
collect itabsum.
endloop.
09-15-2008 12:14 PM
Hello
As you want Plant Wise total quantities for a given material against multiple St. Locs... Internal table should have Material Number as a first column and Plant as Second Column in the structure... Sort internal table by Material and Plant...
sort int_tab by matnr ascending plant ascending.
Loop at int_tab.
at new plant.
sum.
At this point you will have Total of material quantity against the Current Plant
endat.
endloop.
Thanks
Amol Lohade
09-15-2008 12:16 PM
Hi,
No need of this calculation inside AT END OF...
All the Integer values will get added automatically inside AT END OF..
So your code should be like this
LOOP AT it_mard.
st_mard = it_mard .
it_final-matnr = it_mard-matnr.
it_final-maktx = it_mard-maktx.
it_final-zmatsiz = it_mard-zmatsiz.
it_final-werks = it_mard-werks.
AT END OF matnr.
v_sum = it_mard-labst.
endat.
Now the V_SUM will have 125 after 2nd run inside loop.
similarly for separate MATNRs
Cheers,
Kothand
09-15-2008 12:17 PM
Hi ,
First of all you have to sort this internal table:
Second ,logic should be like below:
at end of matnr.
read table it_mard index sy-tabix.
v sum = vsum + it_mard-labst.
endat.
Regards,
Talwinder
09-15-2008 12:21 PM
i hope this suits ur qn...
try something like this.
sort itab_mard by matnr plant .
data:v_sum type mard-labst.
loop at it_mard.
v_sum = v_sum + it_mard-labst.
at end of lgort.
skip 1.
write:it_mard-matnr.
write:v_sum.
clear v_sum.
endat.
09-15-2008 12:34 PM
Hi,
Try like this:
loop at it_mard.
at end of matnr.
SUM.
uline.
write:/ it_mard-matnr, it_mard-lgort, it_mard-plant, it_mard-labst.
endat.
endloop.
Regards,
Bhaskar
09-15-2008 2:11 PM
1) declare the fields in sequence "matnr plant lgort labst" and not "matnr lgort plant labst".
2) code:
sort it_mard by matnr plant.
loop at it_mard.
at end of PLANT.
SUM.
uline.
write:/ it_mard-matnr, it_mard-plant, it_mard-labst.
endat.
endloop.
OR
sort it_mard by matnr plant lgort.
loop at it_mard.
at end of LGORT.
SUM.
uline.
write:/ it_mard-matnr, it_mard-plant, it_mard-lgort, it_mard-labst.
endat.
endloop.
09-25-2008 10:32 AM