ADD COLOR TO CELL WITH ALV REPORT

This alv report is useful to add color to a particular cell using abap alv report.Here is the code.

DATA: g_color_green TYPE slis_t_specialcol_alv.

  • create a table of fieldnames to be coloured intensified green -

PERFORM colour_cells TABLES g_color_green
USING 21 31 5.


  • set cells of this line to intensified green
IF CONDITION.....
out-color] = g_color_green[.
ENDIF.


---------------------------------------------------------------------

  • FORM E05_LAYOUT_BUILD *
---------------------------------------------------------------------
  • ALV Layout options *
---------------------------------------------------------------------
  • <-> E05_LS_LAYOUT *
---------------------------------------------------------------------
FORM e05_layout_build USING e05_ls_layout TYPE slis_layout_alv.
  • Setting this flag avoids having to define field sizes.
e05_ls_layout-colwidth_optimize = 'X'.

  • FIELD COLOR contains table of FIELDNAME and COLOURS.
e05_ls_layout-coltab_fieldname = 'COLOR'.
ENDFORM.

&---------------------------------------------------------------------
*& Form colour_cells
&---------------------------------------------------------------------
  • Set up table to color field groups different from default colour
----------------------------------------------------------------------
  • <--> t_color table of fields and colours
  • <-- p_index_from - first field of catalogue to be coloured
  • <-- p_index_to - last field of catalogue to be coloured
  • <-- p_color - color number
----------------------------------------------------------------------
FORM colour_cells TABLES t_color
USING p_index_from TYPE sy-index
p_index_to TYPE sy-index
p_color TYPE i.

DATA: ls_fieldcat TYPE slis_fieldcat_alv,
w_tab TYPE slis_specialcol_alv.

  • use field catalogue to build new table for consecutive fields
LOOP AT gt_fieldcat INTO ls_fieldcat FROM p_index_from TO p_index_to.
w_tab-fieldname = ls_fieldcat-fieldname.
w_tab-color-col = p_color.
IF p_color = 5. "green
w_tab-color-int = 1. "intensified on
ELSE.
w_tab-color-int = 0. "intensified off
ENDIF.
APPEND w_tab TO t_color.

ENDLOOP.
ENDFORM. " colour_cells

The previous post deals with finding user exits for a given sap transaction code.

No comments:

Post a Comment