0

I need to color the cells of an ALV Grid dynamically. I use CL_SALV_TABLE.

E.g. in my case I select data from data table according to a parameter. I want to display the selected results in an ALV-grid. -> so far everything works as I need it.

Now, I want to color cells in the grid in red which have initial or zero value.

Is this possible? If yes, how to do it?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
D.Ge.
  • 107
  • 1
  • 9
  • There are many answers in the web, you could at least try them, and revert back if you fail and ask a more precise question including a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Sandra Rossi Sep 25 '19 at 09:12
  • Which ALV technology do you use? (`REUSE_ALV_GRID_DISPLAY`, `CL_GUI_ALV_GRID`, `CL_SALV_TABLE`, Web Dynpro, ...) – Sandra Rossi Sep 25 '19 at 09:32
  • I am using cl_salv_table ! – D.Ge. Sep 25 '19 at 10:31

1 Answers1

4

Add another column of type lvc_t_scol to your final output table, fill it and tell the ALV to use it as a color column.

Here is a blog post that includes the possible colors.

* declaration of output table with color column
TYPES: BEGIN OF lty_output,
         carrid   TYPE  scarr-carrid,
         carrname TYPE  scarr-carrname,
         color    TYPE  lvc_t_scol,
       END OF lty_output.

DATA gt_output TYPE STANDARD TABLE OF lty_output.

* filling color column of output table (e.g. based on condition during a LOOP)
DATA: ls_color TYPE lvc_s_scol,
      lt_color TYPE lvc_t_scol.

gt_output = VALUE #(
    ( carrid = 'AA' carrname = 'American Airlines' color = VALUE #(
        ( fname = 'CARRNAME' color = VALUE #( col = 6 int = 0 inv = 0 ) ) ) )
    ( carrid = 'AF' carrname = 'Air France' color = VALUE #(
        ( fname = 'CARRID'   color = VALUE #( col = 7 int = 0 inv = 0 ) )
        ( fname = 'CARRNAME' color = VALUE #( col = 5 int = 0 inv = 0 ) ) ) )
    ( carrid = 'LH' carrname = 'Lufthansa' color = VALUE #(
        ( fname = ''         color = VALUE #( col = 3 int = 0 inv = 0 ) ) ) ) ).

cl_salv_table=>factory(
    IMPORTING
        r_salv_table = DATA(go_alv)
    CHANGING
        t_table = gt_output ).

* setting color column
go_alv->get_columns( )->set_color_column( 'COLOR' ).

go_alv->display( ).
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Legxis
  • 886
  • 7
  • 19