ALV Color a CELL?

HI all,
i need to place a color for a cell.
color is ORANGE.
i am passing the code 7 to that field.
but ia m getting PURPUL Color....
I ned to make it ORANGE..
          ls_cellcolor-color-col = '7'.
          ls_cellcolor-color-int = '0'.
          ls_cellcolor-color-inv = '0'.
PLaese help...
sachin.

hi  Samarendra
try like this
here is code
TYPE-POOLS:slis.
TABLES:mara,
       makt,
       marc.
DATA:BEGIN OF itab OCCURS 0,
      matnr LIKE mara-matnr,
      maktx LIKE makt-maktx,
      werks LIKE marc-werks,
      mtart LIKE mara-mtart,
      matkl LIKE mara-matkl,
      meins LIKE mara-meins,
      ntgew LIKE mara-ntgew,
     rowcolor(4) TYPE c,
      cellcolors TYPE lvc_t_scol,
     END OF itab.
DATA:t_fcat TYPE slis_t_fieldcat_alv,
     t_eve TYPE slis_t_event.
DATA : st_layout TYPE slis_layout_alv.
SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:mat FOR mara-matnr.  " no intervals no-extension.
*PARAMETERS:mat LIKE mara-matnr.
SELECTION-SCREEN:END OF BLOCK blk1.
INITIALIZATION.
  PERFORM build_cata USING t_fcat.
  PERFORM build_event.
START-OF-SELECTION.
  PERFORM data_retrieval.
  PERFORM display_data.
*&      Form  build_cata
      text
     -->TEMP_FCAT  text
FORM build_cata USING temp_fcat TYPE slis_t_fieldcat_alv.
  sy-tvar0 = sy-uname.
  WRITE sy-datum TO sy-tvar1.
  DATA:wa_fcat TYPE slis_fieldcat_alv.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MATNR'.
   wa_fcat-ref_tabname = 'MARA'.
wa_fcat-ref_fieldname = 'MATNR'.
  wa_fcat-col_pos = 1.
  wa_fcat-seltext_m = 'Material'.
wa_fcat-emphasize = 'C10'.                             "To change ALV Background Color
  APPEND wa_fcat TO temp_fcat.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MAKTX'.
  wa_fcat-seltext_m = 'Description'.
  wa_fcat-fix_column = 'x'.
  wa_fcat-key = 'X'.                                     "To color a column
  APPEND wa_fcat TO temp_fcat.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-seltext_m = 'Plant'.
  wa_fcat-key = ' '.
  APPEND wa_fcat TO temp_fcat.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MTART'.
  wa_fcat-ddic_outputlen = 4.
  wa_fcat-row_pos = 2.
wa_fcat-ref_tabname = 'MARA'.
wa_fcat-ref_fieldname = 'MTART'.
wa_fcat-seltext_m = 'Type'.
  APPEND wa_fcat TO temp_fcat.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MATKL'.
  wa_fcat-ref_tabname = 'MARA'.
  wa_fcat-row_pos = 2.
wa_fcat-ref_fieldname = 'MATKL'.
  wa_fcat-seltext_m = 'Group'.
  APPEND wa_fcat TO temp_fcat.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-ref_tabname = ' '.
  wa_fcat-ref_fieldname = ' '.
  wa_fcat-row_pos = 2.
  wa_fcat-seltext_m = 'Measurement Unit'.
  APPEND wa_fcat TO temp_fcat.
  wa_fcat-tabname = 'ITAB'.
  wa_fcat-fieldname = 'NTGEW'.
  wa_fcat-seltext_m = 'Net Value'.
  wa_fcat-row_pos = 2.
  wa_fcat-no_out = ' '.
  APPEND wa_fcat TO temp_fcat.
ENDFORM.                    "build_cata
*&      Form  build_event
      text
FORM build_event.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = t_eve
    EXCEPTIONS
      list_type_wrong = 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.                    "build_event
*&      Form  data_retrieval
      text
FORM data_retrieval.
  SELECT maramatnr  maramtart maramatkl marameins mara~ntgew
   maktmaktx  marcwerks
  INTO CORRESPONDING FIELDS OF TABLE itab
  FROM mara INNER JOIN makt ON
  maramatnr = maktmatnr
  INNER JOIN marc ON
  maramatnr = marcmatnr
  WHERE mara~matnr IN mat.
  SORT itab BY matnr.
  DELETE ADJACENT DUPLICATES FROM itab.
ENDFORM.                    "data_retrieval
*&      Form  display_data
      text
FORM display_data.
*******************************For setting Cell Color*******************************************
  DATA ls_cellcolor TYPE lvc_s_scol .
  st_layout-coltab_fieldname = 'CELLCOLORS'.
  LOOP AT itab WHERE meins EQ 'KG'.
READ TABLE itab INDEX 5 .
    ls_cellcolor-fname = 'MEINS' .
    ls_cellcolor-color-col = '7' .
    ls_cellcolor-color-int = '1' .
    APPEND ls_cellcolor TO itab-cellcolors .
    MODIFY itab TRANSPORTING cellcolors .
  ENDLOOP.
st_layout-colwidth_optimize = 'X'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = 'ZALV_DS'
      is_layout                = st_layout
      i_save                   = 'X'
      it_fieldcat              = t_fcat
      it_events                = t_eve
    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.
ENDFORM.                    "display_data

