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: 

how can i cummulate the quantity in this example

Former Member
0 Kudos
116

my requirement is like this:

PLANT MATNR PERIOD LGORT QUAN MEINS

A001 03201780 03122004 AA01 4 EA

A001 03201780 03122004 AA01 -2 LB

A001 03201780 03122004 AA01 8 LB

A003 03201782 03122004 AA02 4 EA

A003 03201782 03122004 AA02 -2 LB

A003 03201782 03122004 AA02 8 LB

now i want to cummulate the quantity from

UNIQUE fileds are : PLANT MATNR PERIOD LGORT QUAN MEINS

help me

Thanks & Regards

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos
93

Hi Ramesh,

first sort the table based on the non numeric key fields viz,

sort itab by PLANT MATNR PERIOD LGORT MEINS.

loop at itab.

collect itab into wa.

write:/ wa.

endloop.

REgards,

Ravi

6 REPLIES 6

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
93

Use the COLLECT statement as discussed in the other post.

You will then get values like this.

PLANT MATNR PERIOD LGORT QUAN MEINS
A001 03201780 03122004 AA01 4 EA
A001 03201780 03122004 AA01 6 LB
A003 03201782 03122004 AA02 4 EA
A003 03201782 03122004 AA02 6 LB

Please make sure to award points for any helpful answers in your other post as well.

Regards,

Rich Heilman

Former Member
0 Kudos
93

Hi Ramesh,

As Ravi mentioned :

sort your internal table by PLANT MATNR MEINS.

LOOP At ITAB.

collect itab.

ENDLOOP.

Lanka

former_member181962
Active Contributor
0 Kudos
94

Hi Ramesh,

first sort the table based on the non numeric key fields viz,

sort itab by PLANT MATNR PERIOD LGORT MEINS.

loop at itab.

collect itab into wa.

write:/ wa.

endloop.

REgards,

Ravi

0 Kudos
93


report zrich_0003 .


data: begin of itab occurs 0,
      matnr type mard-matnr,
      werks type mard-werks,
      lgort type mard-lgort,
      perid type sy-datum,
      labst type mard-labst,
      meins type mara-meins,
      end of itab.

data: begin of itab2 occurs 0,
      matnr type mard-matnr,
      werks type mard-werks,
      lgort type mard-lgort,
      perid type sy-datum,
      labst type mard-labst,
      meins type mara-meins,
      end of itab2.


itab-matnr = '03201780'.
itab-werks = 'A001'.
itab-lgort = 'AA01'.
itab-perid = '20041203'.
itab-labst = '4'.
itab-meins = 'EA'.
append itab.

itab-matnr = '03201780'.
itab-werks = 'A001'.
itab-lgort = 'AA01'.
itab-perid = '20041203'.
itab-labst = '-2'.
itab-meins = 'LB'.
append itab.

itab-matnr = '03201780'.
itab-werks = 'A001'.
itab-lgort = 'AA01'.
itab-perid = '20041203'.
itab-labst = '8'.
itab-meins = 'LB'.
append itab.


itab-matnr = '03201782'.
itab-werks = 'A003'.
itab-lgort = 'AA02'.
itab-perid = '20041203'.
itab-labst = '4'.
itab-meins = 'EA'.
append itab.

itab-matnr = '03201782'.
itab-werks = 'A003'.
itab-lgort = 'AA02'.
itab-perid = '20041203'.
itab-labst = '-2'.
itab-meins = 'LB'.
append itab.

itab-matnr = '03201782'.
itab-werks = 'A003'.
itab-lgort = 'AA02'.
itab-perid = '20041203'.
itab-labst = '8'.
itab-meins = 'LB'.
append itab.

loop at itab.
  move-corresponding itab to itab2.
  collect itab2.
endloop.


loop at itab2.
  write:/ itab2-werks, itab2-lgort, itab2-labst.
endloop.

Regards,

Rich Heilman

Former Member
0 Kudos
93

declare another internal table interchanging quan and meins fields,

sort itab by plant matnr period lgort meins quan.

loop at itab.

at end of meins.

collect itab.

endat.

endloop.

Former Member
0 Kudos
93

sorry the uinique fields are PLANT MATNR PERIOD LGORT only

A001 03201780 03122004 AA01 4 EA

A001 03201780 03122004 AA01 -2 LB

A001 03201780 03122004 AA01 8 LB

A003 03201782 03122004 AA02 4 EA

A003 03201782 03122004 AA02 -2 LB

A003 03201782 03122004 AA02 8 LB

now i want to cummulate the quantity from

UNIQUE fileds are : PLANT MATNR PERIOD LGORT

now i think collect will not work. how can i do.

help me

Thanks & Regards