ALV color palette - example based on class CL_SALV_TABLE

There are some colors in ALV possible. You can combine them with attributes for intensification and inversion to get a bit more then 8 standard colors. First row is displayed in default color.
Here the complete palette:
and the related coding to reproduce it in your system:
PROGRAM zkmalvcp.

  BEGIN OF ts_data,
    col   TYPE lvc_col,    " color 1-7
    int   TYPE lvc_int,    " intensified 0-1
    inv   TYPE lvc_inv,    " inverse 0-1
    scol  TYPE lvc_t_scol, " table for cell coloring
  END OF ts_data,
  tt_data TYPE TABLE OF ts_data.

  ls_data    TYPE ts_data,
  lt_data    TYPE tt_data,
  lv_index   TYPE i,
  ls_color   TYPE lvc_s_scol,
  lt_color   TYPE lvc_t_scol,
  lo_table   TYPE REF TO cl_salv_table,
  lo_columns TYPE REF TO cl_salv_columns_table,
  lo_column  TYPE REF TO cl_salv_column_list.

* empty row with default color
APPEND ls_data TO lt_data.

* rows with possible colors

  ls_color-color-col = sy-index.   " 1-7


    lv_index = sy-index - 1.
    ls_color-color-int = lv_index.   " 0-1

    DO 2 TIMES.

      lv_index = sy-index - 1.
      ls_color-color-inv = lv_index.   " 0-1

      APPEND ls_color TO lt_color.

      ls_data-col   = ls_color-color-col.
      ls_data-int   = ls_color-color-int.
      ls_data-inv   = ls_color-color-inv.

      ls_data-scol = lt_color.
      APPEND ls_data TO lt_data.
      CLEAR lt_color.

    CALL METHOD cl_salv_table=>factory
        r_salv_table = lo_table
        t_table      = lt_data.

    lo_columns = lo_table->get_columns( ).

*   set descriptions of columns
    lo_column ?= lo_columns->get_column( 'COL' ).
    lo_column->set_short_text( 'COL' ).

    lo_column ?= lo_columns->get_column( 'INT' ).
    lo_column->set_short_text( 'INT' ).

    lo_column ?= lo_columns->get_column( 'INV' ).
    lo_column->set_short_text( 'INV' ).

*   set the column with the information about colors of rows and fields
    lo_columns->set_color_column( 'SCOL' ).

    lo_table->display( ).

  CATCH cx_salv_msg.             " cl_salv_table=>factory
    WRITE: / 'cx_salv_msg exception'.

  CATCH cx_salv_data_error.      " cl_salv_filters->add_filter()
    WRITE: / 'cx_salv_data_error'.

  CATCH cx_salv_not_found.       " cl_salv_columns_table->get_column()
    WRITE: / 'cx_salv_not_found exception'.
See other related notes in my infodepot:
How to avoid displaying zero in data cells in ALV
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2010

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.