Step 1:
Desired cells of the SAP ALV Display can be colored using the structure lvc_s_scol. The color codes must be set to each line of record. Therefore the structure of the ALV Display must be extended with the additional field with an internal table of type lvc_t_scol.
TYPES: BEGIN OF ty_contact.
INCLUDE STRUCTURE ztt_db_table2.
TYPES: color_field TYPE lvc_t_scol,
END OF ty_contact.
DATA ls_color_field TYPE lvc_s_scol.
DATA lr_all_columns TYPE REF TO cl_salv_columns_table.
DATA lt_contact TYPE TABLE OF ty_contact.
SELECT * FROM ztt_db_table2 INTO TABLE lt_contact.
Lr_all_columns = lr_salv_table->get_columns( ).
Step2:
Make the ALV Table recognize the newly added ‘color_field’ with the help of the method set_color_column( ) of class CL_SALV_COLUMNS_TABLE.
Lr_all_columns->set_color_column( ‘COLOR_FIELD’ ).
Step3:
Finally fill the internal table ( new field ) with the desired color codes.
DATA ls_contact TYPE ztt_db_table2.
LOOP AT lt_contact ASSIGNING ls_contact WHERE age > 30.
Ls_color_field-fname = ‘CONTACT_ADDRESS’.
Ls_color_field-color-col = 7.
Ls_color_field-color-int = 1.
Ls_color_field-color-inv = 1.
APPEND ls_color_field TO ls_contact-color_field.
ENDLOOP.