Skip to Content

Here I attached an example quite useful to know the different cell colors we can give to a ALV.


*&———————————————————————*
*& Report  ZCELL_COLORS
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

REPORT  ZCELL_COLORS.

TYPES:
   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.

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
DO 7 TIMES.

   ls_colorcolorcol = syindex.   ” 1-7

   DO 2 TIMES.

     lv_index = syindex 1.
     ls_colorcolorint = lv_index.   ” 0-1

     DO 2 TIMES.

       lv_index = syindex 1.
       ls_colorcolorinv = lv_index.   ” 0-1

       APPEND ls_color TO lt_color.

       ls_datacol   = ls_colorcolorcol.
       ls_dataint   = ls_colorcolorint.
       ls_datainv   = ls_colorcolorinv.

       ls_datascol = lt_color.
       APPEND ls_data TO lt_data.
       CLEAR lt_color.
     ENDDO.
   ENDDO.
ENDDO.

TRY.
     CALL METHOD cl_salv_table=>factory
       IMPORTING
         r_salv_table = lo_table
       CHANGING
         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’.
     STOP.

   CATCH cx_salv_data_error.      ” cl_salv_filters->add_filter()
     WRITE: / ‘cx_salv_data_error’.
     STOP.

   CATCH cx_salv_not_found.       ” cl_salv_columns_table->get_column()
     WRITE: / ‘cx_salv_not_found exception’.
     STOP.
ENDTRY.

*————————————————

Regards.


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply