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

Highlighting cells in ALV

Former Member

Hi, sorry to ask a question that has already been asked many times

**** This question is not about cells colouring (background) *** Thanks ***

How can I mark a cell as error, with a red border in my ALV ?

Using method ADD_PROTOCOL_ENTRY of class CL_ALV_CHANGED_DATA_PROTOCOL I've add some protocol entries to the alv protocol at the event Z_CONTROL_DATA,

Then I show the protocol entry with method DISPLAY_PROTOCOL   but the wrong cells are not marked red.

==> Is there a way to have them marked red like in the output of "on data_changed event" ?

I hope someone will finally give me (and the world, as this question seems to remain unanswered since years) an answer .

Thanks a lot



Former Member
0 Kudos


Pls check below example program whether it useful




Chandra, I'm sorry but it has absolutely nothing to do with my problem

I'm trying to put a red border around a cell, and have not yet found a clue of how to do this on Google.... seems that this question has beeen asked many times but not (yet) answered....


0 Kudos



Former Member
0 Kudos

The poor guy only got answers on how to change BACKGROUND color

Active Participant
0 Kudos

I dont think there is a standard solution, probably you need to use custom coding to achieve it.. youneed to debug the code for the error message and find out which part of the code is responsible for
the modification of the layout .. you can sebug the standard report bcalv_grid_edit by entering an alphabet in a numberic field and debug.. if you find something please do share..


