ALV has three color settings: Row, column, and cell. 1. Set the color of the column in The slis_t_fieldcat_alv-emphasize, write the color code you need. Eg: Data: fc type slis_t_fieldcat_alv with header line. FC-tabname = 'itab '. FC-fieldname = 'col '. FC-emphasize = 'c100 '. append FC. 2. row color settings. in the itab to be output, add the color column with the type C (4) to record the required color code. B. Set layout. Alv_layout-info_fieldname = 'color '. eg: Data: Begin of itab occurs 0. include structure Mara. data: color (4) type C. data: End of itab. data: alv_layout type slis_layout_alv. itab-matnr = '000000 '. itab-color = 'c200 '. append itab. alv_layout-info_fieldname = 'color '. 3. cell color settings. in the itab to be output, add the color column of the slis_t_specialcol_alv type to record the required color code. B. Set layout. Alv_layout-coltab_fieldname = 'color '. eg: Data: Begin of itab occurs 0. include structure Mara. data: color type slis_t_specialcol_alv. data: End of itab. data: color type slis_t_specialcol_alv. data: alv_layout type slis_layout_alv. color-Col = '1 '.
Color-Int = '0 '.
Color-inv = '0 '.
Color-fieldname = 'col '. append color. itab-matnr = '000000 '. itab-color [] = color []. append itab. alv_layout-coltab_fieldname = 'color '. the above is my summary of the ALV grid coloring method. Due to the limited technical level, there may still be some omissions. Example code: Report ztest.
"Double-click the cell to enter the new ALV screen.
Type-pools: slis.
* A total of three internal tables are defined.
* Itab1: Set the column color,
* Itab2: Set the row color.
* Itab3: Set the cell color.
Data: Begin of itab_test occurs 0,
Col1 (4) type C,
Col2 (4) type C,
Col3 (4) type C,
Col4 (4) type C,
Col5 (4) type C,
Col6 (4) type C,
End of itab_test.
Data: Begin of itab_test2 occurs 0.
Include structure itab_test.
Data: color (4) type C.
Data: End of itab_test2.
Data: Begin of itab_test3 occurs 0.
Include structure itab_test.
Data: color type slis_t_specialcol_alv.
Data: End of itab_test3.
Data: fc type slis_t_fieldcat_alv with header line,
FC2 type slis_t_fieldcat_alv with header line,
FC3 type slis_t_fieldcat_alv with header line.
Start-of-selection.
Perform create_data.
End-of-selection.
Perform fieldcat_build.
Perform show_alv.
*&---------------------------------------------------------------------*
* & Form create_data
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form create_data.
Data: l_color (4) type C,
Rochelle char type C,
I type I.
Data: color type slis_t_specialcol_alv with header line.
Refresh itab_test.
Refresh itab_test2.
Refresh itab_test3.
Refresh FC.
Refresh FC2.
Refresh FC3.
While sy-index <8.
* Inner table 1
Itab_test-col1 = (sy-index-1) * 6 + 1.
Itab_test-col2 = (sy-index-1) * 6 + 2.
Itab_test-col3 = (sy-index-1) * 6 + 3.
Itab_test-col4 = (sy-index-1) * 6 + 4.
Itab_test-col5 = (sy-index-1) * 6 + 5.
Itab_test-col6 = (sy-index-1) * 6 + 6.
Append itab_test.
* Inner table 2
Move-corresponding itab_test to itab_test2.
L_char = sy-index.
I = sy-index mod 2.
If I = 0.
Concatenate 'C' l_char '01 'into l_color.
Else.
Concatenate 'C' l_char '10' into l_color.
Endif.
Itab_test2-color = Rochelle color.
Append itab_test2.
* Inner table 3
Move-corresponding itab_test to itab_test3.
Refresh color.
Color-Col = l_char.
Color-Int = '0 '.
Color-inv = '0 '.
Color-fieldname = 'col1'. append color.
Concatenate l_char '00' into itab_test3-col1.
Color-Int = '0 '.
Color-inv = '1 '.
Color-fieldname = 'col2'. append color.
Concatenate l_char '01 'into itab_test3-col2.
Color-Int = '1 '.
Color-inv = '0 '.
Color-fieldname = 'col3'. append color.
Concatenate l_char '10' into itab_test3-col3.
Itab_test3-color [] = color [].
Append itab_test3.
Endwhile.
Endform. "create_data
**************************************** ********************************
Form fieldcat_build.
Data: Begin of fc_struct,
Tabname (10 ),
Fieldname (5 ),
Seltext_m (5 ),
Emphasize (4 ),
End of fc_struct.
Define AC.
Clear: fc, FC2, fc_struct.
Fc_struct = & 1.
FC-tabname = fc_struct-tabname. "inner table name
FC-fieldname = fc_struct-fieldname. "field name
Fc-seltext_m = fc_struct-seltext_m. "field description
FC-emphasize = fc_struct-emphasize. "column color
Append FC.
Fc2-tabname = fc_struct-tabname. "In table name
Fc2-fieldname = fc_struct-fieldname. "field name
Fc2-seltext_m = fc_struct-seltext_m. "field description
Append FC2.
If fc3-fieldname <'col4 '.
Fc3-tabname = fc_struct-tabname. "In table name
Fc3-fieldname = fc_struct-fieldname. "field name
Fc3-seltext_m = fc_struct-seltext_m. "field description
Append FC3.
Endif.
End-of-definition.
Ac'itab _ test col1 col1 c100 '.
Ac'itab _ test col2 col2 c200 '.
Ac'itab _ test col3 col3 c300 '.
Ac'itab _ test col4 col4 c400 '.
Ac'itab _ test col5 col5 c500 '.
Ac'itab _ test col6 col6 c600 '.
Endform. "fieldcat_build
*&---------------------------------------------------------------------*
* & Form show_alv
*&---------------------------------------------------------------------*
* Show inner table 1
*----------------------------------------------------------------------*
Form show_alv.
Call function 'reuse _ alv_grid_display'
Exporting
I _callback_program = sy-repid
It_fieldcat = FC []
I _callback_user_command = 'process _ user_command_1'
I _save = 'A'
Tables
T_outtab = itab_test
Exceptions
Program_error = 1
Others = 2.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.
Endform. "show_alv
*&---------------------------------------------------------------------*
* & Form process_user_command_1
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Ucomm text
* --> Rs_selfield text
*----------------------------------------------------------------------*
Form process_user_command_1 using ucomm
Rs_selfield type slis_selfield.
If rs_selfield-fieldname <> space and rs_selfield-tabindex> 0.
Perform show_alv_2.
Endif.
Endform. "process_user_command_1
*&---------------------------------------------------------------------*
* & Form show_alv_2
*&---------------------------------------------------------------------*
* Display table 2
*----------------------------------------------------------------------*
Form show_alv_2.
Data: alv_layout type slis_layout_alv.
Alv_layout-info_fieldname = 'color '.
Call function 'reuse _ alv_grid_display'
Exporting
I _callback_program = sy-repid
It_fieldcat = FC2 []
I _callback_user_command = 'process _ user_command_2'
Is_layout = alv_layout
I _save = 'U'
Tables
T_outtab = itab_test2
Exceptions
Program_error = 1
Others = 2.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.
Endform. "show_alv_2
*&---------------------------------------------------------------------*
* & Form process_user_command_2
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Ucomm text
* --> Rs_selfield text
*----------------------------------------------------------------------*
Form process_user_command_2 using ucomm
Rs_selfield type slis_selfield.
If rs_selfield-fieldname <> space and rs_selfield-tabindex> 0.
Perform show_alv_3.
Endif.
Endform. "process_user_command_2
*&---------------------------------------------------------------------*
* & Form show_alv_3
*&---------------------------------------------------------------------*
* Show table 3
*----------------------------------------------------------------------*
Form show_alv_3.
Data: alv_layout type slis_layout_alv.
Alv_layout-coltab_fieldname = 'color '.
Call function 'reuse _ alv_grid_display'
Exporting
I _callback_program = sy-repid
It_fieldcat = FC3 []
Is_layout = alv_layout
I _save = 'U'
Tables
T_outtab = itab_test3
Exceptions
Program_error = 1
Others = 2.
If sy-subrc <> 0.
Message ID sy-msgid type sy-msgty number sy-msgno
With sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
Endif.
Endform. "show_alv_3
ALV row column color settings