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 show only the aggregated value and not the individual records using CL_SALV_TABLE

former_member623629
Participant

Hello Everyone,

I am required to write codes which will generate an alv. In the ALV the time field will be aggregated depending on the Kostenart. The additional requirement is that the ALV should only output the aggregated amount and the not the records. That means if Kostenart Y001 got 2 records of total 135 minutes (90+45) then only 135 minitues will come as output not the 90 and 45. If my question is not clear then please feel free to look at the screen shot. It will give a much clearer view.

Your suggestions will be highly appreciated.

Thanks in advance

Arnab

  cl_salv_table=>factory(
  IMPORTING r_salv_table = g_o_table
  CHANGING t_table = g_it_output ).

  "Funktionen aktivieren
  g_o_functions = g_o_table->get_functions( ).
  g_o_functions->set_all( abap_true ).
  g_o_display = g_o_table->get_display_settings( ).

  g_o_display->set_striped_pattern( abap_true ).
  g_o_columns = g_o_table->get_columns( ).

  "Um spalten aus zu blenden
  g_o_column ?= g_o_columns->get_column( 'MANDT' ).
  g_o_column->set_technical( if_salv_c_bool_sap=>true ).
  g_o_column ?= g_o_columns->get_column( 'AWE_ID' ).
  g_o_column->set_technical( if_salv_c_bool_sap=>true ).

  "Spalten optimieren
  g_o_columns->set_optimize( abap_true ).

  "Um Daten zu sortieren
  g_o_sorts = g_o_table->get_sorts( ).
  g_o_sorts->add_sort( columnname = 'KOSTENART' subtotal = abap_true ).
  g_o_sorts = g_o_table->get_sorts( ).
  g_o_sorts->add_sort( columnname = 'MATNR' subtotal = abap_true ).

  "Zu aggregieren
  g_o_agg = g_o_table->get_aggregations( ).
  g_o_agg->add_aggregation( 'ZEIT' ).
1 ACCEPTED SOLUTION

michael_piesche
Active Contributor

1) If the user still wants to be able to expand the view from collapsed to un-collapsed, you can work with saving the layout. This is a one time user process.

You can save the layout of the collapsed ALV view and make it a system or just a user default. If it is a default, it will be automatically opened this way, the next time the user opens that ALV. This way, you dont have to programm anything.

2) If the user doesnt want to know anything about the details and always just view the aggregation, you should aggregate the table before passing it to the ALV.

6 REPLIES 6

Sandra_Rossi
Active Contributor

NB: why don't you clarify with example from screenshot? (45+90 gives 135, instead of explaining with 2+3+1 gives 6).

I doubt that the solution of displaying a total line alone, without the detail lines, is feasible because it's against ALV principle.

I guess a more feasible solution would be to collapse the detail lines automatically for those with KostenArt = 'Y001', but I doubt it's feasible with standard features. You may compress/expand the nodes of a whole level, but you can't do it for only one subtotaled group of lines. Maybe you could do it if you tweak the standard (!!), by changing the attribute MT_GROUPLEVELS_FILTER which is set inside the private method GET_GROUPLEVELS of CL_GUI_ALV_GRID/of course you also need to determine the grid instance which is instantiated by your SALV instance, this attribute has the attribute COMPRESS which is transferred to the frontend to indicate what groups are to be compressed.

Seriously, you should not change the standard, and it's risky and it will take you a lot of time to do it. So, one workaround is to limit the number of detail lines by summing them into one detail line in the main internal table (not an ALV feature).

former_member623629
Participant

sandra.rossi Thanks for the explanations. I have already tried with compress. Let's see whether the person who requested to make the program is okay with it or not. Thanks again. I appreciate.

michael_piesche
Active Contributor

1) If the user still wants to be able to expand the view from collapsed to un-collapsed, you can work with saving the layout. This is a one time user process.

You can save the layout of the collapsed ALV view and make it a system or just a user default. If it is a default, it will be automatically opened this way, the next time the user opens that ALV. This way, you dont have to programm anything.

2) If the user doesnt want to know anything about the details and always just view the aggregation, you should aggregate the table before passing it to the ALV.

Thanks. The suggestions were really helpful.

arnab19871 Didn't you want only one group of lines to be compressed programatically, and the rest remain expanded? (because in your screenshot your example was only for one group of lines, and in your explanation you were talking about the Kostenart Y001)Note that the solution by Michael can be achieved programatically too when the ALV is first displayed (expand or compress at a given sort level).

0 Kudos

See set_compressed_subtotal method of cl_salv_sorts class