4.66666666667 1 1 1 1 1 Rating 93% (3 Votes)
ALV Grid gives us some possibilities for easier reading of the grid content like "zebra" or colored rows. But when this is not enough and you want to make sure that users will focus on part of the rows only, then you have additionally two options:
1st) Add empty line after each part you want to separate and color it differently; 
2nd) Use subototals of ALV Grid to do it instead of you (but without any values).

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. 
I will use event subtotal_text for cl_gui_alv_grid, three additional colums in internal table (for sorting and separating key) and  lvc_s_layo settings NO_TOTEXPNO_TOTLINENO_ROWMARK.
First of all lest prepare method for subtotal_text event handling. Definition as usual:

methodssubtotal_text
  
for event subtotal_text of cl_gui_alv_grid
  
importing
      es_subtottxt_info
      ep_subtot_line
      e_event_data
.  

and the implementation in which I'm clearing all descriptions from subtotals:

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

Of course don't forget to set the event handler:

set handler go_event_receiver->subtotal_text for go_grid.

We have now our method implemented, so now it's time to add our 3 additional columns. I will call them "SUBTOTALKEY", "SORTKEY" AND "COUNT".
  • 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.
Our fields are defined so lets set fieldcatalog and sort properties for them (lvc_s_sort):

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.

 
When we have our fieldcatalog and sorting info ready, it's time to set some layout properties:

  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

Now if you use such prepared layout, sort info, fieldcatalog and event handler then as a result you'll have subtotal lines without any text separating your data on grid:
 
Our sort info would look like this:

Have fun!