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: 

Cumulative sum in ALV report output

Former Member
0 Kudos

Hello all,

I given the fields of DMBTR and LIFNR in my ALV report and i got the number of vendors and Amounts in my output grid.So now how can i calculate the same vendor number with all the Amount added and give the total sum for that vendor and display only that one vendor number with all the total sum of amounts in output

Give me coding for that.

Thank you

divya

1 ACCEPTED SOLUTION

PraveenChitturi
Participant

Hello,

If you have ABAP 7.4 then can use concept something like this.

sample-logic-for-cumulative-amounts.txt

13 REPLIES 13

PraveenChitturi
Participant

Hello,

If you have ABAP 7.4 then can use concept something like this.

sample-logic-for-cumulative-amounts.txt

0 Kudos

Thank you praveen for giving answerreport1.txt.But i want logic according to my coding can you please give based on my coding and output.screenshot-24.png and my coding and output was like that. can you please give coding according to that.

0 Kudos

Hi Divya,

You can enhance the txt file logic as per your internal table right? Please let me know what exactly you have difficulty in implementing.

Thanks,

Praveen.

0 Kudos

Actually,the coding what you sent was little bit confused to me.so can you please explain clearly the coding according to what i send to you.

Thank you

Hi,

data:t_dmbtr type mseg-dmbtr.

What i understood is
Report
Lifnr Amount

L1 25

L2 30

L1 1

Cumulative Vendor Report

LIfnr Amount

L1 26

L2 30

If you need like above, Small operation you need to do.
You internal table like it_tab1

Sort it_tab1 by lifnr
now Create one more table like it_tab2 ,It_final Same files and structures.

Now move it_tab1 to it_tab2.

delete adjacent duplicates from it_tab1 comparing lifnr.

Now in the it_tab1 duplicate lifnr will be deleted.

Loop at it_tab1.

loop at it_tab2 where lifnr eq it-tab1-lfirn.
t_dmbtr = t_dmbtr + it_tab2-dmbtr .
endloop

it_final-lifnr = it_tab1-lifnr.
it_final-dmbtr = t_dmbtr.

append it_final.
clear:it_final,t_dmbtr.

endloop.
endloop.

Hope you understood, More than above there is no easy solution.

Hi Divya,

I recommend you to copy that code in a test program and debug . Then you will come to know the functionality and logic. If your system is having abap 7.4 then that logic is much useful.

Thanks,

Praveen.

0 Kudos

Thank you so much.It is useful to me.

0 Kudos

Thankyou for your support.

0 Kudos

What you sent the code was exactly done.But again when i calculate the amount it not getting the exacly same amount.Like

vendor(LIFNR) amount(DMBTR)

20 10

20 15

21 20

21 25

This is what i alrdy got.And when i use the code it got it what i want to be.but when i calculate the amount it just shown as

vendor(LIFNR) amount(DMBTR)

20 30

21 50

how to solve this issue?

0 Kudos

Can i get your code.

0 Kudos

Solved the issue.I declared another internal table and written the code for that properly.

Thank you

0 Kudos

Ok, You Can solve the issues, If you debug it properly.

SimoneMilesi
Active Contributor
0 Kudos

It's a pretty basic question.

Apart praveen.chitturi suggestion (which is the right way to do if you are at least on 7.40), even old ABAP offers you the solution with Control Level Staments.

https://wiki.scn.sap.com/wiki/display/ABAP/Control+Level+Statements+in+ABAP

Again, it's something pretty basic.