Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Regarding ALV

Former Member
0 Likes
673

Hi ALL,

How to create row color in ALV list display.

I want to make 1st row as red and remaining rows as green.

Regards

Divakar

1 ACCEPTED SOLUTION
Read only

anversha_s
Active Contributor
0 Likes
644

hi divakar,

chk this link.

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

rgds

anver

if hlped mark points

hi divakar,

chk this link.

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

rgds

anver

if hlped mark points

3 REPLIES 3
Read only

anversha_s
Active Contributor
0 Likes
645

hi divakar,

chk this link.

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

rgds

anver

if hlped mark points

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
644

Hopefully you are using the FM and this example will show you how to color the line.



report zrich_0004
       no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,
      matnr type mara-matnr,
      mtart type mara-mtart,
      maktx type makt-maktx,
      color_line(4) type c,
      tcolor type slis_t_specialcol_alv,  "cell
      end of imara.

data: xcolor type slis_specialcol_alv.

start-of-selection.

  perform get_data.
  perform write_report.


************************************************************************
*  Get_Data
************************************************************************
form get_data.

  imara-matnr = 'ABC'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for ABC'.
  append imara.

  imara-matnr = 'DEF'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for DEF'.
  append imara.

  imara-matnr = 'GHI'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for GHI'.
  append imara.

  loop at imara.

    if sy-tabix = 1.
      imara-color_line = 'C410'.   " color line
    endif.

    if sy-tabix = 2.          "color CELL
      clear xcolor.
      xcolor-fieldname = 'MTART'.
      xcolor-color-col = '3'.
      xcolor-color-int = '1'. "Intensified on/off
      xcolor-color-inv = '0'.

      append xcolor to imara-tcolor.

    endif.

    modify imara.

  endloop.

endform.

************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.

  data: layout type  slis_layout_alv.

  layout-coltab_fieldname = 'TCOLOR'.
  layout-info_fieldname = 'COLOR_LINE'.

  perform build_field_catalog.

* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            is_layout   = layout
            it_fieldcat = fieldcat
       tables
            t_outtab    = imara.

endform.

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.

  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat. refresh: fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Type'.
  fc_tmp-fieldname  = 'MTART'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '4'.
  append fc_tmp to fieldcat.

  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  fc_tmp-emphasize = 'C610'.   " color column
  append fc_tmp to fieldcat.

endform.

I have an example for the class based also if you need it.

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
644

BTW, the color coding works like this.




*****************************************************************
* 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                                                   *

Regards,

RIch Heilman