Coloring Record in ALV Grid

How to do coloring for single record in alv grid display?

To give color for single record add one more field to your output internal table.

Let say you have 

itab_out with structure as

TYPES : BEGIN OF TY_COLS,
         YCONS(50)     TYPE C,
         YMON01(10)    TYPE C,
         YMON02(10)    TYPE C,
         YMON03(10)    TYPE C, 
         YCOL(4),  " this field to be added ...
END OF TY_COLS. 

DATA: WA_COLS TYPE TY_COLS,
              TA_COLS TYPE TABLE OF TY_COLS.

FORM BUILD_LAYOUT.
  TA_LAYOUT1-ZEBRA             = 'X'.
  TA_LAYOUT1-INFO_FIELDNAME    = 'YCOL'."this is field to beadded
  TA_LAYOUT1-COLWIDTH_OPTIMIZE = 'X'.
  TA_LAYOUT1-BOX_TABNAME       = 'TA_COLS '.
ENDFORM. 

and then 
add this number to that row where you want color....that's it...

WA_COLS-YCONS = TEXT-017.
WA_COLS-YCOL   = 'C400'.
APPEND WA_COLS TO TA_COLS. 

*-- End of Program

Sample Colour Program

*&---------------------------------------------------------------------*
*& Report  ZGS_ALV_COLOUR
*&---------------------------------------------------------------------*

REPORT  ZBGR_ALV_COLOR.
TYPE-POOLS:SLIS.

DATA:BEGIN OF ITAB OCCURS 0,
     VBELN LIKE VBAP-VBELN,
     POSNR LIKE VBAP-POSNR,
     MATNR LIKE VBAP-MATNR,
     NETWR LIKE VBAP-NETWR,
     COLOR(4),
     END OF ITAB.

DATA:FCAT TYPE SLIS_T_FIELDCAT_ALv.
*     CAT TYPE SLIS_FIELDCAT_ALV.

DATA:LAYOUT TYPE SLIS_LAYOUT_ALV,
      SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.

START-OF-SELECTION.
SELECT VBELN POSNR MATNR NETWR FROM VBAP INTO TABLE ITAB UP TO 30 ROWS.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
   I_PROGRAM_NAME               = SY-CPROG
   I_INTERNAL_TABNAME           = 'ITAB'
*   I_STRUCTURE_NAME             =
   I_CLIENT_NEVER_DISPLAY       = 'X'
   I_INCLNAME                   = SY-CPROG
*   I_BYPASSING_BUFFER           =
*   I_BUFFER_ACTIVE              =
  CHANGING
    CT_FIELDCAT                  = FCAT
* EXCEPTIONS
*   INCONSISTENT_INTERFACE       = 1
*   PROGRAM_ERROR                = 2
*   OTHERS                       = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

SORT-SPOS = 1.
SORT-FIELDNAME = 'NETWR'.
SORT-TABNAME = 'ITAB'.
SORT-UP = 'X'.

APPEND SORT.
CLEAR SORT.

LOOP AT ITAB.
IF ITAB-NETWR < 3000.
ITAB-COLOR = 'C615'.
MODIFY ITAB INDEX SY-TABIX.
ELSEIF ITAB-NETWR > 3000 AND ITAB-NETWR < 8000.
ITAB-COLOR = 'C501'.
MODIFY ITAB INDEX SY-TABIX.
ELSE.
ITAB-COLOR = 'C710'.
MODIFY ITAB INDEX SY-TABIX.
ENDIF.
ENDLOOP.

LAYOUT-INFO_FIELDNAME = 'COLOR'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                = 'SY-CPROG'
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
   IS_LAYOUT                         = LAYOUT
   IT_FIELDCAT                       = FCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
   IT_SORT                           = SORT[]
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  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.

*-- End of Program

Notes:

Cxyz  similar to C501.

Here x stands for color numbers.
y stands for intensified.  Values can be 1 or 0 for on or off
z stands for inverse off or on. 1 is on and 0 is off

color numbers are-- i.e the values you can have for "X"--

x       color                   intended for 
--       -------------            ------------------
1-      gray blue            headers
2-      light gray            list bodies
3-      yellow                totals
4-      blue-green          key columns
5-      green                  positive threshold value
6-      red                      negative threshold value
7-      orange                control levels

So, now when you say 'c501',  it means the color will be green, its not intensified and the inverse is on. 

ABAP Tips

See Also
Abap ALV Tree - A Complete Example Code

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.