Skip to Content
author's profile photo Former Member
Former Member

Cell Colors in ALV report

Hi all

I want to assign color to a specific cell, I know that is in the LAYOUT-Coltab_fieldname but i don't know how can i use it.

Can anyone help me please!!

Thanks & Regards

David N

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2006 at 04:14 PM

    Hi,

    Do as follows

    1. declare one field say color in the output table of type SLIS_T_SPECIALCOL_ALV.

    2. Also declare a table color like

    DATA COLOR TYPE SLIS_T_SPECIALCOL_ALV WITH HEADER LINE.

    3. After you have filled the field catalog do like this,

    LOOP AT IT_ALV_DATA.

    IF SY-TABIX = 2.

    COLOR-FIELDNAME = 'POSNR'.

    COLOR-COLOR-COL = 6.

    COLOR-COLOR-INT = 0.

    APPEND COLOR.

    IT_ALV_DATA-COLOR = COLOR[].

    MODIFY IT_ALV_DATA.

    ENDIF.

    ENDLOOP.

    Hope this helps.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      use this routine to set the cell color:

      <pre>

      &----


      *& Form alv_color

      &----


      • set field color

      ----


      FORM alv_color USING pv_fieldname TYPE fieldname

      pv_color TYPE i

      pv_intensify TYPE i

      pv_inverse TYPE i

      CHANGING pt_colors TYPE slis_t_specialcol_alv.

      DATA:

      ls_colors TYPE LINE OF slis_t_specialcol_alv.

      ls_colors-fieldname = pv_fieldname.

      ls_colors-color-col = pv_color.

      ls_colors-color-int = pv_intensify.

      ls_colors-color-inv = pv_inverse.

      APPEND ls_colors TO pt_colors.

      ENDFORM. " alv_color

      [pre/]

      Sample call like

      <pre>

      PERFORM alv_color

      USING '' col_negative 0 0 "whole row red

      CHANGING ls_alv_display-color.

      PERFORM alv_color

      USING 'DMBTR' col_positive 0 0 "field DMBTR green

      CHANGING ls_alv_display-color.

      [pre/]

      Regards,

      Clemens

  • author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2006 at 04:11 PM

    Assign a variable celltab TYPE lvc_t_styl, in the internal table which u dispaly the data.

    In the layout give, wa_layout-stylefname = 'CELLTAB'.

    In the final table before showing the data do like the below code.

    DATA : lt_celltab TYPE lvc_t_styl,

    ls_celltab TYPE lvc_s_styl.

    READ TABLE i_final_data INTO wa_final_data INDEX 1.

    ls_celltab-fieldname = 'LNG_TYPES'.

    ls_celltab-style = '00000060'.

    INSERT ls_celltab INTO TABLE lt_celltab.

    CLEAR ls_celltab.

    ls_celltab-fieldname = 'LNG_QUANTITY'.

    ls_celltab-style = '00003060'.

    INSERT ls_celltab INTO TABLE lt_celltab.

    CLEAR ls_celltab.

    ls_celltab-fieldname = 'NG_TYPES'.

    ls_celltab-style = '00000666'.

    INSERT ls_celltab INTO TABLE lt_celltab.

    CLEAR ls_celltab.

    ls_celltab-fieldname = 'NG_QUANTITY'.

    ls_celltab-style = '00000066'.

    INSERT ls_celltab INTO TABLE lt_celltab.

    CLEAR ls_celltab.

    wa_final_data-celltab[] = lt_celltab[].

    MODIFY i_final_data FROM wa_final_data INDEX 1.

    CLEAR: ls_celltab, lt_celltab, wa_final_data.

    Here <b>ls_celltab-style = '00000066' or '00000060'</b> gives the color for a particular cell.

    Read the row which u want to make cell colored. For that row, append the field name and style into ls_celltab.

    ls_celltab-fieldname = 'LNG_TYPES'.

    ls_celltab-style = '00003040'.

    INSERT ls_celltab INTO TABLE lt_celltab.

    wa_final_data-celltab[] = lt_celltab[].

    So that the particular cell will become colored.

    Regards,

    Prakash.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2006 at 04:20 PM

    hi,

    you can set the color using Emphasize also.

          WHEN 'NETWR'.
            WA_FIELDCAT-SELTEXT_L = 'Net Price'.
            WA_FIELDCAT-SELTEXT_M = 'Net Price'.
            WA_FIELDCAT-SELTEXT_S = 'Net Price'.
            WA_FIELDCAT-DDICTXT = 'M'.
            WA_FIELDCAT-OUTPUTLEN = 30.
            WA_FIELDCAT-COL_POS = 6.
    **--To set the default column highlight color
    **--Value Set : ' ', 'X', 'Cxyz' x = 1-9, y = bold z = inverse
    **--Value set for y/z: 0 = Off 1 = On
            WA_FIELDCAT-EMPHASIZE = 'C611'.

    We can give different numbers to x from 1 to 9.

    In the above code, NETWR will be displayed in red.

    REgards,

    Sailaja.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2006 at 05:04 PM

    Hi,

    Go thru this link

    http://www.sapdevelopment.co.uk/reporting/alvhome.htm

    Thanks

    Sunil

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2006 at 06:17 PM

    Hi David,

    see the full sample code

    REPORT ZALV_CELL_COLOR.

    TYPE-POOLS: SLIS.

    *--Fieldcatalog

    DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

    X_FIELDCAT TYPE LVC_S_FCAT.

    *--For Events

    DATA: IT_EVENTS TYPE SLIS_T_EVENT.

    *--Layout

    DATA: X_LAYOUT TYPE LVC_S_LAYO.

    *--for Cell Color

    DATA: LS_CELLCOLOR TYPE LVC_S_SCOL.

    DATA: L_INDEX TYPE SY-TABIX.

    DATA: L_POS TYPE I VALUE 1.

    DATA: BEGIN OF IT_VBAP OCCURS 0,

    VBELN LIKE VBAP-VBELN,

    POSNR LIKE VBAP-POSNR,

    CELLCOLOR TYPE LVC_T_SCOL,

    END OF IT_VBAP.

    START-OF-SELECTION.

    PERFORM GET_DATA.

    PERFORM GENERATE_FLDCAT.

    PERFORM SET_CELL_COLORS.

    END-OF-SELECTION.

    PERFORM GENERATE_ALV_GRID.

    &----


    *& Form GET_DATA

    &----


    • text

    ----


    FORM GET_DATA.

    SELECT VBELN

    POSNR

    UP TO 10 ROWS

    INTO (IT_VBAP-VBELN,

    IT_VBAP-POSNR)

    FROM VBAP.

    APPEND IT_VBAP.

    ENDSELECT.

    ENDFORM. " GET_DATA

    &----


    *& Form GENERATE_FLDCAT

    &----


    • text

    ----


    FORM GENERATE_FLDCAT.

    CLEAR: L_POS.

    L_POS = L_POS + 1.

    X_FIELDCAT-SELTEXT = 'VBELN'.

    X_FIELDCAT-FIELDNAME = 'VBELN'.

    X_FIELDCAT-TABNAME = 'ITAB'.

    X_FIELDCAT-COL_POS = L_POS.

    X_FIELDCAT-OUTPUTLEN = '10'.

    APPEND X_FIELDCAT TO IT_FIELDCAT.

    CLEAR X_FIELDCAT.

    L_POS = L_POS + 1.

    X_FIELDCAT-SELTEXT = 'POSNR'.

    X_FIELDCAT-FIELDNAME = 'POSNR'.

    X_FIELDCAT-TABNAME = 'ITAB'.

    X_FIELDCAT-COL_POS = L_POS.

    X_FIELDCAT-OUTPUTLEN = '5'.

    APPEND X_FIELDCAT TO IT_FIELDCAT.

    CLEAR X_FIELDCAT.

    L_POS = L_POS + 1.

    X_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

    ENDFORM. " GENERATE_FLDCAT

    &----


    *& Form SET_CELL_COLORS

    &----


    • text

    ----


    FORM SET_CELL_COLORS.

    LOOP AT IT_VBAP.

    L_INDEX = SY-TABIX.

    LS_CELLCOLOR-FNAME = 'VBELN'.

    LS_CELLCOLOR-COLOR-COL = '6'.

    LS_CELLCOLOR-COLOR-INT = '1'.

    LS_CELLCOLOR-COLOR-INV = '1'.

    APPEND LS_CELLCOLOR TO IT_VBAP-CELLCOLOR.

    MODIFY IT_VBAP INDEX L_INDEX TRANSPORTING CELLCOLOR.

    ENDLOOP.

    ENDFORM. " SET_CELL_COLORS

    &----


    *& Form GENERATE_ALV_GRID

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM GENERATE_ALV_GRID.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

    EXPORTING

    I_CALLBACK_PROGRAM = 'ZTESTALV'

    IS_LAYOUT_LVC = X_LAYOUT

    IT_FIELDCAT_LVC = IT_FIELDCAT

    TABLES

    T_OUTTAB = IT_VBAP[]

    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. " GENERATE_ALV_GRID

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2006 at 09:53 PM

    Thanks a lot everyone!!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.