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.
cancel
Showing results for 
Search instead for 
Did you mean: 

changing colour based on value

0 Kudos

I have an OO ALV, in that the quantity and netprice field is editable and there is some color based on some conditions.

Now, I have requirement to change the color of the cells after editing the value , based on conditions.

Thanks in advance.

10 REPLIES 10

former_member751591
Participant
0 Kudos

Welcome to the SAP Community! We wanted to give you the opportunity to take the tutorial to get started in SAP Community, as it provides tips for preparing questions that draw responses from our members.

Additionally, by adding a picture to your profile you encourage readers to respond to your question. Learn more about your profile using Profile Tutorial

Thank you!

FredericGirod
Active Contributor

This is your requierment, not a technical question. So what is your question ?

VXLozano
Active Contributor

Did you even tried to search for help before posting this question? I have a fish memory for some things, like the one you are asking for, and I'm able to fast find the way to do it without having to post the question again and again.

As you can edit, I assume you are using the "deprecated" CL_GUI_ALV_something... check for program samples, or just search this place for

CL_GUI_ALV_something cell color

Sandra_Rossi
Active Contributor
0 Kudos

The term "OO ALV" is confusing, are you talking about CL_GUI_ALV_GRID or about "OM ALV" (Object Model ALV A.K.A. CL_SALV_* classes)?

The question has been asked so many times how to set a color in a cell. If you tried one of the many solutions, could you precise what your issue is?

0 Kudos

Yea, I am using CL_GUI_ALV_GRID

I have a requirement like i have to change the color of a cell after edit based on some condition

for example suppose if the after edit the Net price is more than 1000 so the colour of the cell will be red.

I want to know how to add colours to the cells after editing the value .

Sandra_Rossi
Active Contributor

So you know how to set the color of a given cell, but you want to know how to change it after you press a button in the toolbar, right?

So, during the processing of the function code, based on condition, you change the color in the field catalog, you transfer it to the frontend (SET_FRONTEND_FIELDCATALOG) and you refresh the ALV (REFRESH).

EDIT after raymond.giuseppi comment: sorry, I am full wrong here. You just need to update the color in the ALV internal table and call REFRESH_TABLE_DISPLAY.

raymond_giuseppi
Active Contributor

Perform some search, you could add a column in your table, type lvc_t_scol, so for each record you can add in this itab a record per column with a color attribute

  • In first display of the table, pass the color column name to the IS_LAYOUT-CTAB_NAME field
  • As sandra.rossi wrote, once you update the displayed internal table, refresh the display with the CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY method.

0 Kudos

METHOD HANDLE_DATA_CHANGED.

    loop at er_data_changed->mt_MOD_cells into is_cells.
      check is_cells-fieldname eq 'NETPR'.
CALL METHOD rg1->get_frontend_layout
  IMPORTING
    es_layout = IS_LAYO1.
      CASE IS_CELLS-FIELDNAME.
        WHEN 'NETPR'.
      REPLACE ALL OCCURRENCES OF ',' IN IS_CELLS-VALUE WITH '.'.
          MESSAGE IS_CELLS-VALUE TYPE 'I'.
         IF IS_CELLS-VALUE >= 100000 AND IS_CELLS-VALUE <= 200000.
           MESSAGE 'HIGH' TYPE 'I'.
        ls_color-fname     = 'NETPR'.
        ls_color-color-col = 3.
        ls_color-color-int = 0.
        ls_color-color-inv = 0.
        APPEND ls_color TO <fs>-color.
      ELSE .
        MESSAGE 'LOW' TYPE 'I'.
        ls_color-fname     = 'NETPR'.
        ls_color-color-col = 4.
        ls_color-color-int = 0.
        ls_color-color-inv = 0.
        APPEND ls_color TO <fs>-color.
      ENDIF.
      ENDCASE.
ENDLOOP.
    is_layo1-ctab_fname = 'COLOR1'.

    CALL METHOD rg1->set_frontend_layout
  EXPORTING
    is_layout = is_layo1.

    CALL METHOD rg1->refresh_table_display
     EXPORTING
*       is_stable      =
       i_soft_refresh = 'X'
*     EXCEPTIONS
*       finished       = 1
*       others         = 2
           .
   IF sy-subrc <> 0.
*    Implement suitable error handling here
   ENDIF.
      ENDMETHOD.

0 Kudos

Can anyone tell me what I am doing wrong ?

when I am pressing enter after editing the value no colors are coming even the old colors are also vanished.

Sandra_Rossi
Active Contributor
0 Kudos

I am concerned about <FS>. Is it the line of the ALV internal table, of which you want to update the color in one of the cells? If yes, then its color column seems to be named COLOR, but you indicate the name COLOR1 in the layout.

Moreover, you need to call SET_FRONTEND_LAYOUT once for all, before SET_TABLE_FOR_FIRST_DISPLAY, you don't need to call it while you handle user events.