Zellenfarbe ändern (REUSE_ALV_LIST_DISPLAY)

Getting started ... Alles für einen gelungenen Start.
4 Beiträge • Seite 1 von 1
4 Beiträge Seite 1 von 1

Zellenfarbe ändern (REUSE_ALV_LIST_DISPLAY)

Beitrag von Zubasa (ForumUser / 72 / 10 / 1 ) »
Hallo ^^,

kann mir jemand helfen und mir erklären, wie man eine Zelle im ALV farbig macht?
Ich bin schon die ganze Zeit am googeln und habe auch viel gefunden, es aber trotzdem nicht hingekriegt :-(.

Ich zeige euch einfach mal am Besten, was ich bis jetzt gebastelt habe (Hoffe ist nicht zuviel code auf einmal).

Bitte helft mir :cry: :

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



Mit der Hoffnung, dass das jemand versteht.
Für Hilfe wäre ich unglaublich dankbar.

Gruß,
Zubasa

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Re: Zellenfarbe ändern (REUSE_ALV_LIST_DISPLAY)

Beitrag von wreichelt (Top Expert / 1042 / 30 / 191 ) »
Hallo Zubasa,

bestimmt was verwetbares dabei:
Farben im ALV-Grid

data:

* Type fuer ALV Grid
BEGIN OF t_alv,
.....
.....
linecolor(4) TYPE c, " Zeilenfarbe
cellcolor TYPE lvc_t_scol, " Zellenfarbe
END OF t_alv.

gt_alv TYPE TABLE OF t_alv, " interne Tabelle
gs_alv LIKE LINE OF gt_alv, " Arbeitsbereich

* Arbeitsbereich Farbe für Zellen

wa_cellcolor LIKE LINE OF cellcolor.



* Zeile färben
LOOP AT gt_alv INTO gs_alv.
CLEAR gs_alv-linecolor.
IF NOT gs_alv-adpos IS INITIAL.
gs_alv-linecolor = 'C300'.
ENDIF.

CLEAR gs_alv-cellcolor.

* Zelle färben
IF gs_alv-posnr NE gs_alv-sposnr.
wa_cellcolor-fname = 'POSNR'. " Feldname
wa_cellcolor-color-col = '3'. " Farbe
wa_cellcolor-color-int = 1. " Intensiv
wa_cellcolor-color-inv = 0. " Invers
wa_cellcolor-nokeycol = 0. " Farbe auch bei key
APPEND wa_cellcolor TO gs_alv-cellcolor.
ENDIF.
*
MODIFY gt_alv FROM gs_alv
TRANSPORTING cellcolor.
ENDLOOP.

Gruß Wolfgang

Folgende Benutzer bedankten sich beim Autor wreichelt für den Beitrag:
Zubasa


Re: Zellenfarbe ändern (REUSE_ALV_LIST_DISPLAY)

Beitrag von mcdelta0six (ForumUser / 8 / 0 / 2 ) »
Hallo,

du hast es fast geschafft.



Füge die folgenden Zeilen ein:

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


Re: Zellenfarbe ändern (REUSE_ALV_LIST_DISPLAY)

Beitrag von Zubasa (ForumUser / 72 / 10 / 1 ) »
Vielen Dank,

hat super geklappt!

Grüße,
Zubasa

Seite 1 von 1

Vergleichbare Themen

2
Antw.
2919
Views
REUSE _ ALV _ LIST _ DISPLAY - Zeile nicht markieren
von Gast » 12.09.2005 08:42 • Verfasst in ABAP® Core
6
Antw.
5233
Views
Checkbox-Inhalt bei REUSE-ALV-GRID-DISPLAY-LVC
von Ucke » 19.11.2006 21:18 • Verfasst in ABAP® Core
9
Antw.
5509
Views
CL_GUI_ALV_GRID Zellenfarbe dynamisch ändern
von Pinguincommander » 30.04.2013 09:43 • Verfasst in ABAP® Core
2
Antw.
4275
Views
message (...) DISPLAY LIKE
von an4kh4 » 21.03.2007 14:42 • Verfasst in ABAP® für Anfänger
4
Antw.
5001
Views
Set table for first display
von pippi1710 » 27.10.2011 10:34 • Verfasst in ABAP® für Anfänger

Über diesen Beitrag


Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.