cancel
Showing results for 
Search instead for 
Did you mean: 

How to display different icon within WDA alv table base on row data ?

Former Member
0 Kudos

Hi,

is that possible to display different icon for every row within ALV table depending on the row data ?

for instance if the status 'S' display ~Icon/SuccessMessage and 'E' display ~Icon/ErrorMessage ?

because base on this code below i only can set 1 icon for the whole row data.


LOOP AT lt_columns ASSIGNING <fs_column>.
    CASE <fs_column>-id.
      WHEN 'ICO'.
        CREATE OBJECT lr_caption.
           lr_caption->set_image_source( value = '~Icon/SuccessMessage').
           <fs_column>-r_column->set_cell_editor( lr_caption ).
    ENDCASE.
  ENDLOOP.

Thank you in advance.

Fernand

Accepted Solutions (0)

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Hi Fernand,

There are a series of excellent articles by Claudia Dangers available over ALV within SDN. Please try to search around before you post a question in here. This would even help save you lot of time before you get a solution. As an example see this [article |https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1190424a-0801-0010-84b5-ef03fd2d33d9]wherein Claudia explains as to how you can conditionally set different traffic lights within an ALV.

Regards,

Uday

Former Member
0 Kudos

Thank you Uday for your information.

Regards

Fernand

Former Member
0 Kudos

Hello,

Yes it is possible to display different images based on data.

For that what you can do is create one attribute 'STATUS' of type string in context node which you are mapping to ALV.

And fill that attribute with the path to image based on your requirement like for status 'S' set the attribute to ~Icon/SuccessMessage and if status is 'E', set it to ~Icon/ErrorMessage at runtime.

Now in the settings for ALV use the following code:

* Display icon in column seatsocc
  DATA: lr_column TYPE REF TO cl_salv_wd_column,
        lr_image TYPE REF TO cl_salv_wd_uie_image,
        lv_icon TYPE string.
  lr_column = lv_model->if_salv_wd_column_settings~get_column( 'SEATSOCC' ).
  CREATE OBJECT lr_image.
  lr_image->SET_SOURCE_FIELDNAME( 'STATUS' ).
  lr_column->set_cell_editor( lr_image ).

in the above code, column 'SEATSOCC' will be displayed as an icon.

Sample code to fill the attribute 'STATUS'

LOOP AT lt_flights INTO ls_flight.
    lv_seatsfree = ls_flight-seatsmax - ls_flight-seatsocc.

    IF lv_seatsfree = 0.
      ls_flight-status = 'ICON_RED_LIGHT'.
    ELSEIF lv_seatsfree <= 50.
      ls_flight-status = 'ICON_YELLOW_LIGHT'.
    ELSE.
      ls_flight-status = 'ICON_GREEN_LIGHT'.
    ENDIF.

    MODIFY lt_flights FROM ls_flight.
  ENDLOOP.

Hope this helps!

Regards,

Srilatha

Edited by: Srilatha M on Jun 25, 2010 12:02 PM

Former Member
0 Kudos

Hi Fernanda ., in do init method you have to set the coloum to the cell editor type cl_salv_wd_uie_image

In wddoinit Method

data: lr_column_settings type ref to if_salv_wd_column_settings.
  data: lr_column type ref to cl_salv_wd_column.
*... define new cell editor image for column field1
  lr_column = lr_column_settings->get_column( 'FIELD1' ). " in which coloum you want to set the Icon or image 
  data:   lr_image type ref to cl_salv_wd_uie_image.

  create object lr_image.
  lr_image->set_source_fieldname( 'FIELD1' ).
  lr_column->set_cell_editor( lr_image ).

then while writing the data to the internal table

ls_stock-field1 = 'ICON_RED_LIGHT'.   
ls_stock-field2 = 'Stock empty'.                         
ls_stock-field3 = 'Pullover'.

 append ls_stock to lt_stock.


ls_stock-field1 = 'ICON_YELLOW_LIGHT.   
ls_stock-field2 = 'Stock medium'.                         
ls_stock-field3 = 'lover'.

 append ls_stock to lt_stock.

Regards

Chinnaiya P

Former Member
0 Kudos

Hi Chinnaiya.

Thank You very Much. It has solved my problem.

Best Regards.

Fernand