cancel
Showing results for 
Search instead for 
Did you mean: 

set color alv output cell abap webdynpro

Former Member
0 Kudos

Hi Guys ,

i wanted to set the color of some cells in alv output to red in ABAP WebDynpro.

i am using the salv_wd_table.

any piece of code is appreciated.

thanks,

Bobby.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Bobby,

Follow below steps .

1)Create one context attribute namely "CELLDESIGN" of type WDUI_TABLE_CELL_DESIGN

2)For the particular column(i.e the column which you want to highlight with red color,set cell design field name as shown below

DATA lo_hdr   TYPE REF TO cl_salv_wd_column.

CALL METHOD lv_value->if_salv_wd_column_settings~get_column
    EXPORTING
      id    = '<your column name>'

    RECEIVING
      value =lo_hdr.

lo_hdr->set_cell_design_fieldname( 'CELLDESIGN' ).

3)While binding data to your ALV table, set the cell design value to 64( 64 = color_red).

For more reference you can browse this link Coloring the column cell – ALV

Thanks

KH

Former Member
0 Kudos

Keep a field CELLDESIGN in the Context node for ALV Data.

Populate '01' into this field wherever you need red color.

in the ALV Configuration.

1. Get all the columns by calling GET_COLUMNS Method.

2. LOOP on Columns and when the column name = 'REQUIRED_FIELD'.

    call method

    IF_SALV_WD_COLUMN_SETTINGS->SET_CELL_DESIGN_FIELDNAME( 'CELLDESIGN' ).

    ENDLOOP.

3.Hide the CELLDESIGN Column

   IF_SALV_WD_COLUMN_SETTINGS->DELETE_COLUMN( ID = 'CELLDESIGN' ).

Thanks,

Mahendra K.

Former Member
0 Kudos
tina_yang
Explorer
0 Kudos

Bobby,

If let's say you are build a ALV table to output 'SFLIGHT' table, and you want PLANETYPE '747-400' to be displayed in green, and PLANETYPE '146-200' displayed in red.

Also, let's just say, you already had a context node 'SFLIGHT_NODE' that is mapped to the external node 'DATA' of your ALV.

Now:

1. you need to modify the context node 'SFLIGHT_NODE' to add an attribute -- say 'CELL_COLOR' of type 'WDY_UIE_LIBRARY_ENUM_TYPE' -- to the SFLIGHT_NODE (note, you need to delete 'DICTIONARY structure' that is bind to the 'SFLIGHT_NODE' node, otherwise, you will not be able to create addition attributes)

After, you will have something like this for your context node .

CONTEXT

--> SFLIGHT_NODE

-


> CARRID

-


> CONNID

-


> FLDATE

-


> PRICE

-


> PLANETYPE

-


> <and any other attributes you had pulled from SFLIGHT)

-


> CELL_COLOR (TYPE WDY_UIE_LIBRARY_ENUM_TYPE)

2. In your supply function to the 'SFLIGHT_NODE', you now need to supply the data to this newly added attribute:

METHOD supply_sflight_node .
** data declaration
  DATA:
    itab_sflight_node            TYPE if_componentcontroller=>elements_sflight_node,
    stru_sflight_node            LIKE LINE OF itab_sflight_node.

** read sflight data
  SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE itab_sflight_node.

** populate the 'CELL_COLOR' field
  LOOP AT itab_sflight_node INTO stru_sflight_node .
    IF stru_sflight_node-planetype = '747-400'.
      stru_sflight_node-cell_color = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-GOODVALUE_DARK . 
     ELSEIF stru_sflight_node-planetype = '146-200'.
      stru_sflight_node-cell_color = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-BADVALUE_DARK .   
    ELSE.
      stru_sflight_node-cell_color = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-STANDARD .
    ENDIF.

    modify itab_sflight_node from stru_sflight_node.
  ENDLOOP.

** bind all the elements
  node->bind_table(
    new_items =  itab_sflight_node
    set_initial_elements = abap_true ).
ENDMETHOD. 

3. Now, you need to obtain the configuration model of the ALV and config it before display. (say you have an method does this 'init_alv_table_settings', and it is called from your view's wddoinit() method)

METHOD init_alv_table_settings .
  DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.

  l_ref_cmp_usage =   wd_this->wd_cpuse_alv_table( ).
  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.

  DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .
  l_ref_interfacecontroller =   wd_this->wd_cpifc_alv_table( ).

  DATA:
  node_sflight_node                   TYPE REF TO if_wd_context_node .
  node_sflight_node = wd_context->get_child_node( name = if_flights_view=>wdctx_sflight_node ).

  CALL METHOD l_ref_interfacecontroller->set_data
    EXPORTING
      r_node_data = node_sflight_node.


**  get ConfigurationModel from ALV Component
  DATA:    lr_table TYPE REF TO cl_salv_wd_config_table.
  lr_table = l_ref_interfacecontroller->get_model( ).

** change the color of the cell
  DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings.
  DATA: lr_column TYPE REF TO cl_salv_wd_column.

  lr_column_settings ?= lr_table.
  lr_column = lr_column_settings->get_column( 'PLANETYPE' ).


  DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
  CREATE OBJECT lr_input_field EXPORTING value_fieldname = 'PLANETYPE'.
  lr_column->set_cell_editor( lr_input_field ).
  lr_column->set_cell_design_fieldname( value = 'CELL_COLOR' ).
ENDMETHOD.

Compile and activate your code.

Regards,

Tina Yang

Message was edited by: Tina Yang

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Tina,

Although this is a very old thread: I have searched the web for this quite some time. Your explanation is one of the very very few that clarify the topic. Thanks a lot!

Markus