09-03-2007 4:18 AM
Hello Everyone !
If the combination of material and plant is same, I need to sum the quantities.
Please help me do this.
Thanks in advance
09-03-2007 4:28 AM
Hi,
you can use the collect statement
eg: itab having three field
material plant qty
001 01 10
001 02 11
002 02 10
001 01 20
if you do
loop at itab into wa.
collect wa to another internal table itab1.
endloop.
then you wil get
<b>001 01 30</b>
001 02 11
002 02 10
or else you can
sort itab by material plant. ( order should be same )
loop at itab.
at end of material plant.
sum.
write:/ itab-material, itab-plant, itab-quantity.
endat
but the table will not be modified.
endloop.
eg code
DATA: BEGIN OF itab OCCURS 0.
DATA: matnr TYPE matnr,
plant(3) TYPE c,
quan TYPE i.
DATA: END OF itab.
itab-matnr = 'aaa'.
itab-plant = '123'.
itab-quan = '10'.
APPEND itab.
itab-matnr = 'aaa'.
itab-plant = '123'.
itab-quan = '10'.
APPEND itab.
itab-matnr = 'aaa'.
itab-plant = '124'.
itab-quan = '10'.
APPEND itab.
itab-matnr = 'aaa'.
itab-plant = '124'.
itab-quan = '10'.
APPEND itab.
SORT itab BY matnr plant.
LOOP AT itab.
AT END OF plant .
SUM.
WRITE:/ itab-matnr, itab-plant, itab-quan.
ENDAT.
ENDLOOP.
thanks & regards,
Venkatesh
09-03-2007 4:23 AM
Hi swati
Try to select data from MARC.
Best Regards
Wiboon
Message was edited by:
Wiboon Chaiyabutsakul
09-03-2007 4:28 AM
Declare two internal tables of similar kind.
Types: begin of ty_tab1
matnr type matnr,
werks type werks,
sum_var type i,p or f,
end of ty_tab1,
ty_tab4 type ty_tab1.
ty_tab2 like standard table of ty_tab1,
ty_tab3 like standard table of ty_tab1.
loop at ty_tab2 into ty_tab1.
move corresponding ty_tab1 to ty_tab4.
collect ty_tab4 to ty_tab3.
clear: ty_tab1, ty_tab2.
endloop.
09-03-2007 4:28 AM
Hi,
you can use the collect statement
eg: itab having three field
material plant qty
001 01 10
001 02 11
002 02 10
001 01 20
if you do
loop at itab into wa.
collect wa to another internal table itab1.
endloop.
then you wil get
<b>001 01 30</b>
001 02 11
002 02 10
or else you can
sort itab by material plant. ( order should be same )
loop at itab.
at end of material plant.
sum.
write:/ itab-material, itab-plant, itab-quantity.
endat
but the table will not be modified.
endloop.
eg code
DATA: BEGIN OF itab OCCURS 0.
DATA: matnr TYPE matnr,
plant(3) TYPE c,
quan TYPE i.
DATA: END OF itab.
itab-matnr = 'aaa'.
itab-plant = '123'.
itab-quan = '10'.
APPEND itab.
itab-matnr = 'aaa'.
itab-plant = '123'.
itab-quan = '10'.
APPEND itab.
itab-matnr = 'aaa'.
itab-plant = '124'.
itab-quan = '10'.
APPEND itab.
itab-matnr = 'aaa'.
itab-plant = '124'.
itab-quan = '10'.
APPEND itab.
SORT itab BY matnr plant.
LOOP AT itab.
AT END OF plant .
SUM.
WRITE:/ itab-matnr, itab-plant, itab-quan.
ENDAT.
ENDLOOP.
thanks & regards,
Venkatesh
09-03-2007 6:37 AM