Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Ram Batulla
Submitted: 03/July/2007

Description: How to change the Cell Color based on its content in an ABAP Web-Dynpro ALV?

Step-1: Add a new Attribute of type "WDY_UIE_LIBRARY_ENUM_TYPE" to the Context Node which is used to display the data on ALV. Lets name the Attribute as "CELL_COLOUR".

Step-2: Figure out the column (Column Variance in the below example) which has to be marked with a different colour based on its content. Assign the context attribute "CELL_COLOUR" to the "Cell Design Fieldname" attribute of the respective column. This can be done while setting Column attributes for each of the ALV Columns - as shown below:

Error rendering macro 'code': Invalid value specified for parameter 'lang'
* Data declarations for ALV
DATA: lt_columns                  TYPE        salv_wd_t_column_ref,
      ls_column                   TYPE        salv_wd_s_column_ref,
      lo_column                   TYPE REF TO cl_salv_wd_column ,
      lo_col_head                 TYPE REF TO cl_salv_wd_column_header ,
      lo_ref_cmp_usage            TYPE REF TO if_wd_component_usage,
      lo_ref_interfacecontroller  TYPE REF TO iwci_salv_wd_table ,
      lo_value                    TYPE REF TO cl_salv_wd_config_table.

* Get reference to the Component usage of the ALV.
lo_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
IF lo_ref_cmp_usage->has_active_component( ) IS INITIAL.
  lo_ref_cmp_usage->create_component( ).
ENDIF.

* Get reference to the Interface controller of the ALV.
lo_ref_interfacecontroller =   wd_this->wd_cpifc_alv( ).
lo_value = lo_ref_interfacecontroller->get_model( ).
wd_this->m_alv_model = lo_value.

* Get the Columns of the ALV
CALL METHOD lo_value->if_salv_wd_column_settings~get_columns
  RECEIVING
    value = lt_columns.

* Get reference to each column and set the column heading.
LOOP AT lt_columns INTO ls_column.
  lo_column = ls_column-r_column.

  CASE ls_column-id.

    WHEN 'VARIANCE'.
      lo_col_head = lo_column->get_header( ) .
      lo_col_head->set_ddic_binding_field(  ).
      DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
      CREATE OBJECT lr_input_field
        EXPORTING
          value_fieldname = 'VARIANCE'.
      lo_column->set_cell_editor( lr_input_field ).
      lo_column->set_cell_design_fieldname( value = 'CELL_COLOR' ).

    WHEN 'CELL_COLOR'.
      CALL METHOD lo_column->set_visible(
        EXPORTING
          value = '00'
                  ).

  ENDCASE.
ENDLOOP.

Step-3: While populating the data into the Context which is bound to the ALV - Do the following based on the content of "VARIANCE" Field to set its colour accordingly -

Error rendering macro 'code': Invalid value specified for parameter 'lang'
* VARIANCE
ls_final-variance     = ls_final-current_amount - ls_final-ses_forecast.
IF ls_final-variance < 0.
  ls_final-cell_color = cl_wd_table_column=>e_cell_design-badvalue_dark.
ELSE.
  ls_final-cell_color = cl_wd_table_column=>e_cell_design-standard.
ENDIF.

4 Comments

  1. This is very useful one. Thank you for sharing this.

  2. Former Member

    Hi,

    I found that the cell color doesn't run if you set design alternating: 
     CALL METHOD lo_value->if_salv_wd_table_settings~set_design
        EXPORTING
          value  = CL_WD_TABLE=>E_DESIGN-ALTERNATING . 

     we can change cell color only for table design

    •  STANDARD 
    • TRANSPARENT 
    • TRANSPARENT_WITH_GRID

    Enjoy

  3. Former Member

    It would be very help full if you also explains how you are binding the value (color Value) to attribute. i am facing a issue .. possible can you please provide step by step approach.. mail me Kranthi.palle@aricent.com

  4. Guest

    You can refer this link for easy steps for colouring column in Web dynpro ALV table

    http://theabap.blogspot.in/2012/03/coloring-particular-column-of-alv-table.html