Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

alv grid

Hi,

How can i color one cell in alv grid (reuse_alv_grid_display) .

thanks

ofer

Tags:
replied

Hi,

Check this sample program from Is it possible to color a text in ALV GRID

..

TABLES: lips.

TYPE-POOLS: slis.
INCLUDE <icon>.

DATA: it_fieldcat TYPE lvc_t_fcat,
      it_fieldcat1 TYPE slis_t_fieldcat_alv..

DATA:it_events TYPE slis_t_event.

DATA: x_fieldcat TYPE lvc_s_fcat,
x_fieldcat1 TYPE slis_fieldcat_alv.

DATA:x_layout TYPE lvc_s_layo.

DATA: BEGIN OF it_vbap OCCURS 0,
  vbeln LIKE vbap-vbeln,
  posnr LIKE vbap-posnr,
  cellcolor TYPE lvc_t_scol,
END OF it_vbap.

SELECT vbeln
       posnr
  UP TO 20 ROWS
  INTO CORRESPONDING FIELDS OF TABLE it_vbap
  FROM vbap.


DATA:l_pos TYPE i VALUE 1.
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'.
DATA: ls_cellcolor TYPE lvc_s_scol.
DATA: l_index TYPE sy-tabix.
LOOP AT it_vbap.
  l_index = sy-tabix.
  IF l_index = 1 OR l_index = 10.
    ls_cellcolor-fname = 'VBELN'.
    ls_cellcolor-color-col = '6'.
    ls_cellcolor-color-int = '1'.
    APPEND ls_cellcolor TO it_vbap-cellcolor.
    MODIFY it_vbap INDEX l_index TRANSPORTING cellcolor.
  ENDIF.
  IF l_index = 5 OR l_index = 20.
    ls_cellcolor-fname = 'VBELN'.
    ls_cellcolor-color-col = '4'.
    ls_cellcolor-color-int = '1'.
    APPEND ls_cellcolor TO it_vbap-cellcolor.
    MODIFY it_vbap INDEX l_index TRANSPORTING cellcolor.
  ENDIF.
ENDLOOP.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program = sy-repid
    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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question