Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Setting cell color in ALV

Hi All

I would be greatful if someone could please help...

I am still attempting to get cells painted within a WDA ALV grid display.

I have tried to use the method stated in the WDA sap press book - but this method is for use with TABLE element and I am using a ViewContainerUIElement for my table. There are mentions of wonderful ways to color cells in a list display - but I cannot understand how this can be achieved. I currently have this working appart from the numeric numbers of the design being set into the relavant column cell.

If anyone could help that would be great...

Please see:

   LOOP AT lt_zdata INTO ls_zdata.

        lv_index = sy-tabix.

*       set column values
*       loop at row data and set colour attributes of individual cells
        LOOP AT lt_columns ASSIGNING <fs_column>.
          lr_col_header = <fs_column>-r_column->get_header( ).
          lr_col_header->set_ddic_binding_field( ).

          CREATE OBJECT lr_input_field EXPORTING value_fieldname = <fs_column>-id.
          lr_column = lr_column_settings->get_column( <fs_column>-id ).

*         for the date columns only...
          IF <fs_column>-id(4) = 'CELL'.

*           get and set column dates from select option user input
            READ TABLE lt_dates INTO ls_dates INDEX 1.
            IF lt_dates IS INITIAL.
              lr_col_header->set_text( 'Date' ).
              ls_dates-low = ls_dates-low + lv_incr_date.
              MOVE ls_dates-low+2(2) TO lv_for_col_date+6(2).   "Year
              MOVE ls_dates-low+4(2) TO lv_for_col_date+3(2).   "Month
              MOVE ls_dates-low+6(2) TO lv_for_col_date(2).     "Day
              MOVE lv_for_col_date   TO lv_col_date.
              lr_col_header->set_text( lv_col_date ).
              lv_incr_date = lv_incr_date + 7.

            LOOP AT lt_orgdata_dates INTO ls_orgdata_dates
              WHERE crew = ls_zdata-crew
                AND position = ls_zdata-position
                AND name = ls_zdata-person
                AND trip_arr >= ls_dates-low
                AND trip_dep <= ls_dates-low.

*             column heading settings
              lr_field = lr_table->if_salv_wd_field_settings~get_field( <fs_column>-id ).
              lr_field->if_salv_wd_sort~set_sort_allowed( abap_false ).

* trying to set cell variants ?@#??!!???
*              lr_cv = lr_column->set_key( ls_zdata-variance ).
*              lr_cv->set_editor( lr_input_field ).
*              lr_cv->set_cell_design( value = '01').
*              lr_column->add_cell_variant( lr_cv ).

* current method of seeting the cell colors... (but puts value in cell!)
              FIELD-SYMBOLS: <fs> TYPE data.
              lr_column->set_cell_design_fieldname( value = <fs_column>-id ).
              ASSIGN COMPONENT <fs_column>-id OF STRUCTURE ls_zdata TO <fs>.
              WRITE: CL_WD_TABLE_COLUMN=>e_cell_design-one TO <fs>.

              MODIFY lt_zdata FROM ls_zdata. " INDEX lv_index.



Kind Regards

Dave Alexander

Former Member
Former Member replied

Hi Dave,

It is not an issue,how many rows of columns you are assigning colors.

you can assign different colors to the same row of different columns.this is possible with my coding for this you need not use cell variant.

Cell variant is for in a single column if you want to show one cell with drop down another with text in this case you can use cell variant.

check this code some small changes to my previos code.

i have taken anothe attribute celldesign1 to set colors for other column.

loop at it_flights into ls_flights.

move-corresponding ls_flights to ls_final.

if ls_final-price = '185.00'.

ls_final-readonly = abap_true.

ls_final-celldesign =


ls_final-celldesign1 =



ls_final-readonly = ' '.

ls_final-celldesign =


ls_final-celldesign1 =



append ls_final to it_final.


*Give colors to cells

l_column1 = l_value->if_salv_wd_column_settings~get_column( 'CARRID' ).

l_column1->set_cell_design_fieldname( value = 'CELLDESIGN' ).

l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN' )


l_column2 = l_value->if_salv_wd_column_settings~get_column( 'CONNID' ).

l_column2->set_cell_design_fieldname( value = 'CELLDESIGN1' ).

l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN1' )


is this the solution you are looking.Please back to me if you have any issues.



0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question