1st) Add empty line after each part you want to separate and color it differently;
Adding empty lines will force you to delete all of them each time you'll do changes inside table displayed in grid and you'll have to do the calculation of position again, that's why today I will show you the second option.
methods: subtotal_text
for event subtotal_text of cl_gui_alv_grid
importing
es_subtottxt_info
ep_subtot_line
e_event_data.
method subtotal_text.
field-symbols: <fs> type any.
assign e_event_data->m_data->* to <fs>.
if sy-subrc eq 0.
clear <fs>.
endif.
assign ep_subtot_line->* to <fs>.
if sy-subrc eq 0.
clear <fs>.
endif.
endmethod. "subtotal_text
set handler go_event_receiver->subtotal_text for go_grid.
- SUBTOTALKEY ( type any but I prefer CHAR fields with lenght 16-18) - I will use to separate lines in grid (for example each sales order separately or each sales order line separately).
- SORTKEY ( type I ) - will be used to sort entries for each SUBTOTAL separately (if needed)
- COUNT ( type I ) - will be always empty, used to set up a summary on that field so subtotal lines are displayed in grid.
loop at gt_fcat assigning <fcat>.
case <fcat>-fieldname.
when 'SUBTOTALKEY'.
<fcat>-no_out = 'X'. "hide column on screen
fs_sort-spos = 1. "first sorting key
fs_sort-fieldname = <fcat>-fieldname. "fieldname for sort
fs_sort-up = 'X'. "sort ascending
fs_sort-subtot = 'X'. "do subtotal
fs_sort-no_out = 'X'. "no display
fs_sort-obligatory = 'X'. "sort is obligatory
insert fs_sort into table gt_sort. "insert to sort table
when 'SORTKEY'.
<fcat>-no_out = 'X'. "hide column on screen
fs_sort-spos = 2. "second sortign key
fs_sort-fieldname = <fcat>-fieldname. "sort fieldname
fs_sort-up = 'X'. "sort ascending
fs_sort-no_out = 'X'. "no display
insert fs_sort into table gt_sort. "insert to sort table
when 'COUNT'.
<fcat>-do_sum = 'X'. "do sum
<fcat>-col_opt = 'X'. "optimize width
<fcat>-no_zero = 'X'. "do not diplay zeros (space instead)
endcase.
endloop.
gs_layout-no_totline = 'X'. "do not display totals, just subtotals will be displayed
gs_layout-no_totexp = 'X'. "do not show expand icons for subtotals
gs_layout-no_rowmark = 'X'. "do not show row selection on the left of grid
Have fun!