‎2009 Jul 22 8:38 AM
Hi all,
i have a requirement to calculate total quantity for each and every material,
fetched data from MSEG table for multiple material's and need to calculate the total of every material.
am little bit confusing while summing the quantity(MSEG-MENGE) for each individual material.
my internal table contains materiel number, quantity and Base UOM.
need sample code...
Regards
Suresh
‎2009 Jul 22 8:40 AM
HI,
Use COLLECT statement.
Suppose your internal table is ITAB and it contains the following fields.
MATNR UOM QTY
Create one more table which is same as ITAB.
Do as follows:-
SORT ITAB BY MATNR UOM.
LOOP AT ITAB INTO WA.
COLLECT WA INTO ITAB2.
ENDLOOP.Regards.
Ankur Parab
‎2009 Jul 22 8:49 AM
Hi,
Declare one more internal table itba2.
Sort table itab1 by Matnr and UoM.
Then loop table itab1.
Inside loop use Collect stmt, which will append record of itab1 to itab2 in such a way that u will get sum of each Quantity.
Eg
Itab1
Material Quantity Uom
1000 10 KG
1000 10 KG
1001 10 Kg
As Per Collect Stmt
Itab2
Material Quantity Uom
1000 20 KG
1001 10 KG
‎2009 Jul 22 8:41 AM
suresh, i am not able to understand the exact requirement. can you please explain what exactly you need?
you can sum them in each line and use at end-of material to update it to some other table.
will this solve your problem?
‎2009 Jul 22 8:50 AM
there are multiple entries for same material, and need to calculate total for each material,
my internal table contains material number and quantity
‎2009 Jul 22 8:58 AM
Hi Suresh,
Try the following code.
Get all the distinct material numbers in to a temporary internal table,
data: begin of it_temp occurs 0,
matnr like mseg-matnr,
menge like mseg-menge,
end of it_temp.
loop at it_mseg.
at new of matnr.
move-corresponding it_mseg to it_temp.
append it_temp.
endat.
endloop.
sort it_temp by matnr.
After this calculate the quantity as per below
loop at it_temp.
loop at it_mseg where matnr = it_temp-matnr.
wa_menge = it_mseg-menge.
it_temp-menge = it_temp-menge + wa_menge.
endloop.
modify it_temp.
clear it_temp-menge.
endloop.
Regards,
Vik
Edited by: vikred on Jul 22, 2009 9:59 AM
‎2009 Jul 22 8:45 AM
SORT the internal stable I_MSEG by MATNR.
Use AT NEW MATNR statement within the loop.
and initilize the total qty within that.
After calculate sum of qty for material as
t_qty = t_qty + i_mseg-menge.
and display the report using AT END OF MATNR statement.
Regds,
ANil
‎2009 Jul 22 8:52 AM
sort gt_mseg by matnr.
loop at gt_mseg into gs_mseg.
gv_qty = gv_qty + gs_mseg-menge.
at end og matnr.
gs_final-qty = gv_qty.
appen gs_ginal to gt_final.
clear: gv_qty.
endat.
endloop.
do a similar code.
‎2009 Aug 20 7:27 AM