Skip to Content
avatar image
Former Member

How to use colours for columns

can anyone tell me ,how to use colours for columns?

plzzzz help me.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Sep 01, 2008 at 03:46 PM

    Hi Nikhil,

    Use the LVC fieldcatalog in the ALV reports.There you can assign the colors to the columns.

    The below code is for your reference,

    *
    REPORT  zmk_alv_lvc.
    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 = 1.       " Intensified on
          ls_tabcolor-color-inv = 1.       " Inverse on
          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.       " Intensified off
          ls_tabcolor-color-inv = 0.       " Inverse off
          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

    Hope this helps you..

    Thanks,

    Khan.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:17 AM

    Hi,

    Check the following code:

    TABLES: ekko.

    type-pools: slis. "ALV Declarations

    *Data Declaration

    TYPES: BEGIN OF t_ekko,

    ebeln TYPE ekpo-ebeln,

    ebelp TYPE ekpo-ebelp,

    statu TYPE ekpo-statu,

    aedat TYPE ekpo-aedat,

    matnr TYPE ekpo-matnr,

    menge TYPE ekpo-menge,

    meins TYPE ekpo-meins,

    netpr TYPE ekpo-netpr,

    peinh TYPE ekpo-peinh,

    line_color(4) type c, "Used to store row color attributes

    END OF t_ekko.

    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

    wa_ekko TYPE t_ekko.

    *ALV data declarations

    data: fieldcatalog type slis_t_fieldcat_alv with header line,

    gd_tab_group type slis_t_sp_group_alv,

    gd_layout type slis_layout_alv,

    gd_repid like sy-repid.

    *Start-of-selection.

    START-OF-SELECTION.

    perform data_retrieval.

    perform build_fieldcatalog.

    perform build_layout.

    perform display_alv_report.

    &----


    *& Form BUILD_FIELDCATALOG

    &----


    • Build Fieldcatalog for ALV Report

    ----


    form build_fieldcatalog.

    fieldcatalog-fieldname = 'EBELN'.

    fieldcatalog-seltext_m = 'Purchase Order'.

    fieldcatalog-col_pos = 0.

    fieldcatalog-outputlen = 10.

    fieldcatalog-emphasize = 'X'.

    fieldcatalog-key = 'X'.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'EBELP'.

    fieldcatalog-seltext_m = 'PO Item'.

    fieldcatalog-col_pos = 1.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'STATU'.

    fieldcatalog-seltext_m = 'Status'.

    fieldcatalog-col_pos = 2.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'AEDAT'.

    fieldcatalog-seltext_m = 'Item change date'.

    fieldcatalog-col_pos = 3.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'MATNR'.

    fieldcatalog-seltext_m = 'Material Number'.

    fieldcatalog-col_pos = 4.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'MENGE'.

    fieldcatalog-seltext_m = 'PO quantity'.

    fieldcatalog-col_pos = 5.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'MEINS'.

    fieldcatalog-seltext_m = 'Order Unit'.

    fieldcatalog-col_pos = 6.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'NETPR'.

    fieldcatalog-seltext_m = 'Net Price'.

    fieldcatalog-col_pos = 7.

    fieldcatalog-outputlen = 15.

    fieldcatalog-datatype = 'CURR'.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    fieldcatalog-fieldname = 'PEINH'.

    fieldcatalog-seltext_m = 'Price Unit'.

    fieldcatalog-col_pos = 8.

    append fieldcatalog to fieldcatalog.

    clear fieldcatalog.

    endform. " BUILD_FIELDCATALOG

    &----


    *& Form BUILD_LAYOUT

    &----


    • Build layout for ALV grid report

    ----


    form build_layout.

    gd_layout-no_input = 'X'.

    gd_layout-colwidth_optimize = 'X'.

    gd_layout-totals_text = 'Totals'(201).

    gd_layout-info_fieldname = 'LINE_COLOR'.

    endform. " BUILD_LAYOUT

    &----


    *& Form DISPLAY_ALV_REPORT

    &----


    • Display report using ALV grid

    ----


    form display_alv_report.

    gd_repid = sy-repid.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    i_callback_program = gd_repid

    is_layout = gd_layout

    it_fieldcat = fieldcatalog[]

    i_save = 'X'

    tables

    t_outtab = it_ekko .

    endform. " DISPLAY_ALV_REPORT

    &----


    *& Form DATA_RETRIEVAL

    &----


    • Retrieve data form EKPO table and populate itab it_ekko

    ----


    form data_retrieval.

    data: ld_color(1) type c.

    select ebeln ebelp statu aedat matnr menge meins netpr peinh

    up to 10 rows

    from ekpo

    into table it_ekko.

    *Populate field with color attributes

    loop at it_ekko into wa_ekko.

    ld_color = ld_color + 1.

    • Only 7 colours so need to reset color value

    if ld_color = 8.

    ld_color = 1.

    endif.

    concatenate 'C' ld_color '10' into wa_ekko-line_color.

    modify it_ekko from wa_ekko.

    endloop.

    endform. " DATA_RETRIEVAL

    Regards,

    Bhaskar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:26 AM
  • avatar image
    Former Member
    Sep 02, 2008 at 04:28 AM

    HI Nikhil,

    Check this simple code snippet from SDN:

    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/coloring%2ba%2brow%2band%2bcolumn%2bin%2balv%2b(OOPS)

    Regards,

    Chandra Sekhar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:52 AM

    Hi,

    1. Declare a variable in ur internal table.say color(4)

    2. Write the if condition.

    for eg-

    if <condition>

    itab-color = C001.

    endif.

    Hope this will help u.

    Regards,

    Aleem.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 12:53 PM

    how to color a column value in ALV Report.

    REPORT z_colour NO STANDARD PAGE HEADING .

    TABLES :pa0002.

    TYPE-POOLS: slis. "ALV Declarations

    DATA : BEGIN OF it OCCURS 0,

    pernr LIKE pa0001-pernr,

    rufnm LIKE pa0002-rufnm,

    cell_colour TYPE lvc_t_scol, "Cell colour

    END OF it.

    SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME.

    SELECT-OPTIONS :s_pnum FOR pa0002-pernr .

    SELECTION-SCREEN END OF BLOCK main.

    *ALV data declarations

    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH

    HEADER LINE,

    gd_layout TYPE slis_layout_alv,

    gd_repid LIKE sy-repid,

    gt_sort TYPE slis_t_sortinfo_alv.

    • To colour a cell.

    DATA ls_cellcolour TYPE lvc_s_scol.

    START-OF-SELECTION.

    PERFORM data_retrieval.

    PERFORM build_fieldcatalog.

    PERFORM build_layout.

    PERFORM display_alv_report.

    END-OF-SELECTION.

    FREE : it.

    FORM build_fieldcatalog .

    fieldcatalog-fieldname = 'PERNR'.

    fieldcatalog-seltext_m = 'Personnel No.'.

    fieldcatalog-col_pos = 0.

    APPEND fieldcatalog TO fieldcatalog.

    CLEAR fieldcatalog.

    fieldcatalog-fieldname = 'RUFNM'.

    fieldcatalog-seltext_m = 'Name'.

    fieldcatalog-col_pos = 0.

    APPEND fieldcatalog TO fieldcatalog.

    CLEAR fieldcatalog.

    ENDFORM.

    FORM build_layout .

    gd_layout-no_input = 'X'.

    gd_layout-colwidth_optimize = 'X'.

    gd_layout-totals_text = 'Totals'(256).

    gd_layout-coltab_fieldname = 'CELL_COLOUR'.

    ENDFORM. " build_layout

    FORM display_alv_report .

    gd_repid = sy-repid.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = gd_repid

    is_layout = gd_layout

    it_fieldcat = fieldcatalog[]

    i_save = 'A'

    TABLES

    t_outtab = it

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    ENDIF.

    ENDFORM. " display_alv_report

    FORM data_retrieval .

    select pernr rufnm from pa0002 into corresponding

    fields of table it where pernr in s_pnum.

    LOOP AT it.

    *Now based on the value of the field pernr we can

    change the cell colour of the field rufnm or pernr.

    IF it-pernr eq '10001' .

    ls_cellcolour-fname = 'RUFNM'.

    ls_cellcolour-color-col = '5'.

    ls_cellcolour-color-int = '1'.

    ls_cellcolour-color-inv = '0'.

    APPEND ls_cellcolour TO it-cell_colour.

    IF sy-subrc EQ 0.

    MODIFY it.

    ENDIF.

    ENDIF.

    ENDLOOP.

    ENDFORM.

    regards

    manju

    Add comment
    10|10000 characters needed characters exceeded