Multi Color ALV Grid Color Alternate using ALV Layout info_fname Property
For a better view in ABAP lists created using ABAP ALV objects on ABAP reports, SAP developers and ABAP programmers generally use Zebra layout style.
Using Zebra Layout in ALV Grid objects for example cl_gui_alv_grid type ALV grids, enables lists whose lines have alternating colors.
This is generally a good feature for tracing a line or tracing a row of values on an ALV Grid list object.
Unfortunately, some times ABAP develoeperS requirements can go further than using alternating colors of subsequent rows.
For example the below screenshot is from an ABAP program which lists possible dublicate sales orders in a SAP system.
So each pair is shown in a single color and the following pair is in alternating color.
Or the next pair is displayed on ALV grid with a different color.
The cl_gui_alv_grid ALV Grid object is being displayed on the sample ABAP program using the following ABAP code.
The set_table_for_first_display method of the cl_gui_alv_grid object is used with layout parameter is_layout, data table parameter it_outtab and field catalog parameter it_fieldcatalog.
Until here there is no difference from calling an ordinary ALV Grid to display on an ABAP report SAP screen.
Actually for ABAP developers, the difference is within the data table parameter it_outtab or gt_dublicates.
In the below ABAP code fragment, you can see that there is an additional column named LINE_COLOR declared in 4 character type.
We will use LINE_COLOR column to hold color information related for the row.
So we can customize different colors for each row in the data structure or in the data table itself.
And the ABAP code block for assigning color codes to the line_color column of each row in the internal table can be manged by using the sy-tabix counter values and the ABAP MOD arithmetic command.
One last step to successfully apply different colors to cl_gui_alv_grid ALV Grid list is to set the value of the grid layout parameter gs_layout info_fname property value to column name LINE_COLOR before calling the ALV grid set_table_for_first_display method.
Here ABAP programmers can find downloadable sample ABAP report for alv coloring.
Also ABAP developers will sample ABAP report at ALV Grid Color - Table Row Background Color in ALV List where all different ALV grid color combinations are used for ALV list table row background color.