Similar Messages

  • ALV : color one cell

    Hi all,
    i want to color just only one cell in my ALV report, but i don't know how can i do that.
    Here my code :
    REPORT  ztest_alv_color_cell.
    Used to limit user commands on selection-screen
    INCLUDE rsdbc1xx.
    DATA: BEGIN OF i_alv OCCURS 0,
          connid   TYPE sflight-connid,
          currency TYPE sflight-currency,
          FLDATE   TYPE sflight-fldate,
          END OF i_alv.
    DATA: alv_grid       TYPE REF TO cl_gui_alv_grid.
    DATA: fieldcat  TYPE lvc_t_fcat.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .
    SELECT-OPTIONS: s_matnr FOR i_alv-connid.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF SCREEN 1010.
    SELECTION-SCREEN END OF SCREEN 1010.
    Events
    AT SELECTION-SCREEN OUTPUT.
      IF sy-dynnr = '1010'.
        current_scr-mode = 'S'.
        APPEND 'SPOS' TO current_scr-excl.
        APPEND 'SCRH' TO current_scr-excl.
        APPEND 'ONLI' TO current_scr-excl.
      ENDIF.
    START-OF-SELECTION.
      PERFORM get_data.
      CREATE OBJECT alv_grid
             EXPORTING
                   i_parent           =  cl_gui_container=>screen0.
    Populate Field Catalog
      PERFORM get_fieldcatalog.
      CALL METHOD alv_grid->set_table_for_first_display
        CHANGING
          it_outtab       = i_alv[]
          it_fieldcatalog = fieldcat[].
      CALL SELECTION-SCREEN 1010.
    FORM GET_DATA
    FORM get_data.
      SELECT * INTO CORRESPONDING FIELDS OF TABLE i_alv
            FROM sflight.
      SORT i_alv ASCENDING BY connid.
    ENDFORM.                    "get_data
         Form  Get_Fieldcatalog - Set Up Columns/Headers
    FORM get_fieldcatalog.
      DATA: ls_fcat TYPE lvc_s_fcat.
      REFRESH: fieldcat.
      CLEAR: ls_fcat.
      ls_fcat-reptext    = 'Connid'.
      ls_fcat-coltext    = 'Connid'.
      ls_fcat-fieldname  = 'CONNID'.
      ls_fcat-ref_table  = 'I_ALV'.
      ls_fcat-outputlen  = '10'.
      ls_fcat-col_pos    = 1.
      APPEND ls_fcat TO fieldcat.
      CLEAR: ls_fcat.
      ls_fcat-reptext    = 'Currency'.
      ls_fcat-coltext    = 'Currency'.
      ls_fcat-fieldname  = 'CURRENCY'.
      ls_fcat-ref_table  = 'I_ALV'.
      ls_fcat-outputlen  = '10'.
      ls_fcat-col_pos    = 2.
      APPEND ls_fcat TO fieldcat.
      CLEAR: ls_fcat.
      ls_fcat-reptext    = 'Flight date'.
      ls_fcat-coltext    = 'Flight date'.
      ls_fcat-fieldname  = 'FLDATE'.
      ls_fcat-ref_table  = 'I_ALV'.
      ls_fcat-datatype   = 'DATS'.
      ls_fcat-outputlen  = '10'.
      ls_fcat-col_pos    = 3.
      APPEND ls_fcat TO fieldcat.
    ENDFORM.                    "get_fieldcatalog
    Imagine that i want to color in red line 1 column 1, please tell how can i do this.
    Thanks very much for help.
    Cheers

    Hi,
    Check this code..
    REPORT  ZTEST1234    MESSAGE-ID ZZ                           .
    DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: L_VALID TYPE C,
          V_FLAG,
          V_DATA_CHANGE,
          V_ROW TYPE LVC_S_ROW,
          V_COLUMN TYPE LVC_S_COL,
          V_ROW_NUM TYPE LVC_S_ROID.
    *       CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION .
      PUBLIC SECTION .
        METHODS:
    **Hot spot Handler
        HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                          IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
    **Double Click Handler
        HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                         IMPORTING E_ROW E_COLUMN ES_ROW_NO.
    ENDCLASS.                    "lcl_event_handler DEFINITION
    *       CLASS lcl_event_handler IMPLEMENTATION
    CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
    *Handle Hotspot Click
      METHOD HANDLE_HOTSPOT_CLICK .
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW_ID.
        V_COLUMN = E_COLUMN_ID.
        V_ROW_NUM = ES_ROW_NO.
        MESSAGE I000 WITH V_ROW 'clicked'.
      ENDMETHOD.                    "lcl_event_handler
    *Handle Double Click
      METHOD  HANDLE_DOUBLE_CLICK.
      ENDMETHOD.                    "handle_double_click
    ENDCLASS.                    "LCL_EVENT_HANDLER IMPLEMENTATION
    *&             Global Definitions
    DATA:      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1
                G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler
    DATA: OK_CODE LIKE SY-UCOMM,
          SAVE_OK LIKE SY-UCOMM,
          G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
          GS_LAYOUT TYPE LVC_S_LAYO.
    *- Fieldcatalog for First and second Report
    DATA: IT_FIELDCAT  TYPE  LVC_T_FCAT,
          X_FIELDCAT TYPE LVC_S_FCAT,
          LS_VARI  TYPE DISVARIANT.
    *                START-OF_SELECTION
    START-OF-SELECTION.
      DATA:BEGIN OF  ITAB OCCURS 0,
           VBELN LIKE LIKP-VBELN,
           POSNR LIKE LIPS-POSNR,
           CELLCOLOR TYPE LVC_T_SCOL, "required for color
           DROP(10),
           END OF ITAB.
      SELECT VBELN
             POSNR
             FROM LIPS
             UP TO 20 ROWS
             INTO CORRESPONDING FIELDS OF TABLE ITAB.
    END-OF-SELECTION.
      IF NOT ITAB[] IS INITIAL.
        CALL SCREEN 100.
      ELSE.
        MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
      ENDIF.
    *&      Form  CREATE_AND_INIT_ALV
    *       text
    FORM CREATE_AND_INIT_ALV .
      DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
      CREATE OBJECT G_CUSTOM_CONTAINER
             EXPORTING CONTAINER_NAME = G_CONTAINER1.
      CREATE OBJECT G_GRID
             EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
    * Set a titlebar for the grid control
      CLEAR GS_LAYOUT.
      GS_LAYOUT-GRID_TITLE = TEXT-003.
      GS_LAYOUT-ZEBRA = SPACE.
      GS_LAYOUT-CWIDTH_OPT = 'X'.
      GS_LAYOUT-NO_ROWMARK = 'X'.
      GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
      CALL METHOD G_GRID->REGISTER_EDIT_EVENT
        EXPORTING
          I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
      CREATE OBJECT G_HANDLER.
      SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
      SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
      DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color
      DATA: L_INDEX TYPE SY-TABIX.
      "Here i am changing the color of line 1,5,10...
      "so you can change the color of font conditionally
      LOOP AT ITAB.
        L_INDEX = SY-TABIX.
        IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.
          LS_CELLCOLOR-FNAME = 'VBELN'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
          LS_CELLCOLOR-FNAME = 'POSNR'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
        ENDIF.
      ENDLOOP.
    * setting focus for created grid control
      CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
        EXPORTING
          CONTROL = G_GRID.
    * Build fieldcat and set editable for date and reason code
    * edit enabled. Assign a handle for the dropdown listbox.
      PERFORM BUILD_FIELDCAT.
      PERFORM  SET_DRDN_TABLE.
    * Optionally restrict generic functions to 'change only'.
    *   (The user shall not be able to add new lines).
      PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
    **Vaiant to save the layout
      LS_VARI-REPORT      = SY-REPID.
      LS_VARI-HANDLE      = SPACE.
      LS_VARI-LOG_GROUP   = SPACE.
      LS_VARI-USERNAME    = SPACE.
      LS_VARI-VARIANT     = SPACE.
      LS_VARI-TEXT        = SPACE.
      LS_VARI-DEPENDVARS  = SPACE.
    **Calling the Method for ALV output
      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
          IS_VARIANT           = LS_VARI
          IS_LAYOUT            = GS_LAYOUT
          I_SAVE               = 'A'
        CHANGING
          IT_FIELDCATALOG      = IT_FIELDCAT
          IT_OUTTAB            = ITAB[].
    * Set editable cells to ready for input initially
      CALL METHOD G_GRID->SET_READY_FOR_INPUT
        EXPORTING
          I_READY_FOR_INPUT = 1.
    ENDFORM.                               "CREATE_AND_INIT_ALV
    *&      Form  EXCLUDE_TB_FUNCTIONS
    *       text
    *      -->PT_EXCLUDE text
    FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
    * Only allow to change data not to create new entries (exclude
    * generic functions).
      DATA LS_EXCLUDE TYPE UI_FUNC.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
    ENDFORM.                               " EXCLUDE_TB_FUNCTIONS
    *&      Form  build_fieldcat
    *       Fieldcatalog
    FORM BUILD_FIELDCAT .
      DATA: L_POS TYPE I.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
      X_FIELDCAT-FIELDNAME = 'VBELN'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-NO_ZERO    = 'X'.
      X_FIELDCAT-OUTPUTLEN = '10'.
      X_FIELDCAT-HOTSPOT = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Item'(025).
      X_FIELDCAT-FIELDNAME = 'POSNR'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      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_FIELDCAT-SCRTEXT_M = 'Drop'(025).
      X_FIELDCAT-FIELDNAME = 'DROP'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      X_FIELDCAT-EDIT = 'X'.
      X_FIELDCAT-DRDN_HNDL = '1'.
      X_FIELDCAT-DRDN_ALIAS = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
    ENDFORM.                    " build_fieldcat
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      IF G_CUSTOM_CONTAINER IS INITIAL.
    **Initializing the grid and calling the fm to Display the O/P
        PERFORM CREATE_AND_INIT_ALV.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  SET_DRDN_TABLE
    *       text
    FORM SET_DRDN_TABLE.
      DATA:LT_DRAL TYPE LVC_T_DRAL,
            LS_DRAL TYPE LVC_S_DRAL.
      LOOP AT ITAB .
    * First listbox (handle '1').
        IF SY-INDEX = 1.
          LS_DRAL-HANDLE = '1'.
          LS_DRAL-VALUE =  ' '.
          LS_DRAL-INT_VALUE =  ' '.
        ELSE.
          LS_DRAL-HANDLE = '1'.
          LS_DRAL-VALUE =  ITAB-POSNR.
          LS_DRAL-INT_VALUE =  ITAB-POSNR.
        ENDIF.
        APPEND LS_DRAL TO LT_DRAL.
      ENDLOOP.
    **Setting the Drop down table for Reason Code
      CALL METHOD G_GRID->SET_DROP_DOWN_TABLE
        EXPORTING
          IT_DROP_DOWN_ALIAS = LT_DRAL.
    ENDFORM.                               " set_drdn_table
    Regards
    vijay

  • ALV - coloring one cell

    Hi,
    i know how to color entire rows or entire columns - but how can i color just one cell?

    Table
    TABLES : mara.
    Type
    TYPES : BEGIN OF ty_mara,
              matnr         LIKE mara-matnr,
              matkl         LIKE mara-matkl,
              counter(4)    TYPE n,
              free_text(15) TYPE c,
              color_line(4) TYPE c,           " Line color
              color_cell    TYPE lvc_t_scol,  " Cell color
    END OF ty_mara.
    Structures
    DATA  : wa_mara     TYPE ty_mara,
            wa_fieldcat TYPE lvc_s_fcat,
            is_layout   TYPE lvc_s_layo,
            wa_color    TYPE lvc_s_scol.
    Internal table
    DATA : it_mara     TYPE STANDARD TABLE OF ty_mara,
           it_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,
           it_color    TYPE TABLE          OF lvc_s_scol.
    Variables
    DATA : okcode LIKE sy-ucomm,
           w_alv_grid          TYPE REF TO cl_gui_alv_grid,
           w_docking_container TYPE REF TO cl_gui_docking_container.
    PARAMETERS : p_column AS CHECKBOX,
                 p_line   AS CHECKBOX,
                 p_cell   AS CHECKBOX.
    START-OF-SELECTION.
      PERFORM get_data.
    END-OF-SELECTION.
      PERFORM fill_catalog.
      PERFORM fill_layout.
      CALL SCREEN 2000.
    *&      Module  status_2000  OUTPUT
    MODULE status_2000 OUTPUT.
      SET PF-STATUS '2000'.
    ENDMODULE.                 " status_2000  OUTPUT
    *&      Module  user_command_2000  INPUT
    MODULE user_command_2000 INPUT.
      DATA : w_okcode LIKE sy-ucomm.
      MOVE okcode TO w_okcode.
      CLEAR okcode.
      CASE w_okcode.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " user_command_2000  INPUT
    *&      Module  alv_grid  OUTPUT
    MODULE alv_grid OUTPUT.
      IF w_docking_container IS INITIAL.
        PERFORM create_objects.
        PERFORM display_alv_grid.
      ENDIF.
    ENDMODULE.                 " alv_grid  OUTPUT
    *&      Form  create_objects
    -->  p1        text
    <--  p2        text
    FORM create_objects.
    Ratio must be included in [5..95]
      CREATE OBJECT w_docking_container
        EXPORTING
          ratio                       = 95
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5
          others                      = 6.
      CREATE OBJECT w_alv_grid
        EXPORTING
          i_parent          = w_docking_container.
    ENDFORM.                    " create_objects
    *&      Form  display_alv_grid
    FORM display_alv_grid.
      CALL METHOD w_alv_grid->set_table_for_first_display
        EXPORTING
          is_layout                     = is_layout
        CHANGING
          it_outtab                     = it_mara
          it_fieldcatalog               = it_fieldcat
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
    ENDFORM.                    " display_alv_grid
    *&      Form  get_data
    FORM get_data.
      SELECT * FROM mara UP TO 5 ROWS.
        CLEAR : wa_mara-color_line, wa_mara-color_cell.
        MOVE-CORRESPONDING mara TO wa_mara.
        ADD 1                   TO wa_mara-counter.
        MOVE 'Blabla'           TO wa_mara-free_text.
        IF wa_mara-counter = '0002'
        AND p_line = 'X'.
    Color line
          MOVE 'C410' TO wa_mara-color_line.
        ELSEIF wa_mara-counter = '0004'
        AND p_cell = 'X'.
    Color cell
          MOVE 'FREE_TEXT' TO wa_color-fname.
          MOVE '5'         TO wa_color-color-col.
          MOVE '1'         TO wa_color-color-int.
          MOVE '1'         TO wa_color-color-inv.
          APPEND wa_color TO it_color.
          wa_mara-color_cell[] = it_color[].
        ENDIF.
        APPEND wa_mara TO it_mara.
      ENDSELECT.
    ENDFORM.                    " get_data
    *&      Form  fill_catalog
    FORM fill_catalog.
    Colour code :                                                 *
    Colour is a 4-char field where :                              *
                 - 1st char = C (color property)                  *
                 - 2nd char = color code (from 0 to 7)            *
                                     0 = background color         *
                                     1 = blue                     *
                                     2 = gray                     *
                                     3 = yellow                   *
                                     4 = blue/gray                *
                                     5 = green                    *
                                     6 = red                      *
                                     7 = orange                   *
                 - 3rd char = intensified (0=off, 1=on)           *
                 - 4th char = inverse display (0=off, 1=on)       *
    Colour overwriting priority :                                 *
      1. Line                                                     *
      2. Cell                                                     *
      3. Column                                                   *
      DATA : w_position TYPE i VALUE '1'.
      CLEAR wa_fieldcat.
      MOVE w_position TO wa_fieldcat-col_pos.
      MOVE 'MATNR'    TO wa_fieldcat-fieldname.
      MOVE 'MARA'     TO wa_fieldcat-ref_table.
      MOVE 'MATNR'    TO wa_fieldcat-ref_field.
      APPEND wa_fieldcat TO it_fieldcat.
      ADD 1 TO w_position.
      CLEAR wa_fieldcat.
      MOVE w_position TO wa_fieldcat-col_pos.
      MOVE 'MATKL'    TO wa_fieldcat-fieldname.
      MOVE 'MARA'     TO wa_fieldcat-ref_table.
      MOVE 'MATKL'    TO wa_fieldcat-ref_field.
    Color column
      IF p_column = 'X'.
        MOVE 'C610'     TO wa_fieldcat-emphasize.
      ENDIF.
      APPEND wa_fieldcat TO it_fieldcat.
      ADD 1 TO w_position.
      CLEAR wa_fieldcat.
      MOVE w_position TO wa_fieldcat-col_pos.
      MOVE 'COUNTER'  TO wa_fieldcat-fieldname.
      MOVE 'N'        TO wa_fieldcat-inttype.
      MOVE '4'        TO wa_fieldcat-intlen.
      MOVE 'Counter'  TO wa_fieldcat-coltext.
      APPEND wa_fieldcat TO it_fieldcat.
      ADD 1 TO w_position.
      CLEAR wa_fieldcat.
      MOVE w_position  TO wa_fieldcat-col_pos.
      MOVE 'FREE_TEXT' TO wa_fieldcat-fieldname.
      MOVE 'C'         TO wa_fieldcat-inttype.
      MOVE '20'        TO wa_fieldcat-intlen.
      MOVE 'Text'      TO wa_fieldcat-coltext.
      APPEND wa_fieldcat TO it_fieldcat.
    ENDFORM.                    " fill_catalog
    *&      Form  fill_layout
    FORM fill_layout.
    Field that identify color line in internal table
      MOVE 'COLOR_LINE' TO is_layout-info_fname.
    Field that identify cell color in inetrnal table
      MOVE 'COLOR_CELL' TO is_layout-ctab_fname.
    ENDFORM.                    " fill_layout
    Flow logic code
    PROCESS BEFORE OUTPUT.
      MODULE status_2000.
      MODULE alv_grid.
    PROCESS AFTER INPUT.
      MODULE user_command_2000.
    Rewards if useful....................
    Minal

  • To color selected cells in dynamically created table in ALV.

    Hi,
           The requirement is to display a table (whose columns are dynamic) using ALV n to color few cells of the table based on some condition.
    For creating the table dynamically i have used the method cl_alv_table_create=>create_dynamic_table.
    Now for coloring the cells i tried to use the field EMPHASIZE .
    But when I try this method the whole column is getting colored.
    So any suggestions on how to color only particular cells.

    Hi,
    Try this one...
    DATA: gs_layout TYPE slis_layout_alv, "Define layout
    gt_color TYPE lvc_t_scol WITH HEADER LINE. "Define Internal Table for Cell Colouring
    Use below Sample Code after building a Field Catalog:
    gs_layout-coltab_fieldname = 'COLINFO'.
    " 'it' is the final internal table which contain positive & negative value of Field 'MENGE'
    LOOP AT it.
    REFRESH gt_color.
    CLEAR gt_color.
    IF it-menge GE 0.
    CLEAR gt_color.
    gt_color-fname = 'MENGE'.
    gt_color-color-col = cl_gui_resources=>list_col_positive.
    gt_color-color-int = 0.
    APPEND gt_color.
    ELSEIF it-menge LE 0.
    CLEAR gt_color.
    gt_color-fname = 'MENGE'.
    gt_color-color-col = cl_gui_resources=>list_col_negative.
    gt_color-color-int = 0.
    APPEND gt_color.
    ENDIF.
    it-colinfo[] = gt_color[].
    MODIFY it.
    ENDLOOP.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = g_repid
    is_layout = gs_layout
    it_fieldcat = ct_fieldcat
    i_save = 'A'
    TABLES
    t_outtab = it
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    Hope this solves your problem.
    Regards,
    Tarun

  • Color some Cells in WD ALV

    Hello,
    im trying to Color some Cells in a Webdynpro ALV.
    So far i found out that there are maybe two ways:
    one like this with WDUI_TABLE_CELL_DESIGN
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b71393
    but i didnt find out, how to color specified Cells. With this example it is only possible to color the column by the saved color.
    the other way is to append a color table to ich column LVC_T_SCOL
    and after that
    *   We will set this COLOR table field name of the internal table to
    *   COLUMNS tab reference for the specific colors   
    TRY.       
    lo_cols_tab->set_color_column( 'T_COLOR' ).     
    CATCH cx_salv_data_error.                         "#EC NO_HANDLER   
    ENDTRY.
    http://help-abap.blogspot.com/2008/10/salv-table-9-apply-colors.html
    but i dont works in Webdynpro ALV. or has someone an idea?
    i hope someone can help me.
    greets,
    Sascha

    Hi ,
    Check this thread, [https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b71393]
    In your case you will have  to create 1 attribute ( type WDY_UIE_LIBRARY_ENUM_TYPE ) for every column. ( for eg: c1, c2, c3 ,c4 , c5 for pt1 pt2 pt3 pt4 pt5 respectively ) and bind it as follows,
    *---------- Column settings
      DATA: l_column_settings TYPE REF TO if_salv_wd_column_settings.
      l_column_settings ?= lo_value.
    * Get columns
      DATA: lt_columns TYPE salv_wd_t_column_ref ,
            ls_columns TYPE salv_wd_s_column_ref .
      DATA: l_column_header  TYPE REF TO cl_salv_wd_column_header .
      lt_columns = l_column_settings->get_columns( )              .
      LOOP AT lt_columns INTO ls_columns                          .
        CASE ls_columns-id                                        .
          WHEN 'PT1'                                            .
            l_column_header = ls_columns-r_column->get_header( )  .
            l_column_header->set_ddic_binding_field(
               if_salv_wd_c_column_settings=>ddic_bind_none )     .
            ls_columns-r_column->set_cell_design_fieldname( value = 'C1' ). "binding C1 is attribute
          WHEN 'PT2'                                            .
            l_column_header = ls_columns-r_column->get_header( )  .
            l_column_header->set_ddic_binding_field(
               if_salv_wd_c_column_settings=>ddic_bind_none )     .
            l_column_header->set_text( 'Item No' )                .
            ls_columns-r_column->set_cell_design_fieldname( value = 'C2' ). " binding
           ........similarly continue for all the columns.
    Now modify your internal table based on your condition and set the required color as follows,
      LOOP AT lt_alv INTO ls_alv.
              if pt1 is lowest. 
                ls_alv-color1 = '02'. " green
              elseif pt2 is lowest.
                ls_alv-color2 = '03'.  "red
              endif.
              MODIFY lt_alv FROM ls_alv INDEX sy-tabix.
            ENDLOOP.
    * Bind Data to ALV
            cn_alv->bind_table( lt_alv ).
    Hope it helps!
    Radhika.

  • ALV color a particular cell on meeting certain condition

    hi all
         i am working with ALV , my requirement is to color a particular cell if condition mate.
    like .
       i have two fields in my ITAB  PlanedCost and ActualCost
    If ACTUALCOST is >= 80% of PLANEDCOST then
    ACTUALCOST cell must come in RED COLOR.
    how to do so .
    please guide me.

    Hi Rock,
            I tried a program to color a cell based on its value, but it is not working. Am pasting the code below and please can u exactly tell me what is the problem it.
    *& Report  ZSAPCOLV
    REPORT  zsapcolv.
    TABLES:mara.
    TYPES:BEGIN OF ty_mara,
          matnr TYPE mara-matnr,
          mtart TYPE mara-mtart,
          color1(4),
         END OF ty_mara.
    DATA:it_mara TYPE STANDARD TABLE OF ty_mara,
         it_color  TYPE TABLE  OF lvc_s_scol,
         wa_mara TYPE ty_mara,
         wa_color    TYPE lvc_s_scol,
         is_layout   TYPE lvc_s_layo.
    DATA: t_newtable TYPE REF TO data,
    t_newline  TYPE REF TO data.
    FIELD-SYMBOLS: <dyntab> TYPE STANDARD TABLE,
                   <wa_dyntab> TYPE ANY,
                   <gfs_wa> TYPE ANY.
    TYPES: BEGIN OF ty_cmara,
        matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
       tabcolor TYPE lvc_t_scol,
    END OF ty_cmara.   " Cell color
    DATA:it_cmara TYPE STANDARD TABLE OF ty_cmara.
    DATA:
          gr_table     TYPE REF TO cl_salv_table,
          gr_functions TYPE REF TO cl_salv_functions,
          gr_display   TYPE REF TO cl_salv_display_settings.
    DATA:   it_fcat TYPE lvc_t_fcat,
            wa_fcat TYPE lvc_s_fcat.
    DATA:it_fcat1 TYPE lvc_t_fcat, "with cell color
         it_fcat2 TYPE lvc_t_fcat,
    wa_fieldcat LIKE LINE OF it_fcat1,
    wa_cellcolors TYPE lvc_s_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:<t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    DATA:t_line  TYPE REF TO data .
    *-----design selection screen for plant and material type.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-b01.
    SELECT-OPTIONS:
                     s_matnr     FOR mara-matnr.    "material type
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      PERFORM fetch_data.
      PERFORM display_data.
    *&      Form  fetch_data
    FORM fetch_data .
      DATA:wa_cmara TYPE ty_cmara.
      DATA: ls_tabcolor TYPE lvc_s_scol.
      SELECT
    FROM mara
        INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE matnr IN s_matnr.
      CHECK sy-subrc EQ 0.
      PERFORM build_catalog USING '1' 'MATNR' 'Material number' 'Material Number' ' ' '18'.
      PERFORM build_catalog USING '1' 'MTART' 'Material type' 'Material type' ' ' '10'.
      it_fcat1[] = it_fcat[].
       wa_fieldcat-fieldname = 'T_CELLCOLORS'.
       wa_fieldcat-ref_field = 'COLTAB'.
       wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
      APPEND wa_fieldcat TO it_fcat.
      cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = it_fcat
                                                  IMPORTING ep_table = t_newtable ).
      ASSIGN t_newtable->* TO <dyntab>.
      CREATE DATA t_line LIKE LINE OF <dyntab>.
      ASSIGN t_line->* TO <gfs_wa>.
      PERFORM fill_data.
    ENDFORM.                    " fetch_data
    *&      Form  build_catalog
    FORM build_catalog  USING    p_pos TYPE lvc_colpos
                           p_field TYPE lvc_fname
                           p_reptext TYPE reptext
                           p_coltext TYPE coltext
                           p_check TYPE lvc_checkb
                           p_len TYPE lvc_outlen.
      wa_fcat-col_pos    = p_pos.
      wa_fcat-fieldname  = p_field.
      wa_fcat-reptext    = p_reptext.
      wa_fcat-checkbox   = p_check.
      wa_fcat-outputlen  = p_len.
      wa_fcat-emphasize = '6'.
      IF p_check = 'X'.
        wa_fcat-edit = 'X'.
      ENDIF.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
    ENDFORM.                    " catalog
    *&      Form  fill_data
    FORM fill_data .
      FIELD-SYMBOLS: <wa_tmp> TYPE ANY,
                     <v_fld> TYPE ANY,
                     <color> TYPE ANY,
                     <wa_color> TYPE lvc_s_scol.
      DATA: v_fld(20).
      DATA : lv_cnt TYPE i,
             t_newline1  type ref to data,
             lv_cnt1 TYPE i.
        FIELD-SYMBOLS: <ta_color> TYPE lvc_t_scol.
         DATA : field(15) TYPE c,
             col TYPE lvc_s_scol.
      create data t_newline1 LIKE <wa_color>.
      LOOP AT it_mara INTO wa_mara.
        lv_cnt1 = lv_cnt1 + 1.
        LOOP AT it_fcat INTO wa_fcat.
          UNASSIGN <wa_tmp>.
          ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <wa_tmp>.
          CONCATENATE 'WA_MARA-' wa_fcat-fieldname INTO v_fld.
          ASSIGN (v_fld) TO <v_fld>.
          CHECK sy-subrc EQ 0.
          IF <v_fld> = '000000000000000004'.
             col-fname = wa_fcat-fieldname.
             col-color-col = '5' .
             col-color-int = '0' .
              "ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <ta_color>.
               ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <ta_color> .
               APPEND col TO <ta_color>.
            <wa_tmp> = <v_fld>.
            lv_cnt = lv_cnt + 1.
          ENDIF.
          IF lv_cnt = 1.
            APPEND <gfs_wa> TO <dyntab>.
          ELSE.
            MODIFY <dyntab> INDEX lv_cnt1 FROM <gfs_wa>.
          ENDIF.
        ENDLOOP.
        lv_cnt = 0.
        CLEAR wa_mara.
      ENDLOOP.
    ENDFORM.                    " fill_data
    *&      Form  display_data
    FORM display_data .
    IF <dyntab> IS NOT INITIAL.
       LOOP AT <dyntab> INTO <gfs_wa>.
         ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gfs_wa> TO <w_field>.
         ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <t_cellcolors> .
         CLEAR wa_cellcolors.
        "wa_cellcolors-fname = 'MATNR'.
         "IF <w_field> = '000000000000000004'.
           "FORMAT INTENSIFIED COLOR = 6.
           wa_cellcolors-fname = 'MATNR'.
           wa_cellcolors-color-col = '7'.
           wa_cellcolors-color-int = '1'.
           "wa_cellcolors-color-inv = '1'.
           "wa_cellcolors-NOKEYCOL = ''.
          "ELSE.
          "wa_cellcolors-color-col = '5'.
        "ENDIF.
         APPEND wa_cellcolors TO <t_cellcolors>.
         MODIFY <dyntab> FROM <gfs_wa>.
       ENDLOOP.
      cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyntab> ).
      gr_functions = gr_table->get_functions( ).
      gr_functions->set_all( abap_true ).
      gr_display = gr_table->get_display_settings( ).
      gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
      gr_display->set_list_header( 'MARA DATA' ).
      gr_table->display( ).
      "ENDIF.
    ENDFORM.                    " display_data

  • ALV color priority:  The layout color or the cell color?

    I'm trying to assign an ALV at the cell level but it is not showing up.  I have specificed the column color at the layout level.  Does the layout level have color priority?

    Hi
    see the doc and do accordingly
    1. add one more field to ur final internal table say COLOR(4)
    2. in layout wa_layout-style_fname = 'COLOR'. " if its grid
    wa_layout-style_fieldname = 'COLOR'. "if its list
    3. read table itab index 3.
    itab-color = 'C410'.
    modify itab index 3
    4. see program SHOWCOLO for all color codes
    1. Add a field of data type CHAR(3) to the internal output table.
    2. Enter the color code in the appropriate field of the row to be colored in the internal
    output table:
    Code: 'Cxy'
    C = Color (all codes begin with 'C')
    x = color number ('1' - '9')
    y = highlight ('0' = off, '1' = on)
    3. Assign the internal output table color code field name to the IS_LAYOUT importing
    structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call
    interface.
    To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, let’s modify declaration of our list data table “gt_list”.
    you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field “INFO_FNAME” of the layout structure.
    e.g.
    ps_layout-info_fname = <field_name_containing_color_codes>. “e.g. ‘ROWCOLOR’
    You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.
    You can color an entire row as described in the next section. However, this method is less time consuming.
    Coloring Individual Cells
    This is the last point about coloring procedures for the ALV Grid. The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by “more” is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.
    The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse).
    If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.
    Regards
    Anji

  • ALV Grid display cell color based on value ( Function Module ALV )

    Hi,
    I want to color the cell based on value eg ( Green = Green color, Red = Red color, Amber = Yello color ).
    Each and every cell is editable after displaying on screen. once the user clicks update button the contents has to be saved to a custom table.
    Can anyone help?
    Advance thanks

    Hi,
    <li>To get color for the cell, you need to set EMPHASIZE field with below information while building fieldcatalog.
    emphasize (highlight columns in color)
    value set: SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
    'X' = column is colored with the default column highlight color.
    'Cxyz' = column is colored with a coded color:
    C: Color (coding must begin with C)
    x: color number
    y: bold
    z: inverse
    <li> To edit the fields, you need to set EDIT = 'X' or INPUT= 'X' . Try those .
    wa_fieldcata-input = 'X'.
    <li>you need to set PF status , to do your remaining requirement.
    <li>For any help, you have to search the forum .
    Thanks
    Venkat.O

  • Color a cell in ALV using CL_GUI_ALV_GRID

    Hi,
    How to color a cell using CL_GUI_ALV_GRID?
    Thanks!

    Hi Ezachiael,
    you dont have to trigger event DOUBLE_CLICK, it will be triggered, in case of double click :-).
    You have to implent event handling class and event handler method - It is quite simple.
    Check out this [Reference on SDN|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907].
    Regards
    REA

  • How to color particular cell while working REUSE_ALV_HIERSEQ_LIST_DISPLAY

    Hi All,
    I am working with REUSE_ALV_HIERSEQ_LIST_DISPLAY  function module to diaplay hierarchial list. Now my requirement is to color particular cells in the output based on condition. Can any one help me in this regard.
    Thanks and Regards,
    Srinadh.

    hi ,
    try this..
    * FIELD CATALOG
    DATA : it_field TYPE slis_t_fieldcat_alv,                       "internal table for field catalog
           wa_field TYPE slis_fieldcat_alv.                         "work area for field catalog
    * FOR LAYOUT OF ALV GRID
    DATA : wa_layout TYPE slis_layout_alv.                          "work area for layout design
    *&      Form  SET_LAYOUT
    *       SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
    *       ALV GRID LINES IN ALTERNATIVE COLOURS
    FORM set_layout .
      wa_layout-zebra = 'X'.
    ENDFORM.                    " SET_LAYOUT
    *&      Form  ALV_DISPLAY
    *       SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
    *       FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
    *       AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
    *       DISPLAYED IN THE GRID FORMAT
    FORM alv_display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       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                         = wa_layout
         it_fieldcat                       = it_field
    *     IT_EXCLUDING                      =
    *     IT_SPECIAL_GROUPS                 =
    *     IT_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                          = it_final
    *   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.                    "alv_display
    regards
    Ritesh J

  • Alv color changing

    hi
      in alv output i got 10 records i need to change the color of only my 3rd record  (not the field) any one could give me an idea.

    REPORT ZTEST.
    TABLES:
      SPFLI.
    TYPE-POOLS:SLIS.
    DATA:
      T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      FS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
    DATA:
      FS_LAYOUT TYPE SLIS_LAYOUT_ALV.
    DATA:
      W_COL_POS TYPE I.
    DATA: BEGIN OF FS_SPFLI,
            W_COL  TYPE SLIS_T_SPECIALCOL_ALV,
            CARRID TYPE SPFLI-CARRID,
            CONNID TYPE SPFLI-CONNID,
            COUNTRYFR TYPE SPFLI-COUNTRYFR,
            COUNTRYTO TYPE SPFLI-COUNTRYTO,
            CITYTO TYPE SPFLI-CITYTO,
            DISTANCE TYPE SPFLI-DISTANCE,
            DISTID TYPE SPFLI-DISTID,
            FLTYPE TYPE SPFLI-FLTYPE,
            CHK(1),
            COL(3),
          END OF FS_SPFLI.
    DATA:                                      " Field String for coloring a
      FS_COL TYPE SLIS_SPECIALCOL_ALV.         " cell
    *--For CheckBox--
    FS_LAYOUT-BOX_FIELDNAME = 'CHK'.
    *--For Row color--
    FS_LAYOUT-INFO_FIELDNAME = 'COL'.                 " Row Color
    *--For Coloring a Cell--
    FS_LAYOUT-COLTAB_FIELDNAME = 'W_COL'.
    DATA:
       T_SPFLI LIKE
      STANDARD TABLE
            OF FS_SPFLI.
    DATA:
      T_SORT TYPE SLIS_T_SORTINFO_ALV.
    DATA:
      FS_SORT TYPE SLIS_SORTINFO_ALV.
    FS_SORT-GROUP = 'UL'.
    APPEND FS_SORT TO T_SORT.
    SELECT CARRID
           CONNID
           COUNTRYFR
           FLTYPE
      INTO CORRESPONDING FIELDS OF TABLE T_SPFLI
      FROM SPFLI.
    WHERE CARRID EQ 'AA'.
    *--COLORING A CELL--
    CLEAR FS_SPFLI.
    FS_COL-FIELDNAME = 'CARRID'.
    FS_COL-COLOR-COL = 3.
    APPEND FS_COL TO FS_SPFLI-W_COL.
    MODIFY T_SPFLI FROM  FS_SPFLI INDEX 10 TRANSPORTING W_COL.
    MODIFY T_SPFLI FROM  FS_SPFLI INDEX 11 TRANSPORTING W_COL.
    *--COLORING A CELL--
    CLEAR FS_SPFLI.
    FS_COL-FIELDNAME = 'CONNID'.
    FS_COL-COLOR-COL = 5.
    APPEND FS_COL TO FS_SPFLI-W_COL.
    MODIFY T_SPFLI FROM  FS_SPFLI INDEX 3 TRANSPORTING W_COL.
    *--COLORING A ROW--
    FS_SPFLI-COL = 'C60'.
    MODIFY T_SPFLI INDEX 7 FROM FS_SPFLI TRANSPORTING COL.
    *--FIELD CATALOGUE--
    PERFORM FIELD_FILLING_CARRID.
    PERFORM FIELD_FILLING_CONNID.
    PERFORM FIELD_FILLING_COUNFR.
    PERFORM FIELD_FILLING_FLTYPE.
    PERFORM FIELD_FILL.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_INTERFACE_CHECK              = ' '
      I_BYPASSING_BUFFER             =
      I_BUFFER_ACTIVE                = ' '
      I_CALLBACK_PROGRAM             = ' '
      I_CALLBACK_PF_STATUS_SET       = ' '
      I_CALLBACK_USER_COMMAND        = ' '
       I_STRUCTURE_NAME               =
        IS_LAYOUT                      = FS_LAYOUT
        IT_FIELDCAT                    = T_FIELDCAT
      IT_EXCLUDING                   =
      IT_SPECIAL_GROUPS              =
        IT_SORT                        = T_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
      IR_SALV_LIST_ADAPTER           =
      IT_EXCEPT_QINFO                =
      I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER        =
      ES_EXIT_CAUSED_BY_USER         =
      TABLES
        T_OUTTAB                       = T_SPFLI
    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  FIELD_FILLING_CARRID
          text
    -->  p1        text
    <--  p2        text
    FORM FIELD_FILLING_CARRID .
      ADD 01 TO W_COL_POS.
      FS_FIELDCAT-FIELDNAME = 'CARRID'.
      FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-row_POS = W_COL_POS.
      FS_FIELDCAT-COL_POS = W_COL_POS.
      FS_FIELDCAT-KEY = 'X'.
      FS_FIELDCAT-OUTPUTLEN = 5.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
    ENDFORM.                    " FIELD_FILLING_CARRID
    *&      Form  FIELD_FILLING_CONNID
          text
    -->  p1        text
    <--  p2        text
    FORM FIELD_FILLING_CONNID .
      ADD 01 TO W_COL_POS.
      FS_FIELDCAT-FIELDNAME = 'CONNID'.
      FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
       FS_FIELDCAT-row_POS = W_COL_POS.
      FS_FIELDCAT-COL_POS = W_COL_POS.
      FS_FIELDCAT-KEY = 'X'.
      FS_FIELDCAT-OUTPUTLEN = 6.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
    ENDFORM.                    " FIELD_FILLING_CONNID
    *&      Form  FIELD_FILLING_COUNFR
          text
    -->  p1        text
    <--  p2        text
    FORM FIELD_FILLING_COUNFR .
      ADD 01 TO W_COL_POS.
      FS_FIELDCAT-FIELDNAME = 'COUNTRYFR'.
      FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
       FS_FIELDCAT-row_POS = W_COL_POS.
      FS_FIELDCAT-COL_POS = W_COL_POS.
    *FS_FIELDCAT-ICON = 'X'.
    FS_FIELDCAT-EMPHASIZE = 'X'.
      FS_FIELDCAT-OUTPUTLEN = 10.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
    ENDFORM.                    " FIELD_FILLING_COUNFR
    *&      Form  FIELD_FILLING_FLTYPE
          text
    -->  p1        text
    <--  p2        text
    FORM FIELD_FILLING_FLTYPE .
      ADD 01 TO W_COL_POS.
      FS_FIELDCAT-FIELDNAME = 'FLTYPE'.
      FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
      FS_FIELDCAT-COL_POS = W_COL_POS.
       FS_FIELDCAT-row_POS = W_COL_POS.
      FS_FIELDCAT-EMPHASIZE = 'C610'.                        " Column Color
      FS_FIELDCAT-KEY = SPACE.
    *FS_FIELDCAT-outputlen = 10.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
    ENDFORM.                    " FIELD_FILLING_FLTYPE
    *&      Form  field_fill
          text
    -->  p1        text
    <--  p2        text
    FORM FIELD_FILL .
      ADD 01 TO W_COL_POS.
      FS_FIELDCAT-FIELDNAME = 'W_COL'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
      FS_FIELDCAT-COL_POS = W_COL_POS.
       FS_FIELDCAT-row_POS = W_COL_POS.
    FS_FIELDCAT-EMPHASIZE = 'C610'.                        " Column Color
      FS_FIELDCAT-KEY = SPACE.
      FS_FIELDCAT-SELTEXT_L = 'NOT FROM DDIC'.
      FS_FIELDCAT-OUTPUTLEN = 20.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
    ENDFORM.                    " field_fill
    Go through the following code.... It will help you in all the aspects...
    Reward if it helps u........

  • Dynamically coloring a cell based on user action.

    Dear Gurus,
    I know that many a questions have been posted based on cell coloring. But sadly i couldn't find anything that suits my requirement. My requirement is like i want to color a cell when the user double clicks on that cell. I have captured the double click event and iam filling the required color in a field in final itab (name : color). After this iam calling refresh_table_display.
    But sadly no changes are visible. Any help would be greatly appreciated.
    Given below the code.
    gfl_color-fname = l_fname-fieldname.
              gfl_color-color-col = '6' .
              gfl_color-color-inv = '1'.
              APPEND gfl_color TO gfl_rfinal-color.
              MODIFY git_rfinal FROM gfl_rfinal INDEX l_index-row_id
                                                TRANSPORTING color.
              CLEAR gfl_rfinal.
              CALL METHOD r_grid1->refresh_table_display
                EXCEPTIONS
                  finished = 1
                  OTHERS   = 2.
    Thanks and Regards,
    Sandeep Sivan
    Edited by: sandeep sivan on Aug 5, 2010 10:51 AM
    Edited by: sandeep sivan on Aug 5, 2010 11:01 AM

    Issue Solved.

  • Problem in color a cell for field symbol table.

    Hi guru's
    when i'm trying to color a cell based on condition, getting the following error.
    ERROR:   the data object  <line> has no structure and therefore no component called  "cell_colour" .
    providing my code here:
    DATA: wa_cellcolor TYPE lvc_s_scol,
             lv_index     TYPE sy-tabix.
       break satishkumarc.
       LOOP AT <table> ASSIGNING <line>.
         lv_index = sy-tabix.
         ASSIGN COMPONENT 'COMPLIANCE' OF STRUCTURE <line> TO <field>.
         IF <field> EQ 'YES'.
           wa_cellcolor-fname     = 'COMPLIANCE'.
           wa_cellcolor-color-col = col_positive.
           wa_cellcolor-color-int = 0.
           wa_cellcolor-color-inv = 0.
         ELSE.
           wa_cellcolor-fname     = 'COMPLIANCE'.
           wa_cellcolor-color-col = col_negative.
           wa_cellcolor-color-int = 0.
           wa_cellcolor-color-inv = 0.
         ENDIF.
         APPEND wa_cellcolor TO <line>-cell_colour.                                                     "   error line
         MODIFY <table> FROM <line>  INDEX lv_index TRANSPORTING cell_colour.      "  error line
         CLEAR: wa_cellcolor.
       ENDLOOP.
    actually i know  that  <line>-cell_colour  won't work. but i don't know how to achive this functionality .
    could anybody please help me out in this.
    Thanks in Advance.
    regards
    satish
    thank

    hi ashish,
    i'm using
    field-symbols: <line> type any.
    CREATE DATA  mydata  LIKE LINE OF <table>.
           ASSIGN mydata->* TO <line>.
    to make the structure. so i guess i cannot give the structure name while declaring <line>.
    Thanks & regards
    satish

  • How to set colors in cells depending the conditions  in alvtree

    Hi All,
    Could you please provide me idea or sample program how to set colors in cells depending the conditions  in alvtree.
    Thanks,
    Suresh

    When running vim in a terminal, it will use whatever colour scheme is defined by the terminal.  You should have a look at this thread:
    http://bbs.archlinux.org/viewtopic.php?id=51818
    Also, check the wiki article on Xdefaults.

  • Color a cell when i select THAT cell

    Hi!
    I searced for something about my question, but i didn't find anything about it :/
    I have to color one cell of a JTable when i select it and make some operation.
    I tried with this:
    java.awt.Component cell = jTable1.getComponentAt(jTable1.getSelectedColumn(),jTable1.getSelectedRow());
                     cell.setForeground(java.awt.Color.red);But it color all my table and not THE cell that i've selected.
    If i've understood, the overriding of the metods prepareRenderer (or similar, i don't remember its exact name) sets the color of cells under particulare condition, but i think i don't need it: i have to color a cell only when i select it.
    Thank you!

    but i think i don't need it: i have to color a cell only when i select it. Why don't you think you need it. You have a special requirement that you only want to give the cell a specific color when it is selected. So the prepareRenderer() method should do what you want.
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.

Maybe you are looking for