Application Development and Automation 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 column in alv report

glory_karra2028
Explorer
0 Kudos
424

I'm having alv report having DMBTR field , client asked me to add another column that should be cumulative of dmbtr filed... i tried this but no use ....can anyone help me on this?

 SORT IT_FINAL BY LIFNR.
LOOP AT it_FINAL INTO WA_FINAL.
* AT NEW LIFNR.
IF WA_FINAL-LIFNR = 'VDSIVATC01'.
* gv_cumulative_sum = WA_FINAL-BASE + gv_cumulative_sum .
gv_cumulative_sum = gv_cumulative_sum + WA_FINAL-BASE .
WA_FINAL-CUM = gv_cumulative_sum. MODIFY it_FINAL FROM WA_FINAL TRANSPORTING CUM WHERE LIFNR = 'VDSIVATC01'.
* ENDAT.
CLEAR :WA_FINAL.
ENDIF.



  
1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
365

Try

SORT IT_FINAL BY name.
LOOP AT it_FINAL ASSIGNINBG <fs>.
  AT NEW name.
    CLEAR lv_cumulative_sum.
  ENDAT.
  <fs>-cum = lv_cumulative_sum = lv_cumulative_sum + <fs>-BASE.
ENDAT.

But if user change the sort order you sum will get wrong (disable sort options or handle relevant event to update those values)

3 REPLIES 3

raymond_giuseppi
Active Contributor
366

Try

SORT IT_FINAL BY name.
LOOP AT it_FINAL ASSIGNINBG <fs>.
  AT NEW name.
    CLEAR lv_cumulative_sum.
  ENDAT.
  <fs>-cum = lv_cumulative_sum = lv_cumulative_sum + <fs>-BASE.
ENDAT.

But if user change the sort order you sum will get wrong (disable sort options or handle relevant event to update those values)

Sandra_Rossi
Active Contributor
365

Please edit your question (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!

Sandra_Rossi
Active Contributor
365

It seems that your requirement is to group by NAME and cumulate DMBTR for each NAME value.

You should explain what you currently get and what you expect instead of "it doesn't work". People can't have any idea of what is in your mind.

What is BASE ? I expected DMBTR...

Why are you doing WHERE name = ' ' ?