Setting Default Value For DropDownByKey
I am currently working on a requirement where I have to add a DropDownbyKey to the webdynpro Layout and have it display a set of values along with one default value to be set up on loading the application. The requirement is straight forward but to get it to work I have involved most of my team members and all of us hit the same roadblocks and searched and thought out of the box and tried various things; I feel that there should be a single place where the whole scenario should exist and hence decided on writing this.
Lets create a standalone application with this dropdownbykey as the only field. Create a webdynpro application; I have named it as Z_DROP_DOWN_BY_KEY.
In the MAIN View, choose the Context, right click, add node, choose connid from sflight structure as shown in the pictures
In the Layout tab, add the dropdownbykey and link it to the connid in the context. As shown in the picture.
Now comes the most important point. Add the code in WDDOMODIFYVIEW. We had the code in INIT and it wasn’t working as expected and hence we have come to the learning point that setting the default works in the ModifyView method.
Add this piece of code in ModifyView
METHOD wddomodifyview . DATA: lo_nd_sflight TYPE REF TO if_wd_context_node, lo_el_sflight TYPE REF TO if_wd_context_element, ls_sflight TYPE wd_this->element_sflight, lv_connid TYPE wd_this->element_sflight-connid, node_info TYPE REF TO if_wd_context_node_info, lt_sflight TYPE STANDARD TABLE OF sflight, lst_sflight LIKE LINE OF lt_sflight, lt_valueset TYPE wdr_context_attr_value_list, l_value TYPE wdr_context_attr_value. lo_nd_sflight = wd_context->get_child_node( name = wd_this->wdctx_sflight ). lo_el_sflight = lo_nd_sflight->get_element( ). node_info = lo_nd_sflight->get_node_info( ). SELECT * FROM sflight INTO TABLE lt_sflight. LOOP AT lt_sflight INTO lst_sflight. IF sy-tabix = 1. lv_connid = lst_sflight-connid. ENDIF. l_value-value = lst_sflight-carrid. l_value-text = lst_sflight-connid. INSERT l_value INTO TABLE lt_valueset. ENDLOOP. node_info->set_attribute_value_set( name = 'CONNID' value_set = lt_valueset ). lo_el_sflight->set_attribute( name = `CONNID` value = lv_connid ). ENDMETHOD.
Activate the code and create a webdynpro application for it. Test the application.
Thanks for reading.