Skip to Content
author's profile photo Former Member
Former Member

Cell color change in ALV

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.

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 24, 2008 at 05:27 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 25, 2008 at 04:30 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 25, 2008 at 05:46 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.