Skip to Content

ALV report Subtotal custom text in OO ALV

Aug 10, 2017 at 05:09 PM


avatar image

Hi Friends,

I have done lot of search and tried with different options before posting this question.

I am using OO ALV with method - set_table_for_first_display

My scenario, report will use 2 levels for sorting process(field1 and field2) and 2 fields for Sub totals(field3 and field4). ( I need all the 4 fields in the output including the sorting fields). How to pass the subtotal custom text for these 2 sorting levels ?

I tried method subtotal_text but this requires in sorting no_out = 'X'.

My text will be same for all level1 and Level2 records, so I cant use them in sorting process if I create new Text fields.

Any hints .pls let me know ..

Thank You.


alv-text.png (5.5 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sandra Rossi Aug 11, 2017 at 06:56 AM

You have the event SUBTOTAL_TEXT of CL_GUI_ALV_GRID (cf subtotal_text)

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Sandra,

Thanks for the reply. I tried this already. If I use this event what fields should I give in sort process?

As my data should be sorting based on first and second fields as per my logic. I can't use the 3rd field(Text field) for sort.

Please let me know on this.



It's explained in the official documentation (URL above) how it works. The basics for using this feature is to hide the subtotal column.

You may test with program BCALV_GRID_TEST_EVENTS:

  • Sort by "plane type"
  • Set totals for "occupied" (number of seats)
  • Set subtotals for "plane type"
  • Hide column "plane type" -> the event SUBTOTAL_TEXT is triggered for every subtotal line of plane type, you may define any text you want, which is displayed from the first column (exception column excluded).

In the demo, SAP replace all subtotal lines with the same text "My Subtotals Text", but it should better be "My Subtotals for plane type 146-200" for the first subtotal line whose plane type value is 146-200, etc.

If you want the column not being hidden, you may cheat the program by simply creating an additional column with the same values.

8tgyg.png (65.8 kB)