Skip to Content
avatar image
Former Member

How to set colour to a field in ALV grid

Hi,

I have a requirement of setting the colour to specific fields in ALV grid.

How to set colour to specific field (not to the entire column) in alv grid.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Sep 01, 2008 at 08:33 AM

    hi,

    By 'not to the entire column'--do you mean coloring specific cells?

    for theory check,

    http://help.sap.com/saphelp_nw2004s/helpdata/en/b6/b7bc68306049bd8500362ce52b6def/content.htm

    for sample code,

    http://www.sap-basis-abap.com/abap/color-a-column-value-in-alv-report.htm

    Regards,

    Anirban

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 08:36 AM

    Hi Charan,

    Please search the forum, you can find many posts related to this topic.

    Here are some of it.

    How to display color for each row in a ALV list

    color a row in an alv grid by special value

    How to color a row of alv grid

    Best regards,

    raam

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 08:36 AM

    Hi Charan,

    Check this one:

    [Coloring Specific Fields|]

    Regards,

    Chandra Sekhar

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 01, 2008 at 08:40 AM

    check this

    https://wiki.sdn.sap.com/wiki/display/Snippets/ColoringacellinanALVconditionally

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 08:46 AM

    Hi,

    tables: vbak.

    type-pools: slis.

    selection-screen: begin of block b1.

    select-options: cust for vbak-kunnr.

    selection-screen: end of block b1.

    types: begin of ty_vbak,

    vbeln type vbeln_va,

    erdat type erdat,

    ernam type ernam,

    netwr type netwr_ak,

    end of ty_vbak.

    types: begin of ty_vbak1,

    vbeln type vbeln_va,

    erdat type erdat,

    ernam type ernam,

    netwr type netwr_ak,

    tabcolor TYPE lvc_t_scol,

    end of ty_vbak1.

    data: i_vbak type table of ty_vbak,

    w_vbak type ty_vbak,

    i_fieldcat type LVC_T_FCAT, "slis_t_fieldcat_alv,

    i_vbak1 type table of ty_vbak1,

    w_vbak1 type ty_vbak1.

    DATA: ls_layout TYPE LVC_S_LAYO.

    select vbeln erdat ernam netwr from vbak into table i_vbak where kunnr in cust.

    perform fieldcat.

    perform display.

    &----


    *& Form fieldcat

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM fieldcat .

    data: w_fieldcat type LINE OF LVC_T_FCAT.

    clear w_fieldcat.

    w_fieldcat-fieldname = 'VBELN'.

    w_fieldcat-tabname = 'I_VBAK'.

    w_fieldcat-seltext = 'DOCUMENT NUMBER'.

    append w_fieldcat to i_fieldcat.

    clear w_fieldcat.

    w_fieldcat-fieldname = 'ERDAT'.

    w_fieldcat-tabname = 'I_VBAK'.

    w_fieldcat-seltext = 'CREATED ON'.

    append w_fieldcat to i_fieldcat.

    clear w_fieldcat.

    w_fieldcat-fieldname = 'ERNAM'.

    w_fieldcat-tabname = 'I_VBAK'.

    w_fieldcat-seltext = 'CREATED BY'.

    append w_fieldcat to i_fieldcat.

    clear w_fieldcat.

    w_fieldcat-fieldname = 'NETWR'.

    w_fieldcat-tabname = 'I_VBAK'.

    w_fieldcat-seltext = 'NET PRICE'.

    append w_fieldcat to i_fieldcat.

    ENDFORM. " fieldcat

    &----


    *& Form display

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM display .

    data: ls_tabcolor TYPE lvc_s_scol.

    loop at i_vbak into w_vbak.

    if sy-tabix <> 3.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'VBELN'.

    ls_tabcolor-color-col = 1. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'ERDAT'.

    ls_tabcolor-color-col = 2. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'ERNAM'.

    ls_tabcolor-color-col = 3. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'NETWR'.

    ls_tabcolor-color-col = 4. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    move-corresponding w_vbak to w_vbak1.

    append w_vbak1 to i_vbak1.

    else.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'VBELN'.

    ls_tabcolor-color-col = 1. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'ERDAT'.

    ls_tabcolor-color-col = 2. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'ERNAM'.

    ls_tabcolor-color-col = 3. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    CLEAR ls_tabcolor.

    ls_tabcolor-fname = 'NETWR'.

    ls_tabcolor-color-col = 6. " Blue.

    ls_tabcolor-color-int = 0.

    ls_tabcolor-color-inv = 0.

    INSERT ls_tabcolor INTO TABLE W_vbak1-tabcolor.

    move-corresponding w_vbak to w_vbak1.

    append w_vbak1 to i_vbak1.

    endif.

    clear w_vbak.

    clear w_vbak1.

    endloop.

    ls_layout-cTab_fname = 'TABCOLOR'.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

    EXPORTING

    • I_INTERFACE_CHECK = ' '

    • I_BYPASSING_BUFFER =

    • I_BUFFER_ACTIVE =

    I_CALLBACK_PROGRAM = SY-REPID

    • 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_LVC = ls_layout

    IT_FIELDCAT_LVC = I_FIELDCAT

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS_LVC =

    • IT_SORT_LVC =

    • IT_FILTER_LVC =

    • IT_HYPERLINK =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    I_SAVE = 'X'

    • IS_VARIANT =

    • IT_EVENTS =

    • IT_EVENT_EXIT =

    • IS_PRINT_LVC =

    • IS_REPREP_ID_LVC =

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • I_HTML_HEIGHT_TOP =

    • I_HTML_HEIGHT_END =

    • IT_EXCEPT_QINFO_LVC =

    • IR_SALV_FULLSCREEN_ADAPTER =

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

    • ES_EXIT_CAUSED_BY_USER =

    TABLES

    T_OUTTAB = I_VBAK1

    • 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. " display

    I think it will be useful for you.

    Thanks & regards

    Deepika

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 01, 2008 at 08:50 AM

    Hi

    Go through the link given below :

    Highlighting a field in red color in ALV

    With Regards

    Nikunj Shah

    Add comment
    10|10000 characters needed characters exceeded