Register Login

ALV Colored Grid Display Program

Updated May 18, 2018

The following extract can be used in ALV related program, where there is a requirement to have colored lines in the display, based on certain conditions.

Add a field to your output table which will determine row color.

data: begin of it_output occurs 0,

"your output fields here/ structure of ur table

ROWCOLOR (4) type c,

             end of it_output.

You can also define constants that can be used in the program instead of specifying the color, since the value does not change

 

constants:      red(4)     TYPE c VALUE 'C600',

                                green(4)   TYPE c VALUE 'C500'.

 

Once these declarations are done, you can go about processing through the internal table as per your business logic.

 

When you want to color the lines, just loop through the internal table and on the reqd. condition assign color for the row and modify the internal table.

 

e.g.

loop at it_output.

if it_output-field1 > 5.                    ß YOU’RE condition here

it_output-rowcolor = red.          ß assign color to row

else.

it_output-rowcolor = green.

endif.

modify it_output.                             ß modify internal table

endloop.

 

but we still need to integrate this with the ALV display function module, this can be done by creating a structure of type slis_layout_alv.

 

e.g.  DATA : fs_layout type slis_layout_alv.

 

fs_layout-info_fieldname = 'ROWCOLOR'.

 

This is to be passed to the function module that displays ALV, it shows in which field the color information is.

 

e.g.

****call ALV

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

      i_callback_program      = sy-repid

      i_callback_user_command = ''

      it_fieldcat             = it_fcat

      is_layout               = fs_layout  ß give the layout structure

    TABLES

      t_outtab                = it_zsapb_ctrlview.

  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

 

Thanks & Regards,


×