Code: Alles auswählen.
REPORT z_farbe_alv.
TYPE-POOLS: slis.
*&---------------------------------------------------------------------*
*& Include (Anfang) Z_DECLARATION_PART
*&---------------------------------------------------------------------*
* Feldkatalog für ALV
DATA: it_cat TYPE slis_t_fieldcat_alv,
wa_cat TYPE slis_fieldcat_alv.
* Struktur für interne tabelle die dem ALV übergeben wird
TYPES: BEGIN OF meine_struktur,
kopf1 TYPE string,
kopf2 TYPE string,
kopf3 TYPE string,
kopf4 TYPE string,
kopf5 TYPE string,
kopf6 TYPE string,
kopf7 TYPE string,
kopf8 TYPE string,
kopf9 TYPE string,
kopf10 TYPE string,
kopf11 TYPE string,
color TYPE slis_t_specialcol_alv,
END OF meine_struktur.
* interne Tabelle und Arbeitsbereich
DATA: itab TYPE TABLE OF meine_struktur,
wa TYPE meine_struktur.
*&---------------------------------------------------------------------*
*& Include (Ende)
*&---------------------------------------------------------------------*
DATA: I_COLOR_TAB TYPE SLIS_T_SPECIALCOL_ALV.
DATA: WA_COLOR_TAB TYPE SLIS_SPECIALCOL_ALV.
DATA: G_CELL_COLOR TYPE SLIS_COLOR.
refresh i_color_tab.
*choose your own conditions here
G_CELL_COLOR-COL = 7.
G_CELL_COLOR-INT = 1.
WA_COLOR_TAB-FIELDNAME = 'COLOR'.
WA_COLOR_TAB-COLOR = G_CELL_COLOR.
APPEND WA_COLOR_TAB TO I_COLOR_TAB.
PERFORM baue_feldkatalog.
PERFORM fuelle_itab.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = it_cat[]
i_callback_program = 'Z_FARBE_ALV'
i_screen_start_column = 0
i_screen_start_line = 0
i_screen_end_column = 0
i_screen_end_line = 0
TABLES
t_outtab = itab
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.
*&---------------------------------------------------------------------*
*& Form baue_feldkatalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM baue_feldkatalog.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF1'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '1'. "#EC NOTEXT
wa_cat-seltext_m = '1'. "#EC NOTEXT
wa_cat-seltext_s = '1'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF2'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '2'. "#EC NOTEXT
wa_cat-seltext_m = '2'. "#EC NOTEXT
wa_cat-seltext_s = '2'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF3'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '3'. "#EC NOTEXT
wa_cat-seltext_m = '3'. "#EC NOTEXT
wa_cat-seltext_s = '3'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF4'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '4'. "#EC NOTEXT
wa_cat-seltext_m = '4'. "#EC NOTEXT
wa_cat-seltext_s = '4'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF5'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '5'. "#EC NOTEXT
wa_cat-seltext_m = '5'. "#EC NOTEXT
wa_cat-seltext_s = '5'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF6'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '6'. "#EC NOTEXT
wa_cat-seltext_m = '6'. "#EC NOTEXT
wa_cat-seltext_s = '6'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF7'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '7'. "#EC NOTEXT
wa_cat-seltext_m = '7'. "#EC NOTEXT
wa_cat-seltext_s = '7'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF8'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '8'. "#EC NOTEXT
wa_cat-seltext_m = '8'. "#EC NOTEXT
wa_cat-seltext_s = '8'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF9'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '9'. "#EC NOTEXT
wa_cat-seltext_m = '9'. "#EC NOTEXT
wa_cat-seltext_s = '9'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF10'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '10'. "#EC NOTEXT
wa_cat-seltext_m = '10'. "#EC NOTEXT
wa_cat-seltext_s = '10'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = 'KOPF11'.
wa_cat-datatype = 'STRING'.
wa_cat-seltext_l = '11'. "#EC NOTEXT
wa_cat-seltext_m = '11'. "#EC NOTEXT
wa_cat-seltext_s = '11'. "#EC NOTEXT
APPEND wa_cat TO it_cat.
CLEAR wa_cat.
ENDFORM. "baue_feldkatalog
*&---------------------------------------------------------------------*
*& Form fülle_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fuelle_itab.
wa-kopf1 = 'Sollen'.
wa-kopf2 = 'alle'.
wa-kopf3 = 'Zellen'.
wa-kopf4 = 'wo'.
wa-kopf5 = 'ein'.
wa-kopf6 = 'E'.
wa-kopf7 = 'drinne'.
wa-kopf8 = 'steht,'.
wa-kopf9 = 'rot'.
wa-kopf10 = 'sein'.
wa-kopf11 = '?'.
MOVE I_COLOR_TAB TO wa-COLOR.
INSERT wa INTO TABLE itab.
ENDFORM. "fülle_itab
Code: Alles auswählen.
*Layout fürs ALV
DATA: wa_layout TYPE slis_layout_alv.
*Dann festlegen, in welcher Spalte der ITAB deine FarbStruktur ist.
wa_layout-coltab_fieldname = 'COLOR'.
* Diese Zeile ändern.
* wa_color_tab-fieldname = 'COLOR'.
* In die Tabelle i_color_tab muss für jede Zelle, die gefärbt werden soll, ein Eintrag.
*In meinem Beispiel werden die KOPF1 und KOPF5 gefärbt.
g_cell_color-col = 7. "Orange
g_cell_color-int = 1.
wa_color_tab-fieldname = 'KOPF1'.
wa_color_tab-color = g_cell_color.
APPEND wa_color_tab TO i_color_tab.
g_cell_color-col = 5. "Grün
g_cell_color-int = 1.
wa_color_tab-fieldname = 'KOPF5'.
wa_color_tab-color = g_cell_color.
APPEND wa_color_tab TO i_color_tab.
*nun nur noch im Bausteinaufruf die Zeile is_layout dazu
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = it_cat
i_callback_program = 'Z_FARBE_ALV'
i_screen_start_column = 0
i_screen_start_line = 0
i_screen_end_column = 0
i_screen_end_line = 0
is_layout = wa_layout
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
Folgende Benutzer bedankten sich beim Autor mcdelta0six für den Beitrag:
Zubasa