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: 

at end of

Former Member
0 Kudos

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.

8 REPLIES 8

kesavadas_thekkillath
Active Contributor
0 Kudos

just declare a itab with those fields.

loop at it_mard.

move-corresponding it_mard to itab_sum.

collect itabsum.

endloop.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

kesavadas_thekkillath
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

former_member194797
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

hi,

i got the answer.

regards

nilabichi.