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 to create subtotal in REUSE_ALV_GRID_DISPLAY base on row No

former_member625844
Participant
0 Kudos
435

I create an ALV with REUSE_ALV_GRID_DISPLAY. I want to create a subtotal for rows 1 to 20 ,1 to 30,and 1 to end. Is it possible? I searched online and most code of ALV subtotal are based on sort catalog. Can I do that based on rownum? Thx.

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos
229

Use the existing feature that you have found: add a column which contains a group number '1', '2' and '3', assign the group '1' to the rows 1 to 20, etc., sort by this column, and do the subtotal on the columns you wish.

FredericGirod
Active Contributor
229

sandra.rossi I though about this at first, but he would like 1-20 and 1-30 (cumulative total)

Gourab_Dey
Contributor
229

Here you can find some good information on Sub-total and total in ALV.

ABAP ALV Total & Sub-total

Thanks,

Gourab

Sandra_Rossi
Active Contributor
0 Kudos
229

Oh, sorry, I didn't see that. Then, what about 2 group columns instead of 1?

          group1 group2 amount/quantity
          1-30   1-20    10
          1-30   1-20    10
          1-30   1-20    10
          1-30   1-20    10
          1-30   21-30   10
          1-30   21-30   10
subtotal  1-30   1-20    40
subtotal  1-30   21-30   20
subtotal  1-30           60

(I used groups named 1-20, 21-30 and 1-30 just to clarify - I hope it clarifies ;-))

I'm not sure whether you can remove the subtotal line "1-30 21-30" by ABAP coding using the event SUBTOTAL_TEXT (it's not intended for removing subtotals, just changing texts).

VXLozano
Active Contributor
0 Kudos
229

Just by using two new columns (they cannot be hidden ones): one for 1-20, and one for 1-30. Mark the first column for the first 20 rows, the secon for the first 30, and then add subtotals for those columns.

But the option to use sorting in the other columns of the ALV will be messed.

I can think in a way to do this with CL_SALV_GRID, but it would be done through events (when the user sorts by any column, you must clear the 1-20/1-30 columns, sort the table, mark (X) the columns again, based in the new sorting, and then change the sorting asked by the user to add a previous sort by the sum columns.
Weird.
And Mostly useless.
Maybe you can put your ALV in a custom control, and use other screen zone for show the subtotals (or the footer section if you use OO)

raymond_giuseppi
Active Contributor
0 Kudos
229

In REUSE_ALV_GRID_DISPLAY you can get the instance of CL_GUI_ALV_GRID with FM GET_GLOBALS_FROM_SLVC_FULLSCR.

Then you can do everything you want handling event AFTER_REFRESH of the class to call method GET_SUBTOTALS and get reference to subtotals table. It would be easier (or at least less difficult) to add some hidden row(s) defined as a sort/subtotal key to contain truncated value of rownum / 10. (sum the totals to following total)