Web Dynpro – Dynamic Drop Down Lists

Home / SAP / ABAP Coding / Web Dynpro – Dynamic Drop Down Lists

Now as promised, creating the dynamic drop down lists.  I mostly skipped these in my previous post just because there are some extra steps, and rather than cram everything together, it seemed like a good point to break it up.  Keep in mind, the concept is the same as my previous post, only for a dropdown list, you need to build the list as well.   (See my previous post for all of the other data declarations).

Hope you find this useful, and as always, if you have a better way to do it, please let  me know. J

DATA LV_BIND_DROP TYPE STRING.
*** check for dropdown fields
dyn_children = rootnode_info->get_child_nodes( ).
READ TABLE dyn_children with key name = field TRANSPORTING NO FIELDS.
CHECK sy-subrc <> 0.
* create sub node of structure (tablename)
* I created a tabletype/structure for DROPDOWNNODE.  If has fields of Key &

* value
cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
parent_info = rootnode_info
node_name = dyn_attr_info-name
structure_name = ‘DROPDOWNNODE’
is_multiple = abap_true ).
*** the On_enter is only if you want something to happen when a value

*** is selected.  I used it to set another context variable.
CONCATENATE LV_BIND ‘.VALUE’ INTO LV_BIND_DROP.
CALL METHOD cl_wd_dropdown_by_idx=>new_dropdown_by_idx
EXPORTING
bind_texts = lv_bind_drop
id         = lv_bind
state      = lv_state
on_Select  = ‘ON_ENTER’
RECEIVING
control    = lr_drop.

*** first, build up the list any way you want and put it into a table with

*** 2 columns, 1 key, 1 value
lo_nd_app->bind_table(
new_items            =  value_list
set_initial_elements = abap_true ).

*** if you want to specifically set a value for the dropdown in advance, here

*** just use this.  The tabix is for the value_list you populated.

lo_nd_app->set_lead_selection_index( sy-tabix ).

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

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