Dynamic Dropdowns – Flight Routes

All Flight Routes webdynpro search dropdowns controls are dynamically populated at runtime based on some inner joins on table data. One may expect dropdown values contain direct data binding from inner tables just like it’s the case for webdynpro tables but this is not the case.

A dropdown control contains data binding to a node attribute that can contain just one value at any given point in time. So how are the dropdown values generated when data binding points to just one element? There are two scenarios here:

  • Data bound attribute is a ddic type referring to a domain containing a set of predefined possible values. In this case the dropdown options get generated automatically by webdynpro.
  • Data bound attribute is of generic type, like string and we have to manually generate the options in component controller initialization method – WDDOINIT. This is the scenario worth discussing about.

We have a dropdownbykey control element and it’s data bound to a node attribute of type string. Obviously, this element of type string can’t possibly hold the dropdown values. It just holds the current selected element from the dropdown. To create the actual dropdown values, we need to access the node attribute value set. The value set holds the dropdown values and we can update it with a special type of inner table – wdy_key_value_table. A work area / one row of this table is of type wdy_key_value and has two properties: value and key.

Data declarations can be something like this:
ctx_node_search_opt type ref to if_wd_context_node,
wd_node_info type ref to if_wd_context_node_info,
ls_value type wdy_key_value,
lt_value_set type wdy_key_value_table

ctx_node_search_opt is our view context node holding the search options attributes, these attributes are data bound to the dynamically populated search dropdowns. wd_node_info contains metadata for a given node, including everything related to its attributes.

Assuming we already have the data (key and value sets) we need to add to a dropdown, we start by creating the wdy_key_value_table, most probably inside a loop.
ls_value-key = 'key'.
ls_value-value = 'value'.
append ls_value to lt_value_set.

We get a reference to the node we’re interested it, get its metadata, and update an attribute value set. The code below updates the values from the airline dropdown control.
ctx_node_search_opt = wd_context->get_child_node( name = 'SEARCH_OPTIONS' ).
wd_node_info = ctx_node_search_opt->get_node_info( ).
wd_node_info->set_attribute_value_set( name = 'CARRIER_OPT' value_set = lt_value_set ).

When you set the data bound attribute value to a new one, matching one of the above defined keys from ls_value-key, on the next WDDOMODIFYVIEW phase the dropdown will automatically show the new value as the selected option.

This post is part of Flight Routes.

Leave a Reply

Your email address will not be published. Required fields are marked *