Skip to Content

I searched a while before I found some helpful threads in the SDN forum concerning this topic, which finally lead me to my solution. That’s why I thought myself why not publish the information consolidated in a blog. And here it is!!!

My blog starts where the blog from Thomas Jung WebDynpro ABAP: ALV ends, so you can just rebuild his example and then proceed here.

After the WDA component, window, view, ALV and the necessary references are created; you need to change the WDDOMODIFYVIEW in order to get the dropdowns into your ALV. In this example the column Planetype will be changed to dropdown fields.

 

Declare Data

First; the data declaration and the references needs to inserted.

 

Disable Write Protection of ALV

To be able to change the type of cells to editable fields like dropdowns, input fields, check boxes etc. it is mandatory to disable the write protection of the ALV. 

 

Prepare and bind value set for dropdown content 

To get values into the dropdown proceed like this:

  • Get all planetypes: Either by reading the context node sflight or by executing a SQL statement
  • Get a reference to the context node sflight
  • Prepare value set table for context element planetypes
  • Assign value set table to context element planetypes

 

Change cell editor to dropdown 

The last step is to assign change the type of the cell editor for column planetype to dropdown.

 

The result

Execute the WD Application and you can will have a dropdown in your ALV!!! 

image 

  

Saving the changes in ALV

How to save the changed values is described in the paper of Claudia Dangers Editing ALV in Web Dynpro for ABAP which is very comprehensive and helpful. 

The complete code of wddomodifyview

METHOD wddomodifyview .

DATA: lr_config TYPE REF TO cl_salv_wd_config_table,
lr_column TYPE REF TO cl_salv_wd_column,
lr_comp_if_alv TYPE REF TO iwci_salv_wd_table,
lo_cmp_usage TYPE REF TO if_wd_component_usage,
lr_dropdown_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key,
lt_columns TYPE salv_wd_t_column_ref,
lr_column_settings type ref to if_salv_wd_column_settings,
lr_node_info TYPE REF TO if_wd_context_node_info,
lr_node TYPE REF TO if_wd_context_node,
wa_value_set TYPE wdr_context_attr_value,
lt_value_set TYPE TABLE OF wdr_context_attr_value,
lv_planetype TYPE sflight-planetype,
lt_planetype TYPE STANDARD TABLE OF sflight-planetype.
FIELD-SYMBOLS LIKE LINE OF lt_columns.

* Get ALV Component
lo_cmp_usage = wd_this->wd_cpuse_alv( ).
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.

* Get References for ALV
lr_comp_if_alv = wd_this->wd_cpifc_alv( ). ” get component
lr_config = lr_comp_if_alv->get_model( ). ” get cofig model
lr_column_settings ?= lr_config. ” get column settings

* ALV – Disable Write Protection
lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).

* Read all Planetypes into iTab lt_planetypes
SELECT DISTINCT planetype FROM sflight INTO lv_planetype.
APPEND lv_planetype TO lt_planetype.
ENDSELECT.

* Get Context Node
lr_node = wd_context->get_child_node( name = ‘SFLIGHT’ ).
lr_node_info = lr_node->get_node_info( ).

* Insert Planetypes to value set of sflight-planteype
LOOP AT lt_planetype INTO lv_planetype.
wa_value_set-value = lv_planetype. ” key to be saved
wa_value_set-text = lv_planetype. ” text to be dispalyed
INSERT wa_value_set INTO TABLE lt_value_set.
ENDLOOP.

* Optional: Add values manual
wa_value_set-value = ‘200’.
wa_value_set-text = ‘Other planetype from me’.
INSERT wa_value_set INTO TABLE lt_value_set.

* Set attribute info for planetype
lr_node_info->set_attribute_value_set( name = ‘PLANETYPE’
value_set = lt_value_set ).

* Find the desired column and assign the dropdown
* Insetad of looping through all coumns, you can also use the following
* statement to get the col reference:
* lr_column = lr_column_settings->get_column( ‘PLANETYPE’ ).

lt_columns = lr_column_settings->get_columns( ).
LOOP AT lt_columns ASSIGNING .
IF -id = ‘PLANETYPE’.
CREATE OBJECT lr_dropdown_key
EXPORTING
selected_key_fieldname = ‘PLANETYPE’.

-r_column->set_cell_editor( lr_dropdown_key ).
ENDIF.
ENDLOOP.

ENDMETHOD.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply