cancel
Showing results for 
Search instead for 
Did you mean: 

Cell color change in ALV

Former Member
0 Kudos

Hi Experts,

I have written following piece of code to change the color of a cell based on condition, but some how its not working. I have define m_alv_model in attribute of the view type ref to CL_SALV_WD_CONFIG_TABLE. My ALV is working fine, but cell colors are not getting changed. Pls suggest.

* 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 -

* 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.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi ,

Please check this code i have used this to show a icons accoring to the values tat iam getting from the bapi.

create object lr_image.

lr_image->set_source_fieldname( 'RISK_CRITICALITY' ).

lr_column->set_cell_editor( lr_image ).

loop at lt_projhealth assigning <fs_risk>.

if <fs_risk>-criticality_desc eq 'VERY HIGH'.

<fs_risk>-risk_criticality = 'ICON_STATUS_CRITICAL'.

elseif <fs_risk>-criticality_desc eq 'HIGH'.

<fs_risk>-risk_criticality = 'ICON_STATUS_ALERT'.

elseif <fs_risk>-criticality_desc eq 'MODERATE'.

<fs_risk>-risk_criticality = 'ICON_LED_YELLOW'.

elseif <fs_risk>-criticality_desc eq 'LOW'.

<fs_risk>-risk_criticality = 'ICON_STATUS_BEST'.

elseif <fs_risk>-criticality_desc eq 'VERY LOW'.

<fs_risk>-risk_criticality = 'ICON_LED_GREEN'.

endif.

Regards,

Muneesh Gitta.

Former Member
0 Kudos

Ok, Icons works fine, but with this code i'm not able to see my ALV editable and also my cell colors is not gettings changed. Could you please see the code and find out whats wrong in it. I have debugged it, it looks fine...pls suggest.

Former Member
0 Kudos

Editable is working now, the missing part was

data: lr_table_settings type ref to if_salv_wd_table_settings.
  lr_table_settings ?= lo_value.
  lr_table_settings->set_read_only( ABAP_FALSE ).

But cell is still not colored.

Former Member
0 Kudos

Hi

For adding the icon to the custom button use this piece of code

data : lr_buttonui type ref to cl_salv_wd_fe_button.
data : button type ref to cl_salv_wd_function.
create object lr_buttonui.
lr_buttonui->set_text( 'SAVE' ).
lr_buttonui->set_image_source( 'ICON_SYSTEM_SAVE' ).
BUTTON = L_VALUE->IF_SALV_WD_FUNCTION_SETTINGS~CREATE_FUNCTION( ID = 'SAVE' ).
BUTTON->SET_EDITOR( LR_BUTTONUI ).

Regards

Tamil

Edited by: Tamilselvan K on Jul 25, 2008 6:30 AM

udo_toenges
Member
0 Kudos

Hi,

for me a similar coding works, as long as I'm using not using the alternating table design.

Did you already check it using the standard table design?

Regards,

Udo

Former Member
0 Kudos

I m not changing table design in this code...

A couple of questions...

1- How to add icon to a custom button on ALV toolbar.

2- If we have icon_name e.g 'ICON_SAVE', how to find out the icon code like '@4B@'

Thanks,

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> 2- If we have icon_name e.g 'ICON_SAVE', how to find out the icon code like '@4B@'

>

> Thanks,

Although you should always try to use the Icon Name, you can find the cross reference to old Icon Codes in the type group ICON.