i saw in a post someone said that cellstyles can be used for border coloring but no examples, ( but as far as i know, it can be used for making buttons in alv display only.

Former Member
0 Kudos

you can go to this link also.

Dear Martin,

First in table for displaying data in ALV should have

for Eg. This



DATA rowcolor(4) TYPE c .

DATA cellcolors TYPE lvc_t_scol .

DATA END OF gt_list .

there must be flag variable showing that data has error and protocol entry is displayed.

Adding inner table that will contain cell color data

DATA ls_cellcolor TYPE lvc_s_scol .


READ TABLE gt_list INDEX 5 .

ls_cellcolor-fname = 'SEATSOCC' .

ls_cellcolor-color-col = '7' .

ls_cellcolor-color-int = '1' .

APPEND ls_cellcolor TO gt_list-cellcolors .

MODIFY gt_list INDEX 5 .

There must some coding for displaying protocol include these coding there

Or You can use cell Styles



DATA rowcolor(4) TYPE c .

DATA cellcolors TYPE lvc_t_scol .

DATA cellstyles TYPE lvc_t_styl .

DATA END OF gtlist .

READ TABLE gt_list INDEX 7 .

ls_style-fieldname = 'SEATSMAX' .

ls_style-style = cl_gui_alv_grid=>MC_STYLE_HOTSPOT  .

APPEND ls_style TO gt_list-cellstyles .

MODIFY gt_list INDEX 7 .


Gaurav Ahluwalia

0 Kudos

**** This question is not about cells colouring (background) *** Thanks ***

Former Member
0 Kudos

here's the step.

1. in the type declaration for the internal table , add a new field say its cell color it sud refer to table type lvc_t_scol, this is used for cell coloring or highlighting a cell.

        cell_color  TYPE lvc_t_scol,   " For cell colouring

2. next process is very simple, for each line item suppose in my case read the code below:

         CLEAR l_atnam.
         SELECT SINGLE atnam FROM cabn INTO l_atnam WHERE atnam EQ ls_zvar_tsc1-zvar_cf.
         IF sy-subrc <> 0.
           l_global_err_flag = 'X'.
*** new code to be tested
           ls_cell_color-fname = 'ZVAR_CF'.
           ls_cell_color-color-col = '6'.
           ls_cell_color-color-int = '1'.
           ls_cell_color-color-inv = '1'.
           APPEND ls_cell_color TO ls_zvar_tsc1-cell_color.
           MODIFY lt_zvar_tsc1 FROM ls_zvar_tsc1.
*** end of new code
see the bold part, u pass the column name, color, etc, append it to the field  cell_colr of the current row, remember this column is a internal table, itself so multiple columns can be added but not duplicates.

then modify the changed structure to the internal table.

3. before calling the screen and set_table_* method in the layout there is a column called ctab_fname, pass the name of the field that holds info on cell coloring, in our case look at my code below:

   ls_layout-ctab_fname = 'CELL_COLOR'.

done then call the method pass the layout too and u have cells highlighted.

   CALL METHOD lref_grid->set_table_for_first_display
       is_layout       = ls_layout
       it_outtab       = lt_zvar_tsc1[]
       it_fieldcatalog = lt_fcat[].

Hi, if u think its not helpful or u find difficulty to understand please fell free i will bw happy to help. or u can share ur further requirement. I will try to upload a doc with a simple program soon on many simple ALV functionalities asap 🙂 happy coding...

0 Kudos

**** This question is not about cells colouring (background) *** Thanks ***

0 Kudos

please make sure you understand what we are talking about, we can change the border of the cell by this method, not the backgroud color.

Active Participant
0 Kudos

i am sure you can achieve this, because i had experience in setting cell with red border.

because now i can't login the sap system, what i only can tell you is

search method in class cl_gui_alv_grid, key words in this method should be 'set' 'error' 'cell', if you can find this method, use it to set the cell as error, then the border will come.

hope this will help you.

Active Contributor
0 Kudos

I know what you are talking about. You can get RED or Yellow borders around the cell if make the cells as "bad".

Std ALV calls the method SAVE_DATA when you try to change anything. Based on the validations it prepares the error table and call the method SET_ERROR_CELLS of class CL_GUI_ALV_GRID_BASE. This method directly calls a method of OLE to set the invert borders.

I'm not sure if the same thing can be achieved via Styles.

Naimesh Patel

Former Member
0 Kudos


I hope you are using Method : set_table_for_first_display.

If yes, you can highlight the Error Rows by appliying the following codes.

DATA : lt_cells TYPE lvc_t_cell.
DATA : lw_cells TYPE lvc_s_cell.

LOOP AT pt_outtab ASSIGNING <fs_outtab> WHERE p_flag = 'E'. (E- error)
      lw_cells-row_id-index = sy-tabix.
      lw_cells-col_id-fieldname = 'LIFNR'.
      APPEND lw_cells TO lt_cells.
      lw_cells-col_id-fieldname = 'NAME1'.
      APPEND lw_cells TO lt_cells.
      CLEAR lw_cells.

CALL METHOD g_grid->set_selected_cells
        it_cells = lt_cells.

Hope this is what you looking for. Let me know.



Former Member
0 Kudos

Hi JC Martin, I did exactly some thing u are looking for validated a column and incase of error highlighted it in red for get the stuffs i mentioned in last post like inheriting and blah blah. here is the working code below. Incase of more explanation required give me a shout I will be very happy to help you 😉

IF sy-uname EQ 'PRBIST'.

                   LOOP AT er_data_changed->mt_good_cells ASSIGNING <lfs_mod_cells>.

                     CASE <lfs_mod_cells>-fieldname.
                       WHEN 'ZVAR_VF'.
                         CALL METHOD er_data_changed->get_cell_value
                             i_row_id    = <lfs_mod_cells>-row_id
                             i_fieldname = <lfs_mod_cells>-fieldname
                             e_value     = lv_value.

                         IF NOT lv_value IS INITIAL.
* logic is to identify the row number, use that as index and read the value of the characteristics entered.
* next read CABN to find data type of the characteristics.
                           UNASSIGN  <lfs_zvar_tsc1>.
                           READ TABLE lt_zvar_tsc1 ASSIGNING <lfs_zvar_tsc1> INDEX <lfs_mod_cells>-row_id.
                           IF sy-subrc = 0.
                             ASSIGN COMPONENT 'ZVAR_CF' OF STRUCTURE <lfs_zvar_tsc1> TO <lfs_zvar_cf>.
                             IF <lfs_zvar_cf> IS ASSIGNED.
                               CLEAR: lv_atfor.
                               SELECT SINGLE atfor INTO lv_atfor FROM cabn WHERE atnam = <lfs_zvar_cf>.
                               IF sy-subrc = 0.
                                 lv_boolean = me->check_data_type( im_char_name = <lfs_zvar_cf>
                                                                   im_data_type = lv_atfor
                                                                   im_entered_value = lv_value ).
                                 IF lv_boolean = 'F'.
                                   " // add it in mt_protocol
                                   ls_mt_protocol-msgid     = 'ZVAR_ERR'.
                                   ls_mt_protocol-msgno     = '000'.
                                   ls_mt_protocol-msgty     = 'E'.
                                   ls_mt_protocol-fieldname = 'ZVAR_VF'.
                                   ls_mt_protocol-row_id    = <lfs_mod_cells>-row_id.

                                   APPEND ls_mt_protocol TO er_data_changed->mt_protocol.