Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

sum qty if material and plant is same

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

4 REPLIES 4

Former Member
0 Kudos

Hi swati

Try to select data from MARC.

Best Regards

Wiboon

Message was edited by:

Wiboon Chaiyabutsakul

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Venky

Thanks. I solved it.