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

/wp-content/uploads/2014/09/add_node_543707.png

/wp-content/uploads/2014/09/select_node_attribute_543708.png

/wp-content/uploads/2014/09/context_543709.png

In the Layout tab, add the dropdownbykey and link it to the connid in the context. As shown in the picture.

Layout.png

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.

/wp-content/uploads/2014/09/modifyview_543717.png

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.

first test.png

/wp-content/uploads/2014/09/test2_543729.png

Thanks for reading.

To report this post you need to login first.

8 Comments

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

  1. 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… 🙂

    (0) 
    1. Preethi Natarajan Post author

      Hi,

      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..

      Thanks,

      Preethi

      (0) 

Leave a Reply