05-07-2020 9:13 AM
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' ).
05-07-2020 3:24 PM
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.
05-07-2020 11:02 AM
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).
05-07-2020 11:12 AM
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.
05-07-2020 3:24 PM
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.
05-08-2020 8:02 AM
05-08-2020 2:39 PM
05-27-2022 1:29 PM