Skip to Content
Author's profile photo Preethi Natarajan

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.
     l_value-value = lst_sflight-carrid.
     l_value-text = lst_sflight-connid.
     INSERT l_value INTO TABLE lt_valueset.
     name = 'CONNID'
     value_set = lt_valueset ).
       name =  `CONNID`
       value = lv_connid ).

Activate the code and create a webdynpro application for it. Test the application.

first test.png


Thanks for reading.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo VASANTHAKUMAR PALANISAMY

      Nice Blog.

      Author's profile photo Preethi Natarajan
      Preethi Natarajan
      Blog Post Author

      Thank you Vasanth

      Author's profile photo Saifulla Mohammed
      Saifulla Mohammed

      Great...!! 😀

      Author's profile photo Preethi Natarajan
      Preethi Natarajan
      Blog Post Author

      Thank you Saif

      Author's profile photo Tudor Riscutia
      Tudor Riscutia

      It's a very easy solution. WD provides these kinds of possibilities more intuitively than old Dynpros.

      Yet in this case, wouldn't have been easier to just check the "Suggest Values" property of the UI element? Because CONNID has a a value table behind the domain... 🙂

      Author's profile photo Preethi Natarajan
      Preethi Natarajan
      Blog Post Author


      Yes the "inputPrompt" will help...Here I have used Sflight as an example..I am actually working on some other customizing table..that doesn't have domains linked to value tables..



      Author's profile photo Kumarak Kannan Thiagarajan
      Kumarak Kannan Thiagarajan

      Informative and useful!

      Author's profile photo Preethi Natarajan
      Preethi Natarajan
      Blog Post Author

      Thank you Kannan 🙂