Showing results for 
Search instead for 
Did you mean: 

Dynamic filtering of domain values for a DropdownByKey

0 Kudos

Hi all gurus,

a trivial question probably for many of you, but I'm a bit lost on the task. We have a custom field at position level on an SRM document which has its own domain populated with 5 fixed values (say A,B,C,D and E).

Shortly, we'd like to filter these values on the basis of criteria which is known only @ runtime.

To make an simple example, consider that a document which refers to a specific company should have only A and E as possible values for the custom field.

To further complicate the problem, consider that this custom field is retrieved dynamically in the WDDOMODIFYVIEW method of the view that shows item's detail, so it's not a static entry under the CONTEXT node of the view itself; it's just added dinamically.

By now I was able to obtain the istance type of that custom field, which leads to the use of the methods from DropdownByKey class:

* Retrieve dynamically the istance type and associate an action/method

         lr_class_descr ?= cl_abap_typedescr=>describe_by_object_ref( lo_ui_element_attr ).

         field_type = lr_class_descr->get_relative_name( ).

         case field_type.



           lo_wd_dropdown_by_key ?= lo_ui_element_attr.

           lo_wd_dropdown_by_key->SET_ON_SELECT( 'REFRESH' ). /this was added to refresh the view on selection

Given that I've got the elements to build a filter condition, how can I:

- retrieve the values from this dropdownbyKey element;

- re-assign the filtered list to the dropdownbyKey element?

Thanks anyone for your kind help

View Entire Topic
0 Kudos

Hi Matteo,

I didn't try it, but theoretically it should work.

Maybe you want to try it.

Idea is to create an attribute with a filtered value set during runtime and bind it to your DropDownByKey.



data lt_all_vals type table of DD07V. "All domain values
data ls_all_vals type DD07V.
data lt_filt_vals type WDR_CONTEXT_ATTR_VALUE_LIST. "filtered values
data ls_filt_vals type WDR_CONTEXT_ATTR_VALUE.
data lv_rc like sy-subrc.

">>>>Populate list with values for your DropDownByKey

  "Get all domain values (if you need them)
     DOMNAME              = 'YOUR DOMAIN NAME'  "Add your domain name
    TEXT                 = 'X'
    LANGU                = sy-langu
*   BYPASS_BUFFER        = ' '
    RC                   = lv_rc
    DD07V_TAB            = lt_all_vals.

"Filter Values:
loop at lt_all_vals into ls_all_vals.

   if <.........>. " Add your filter criteria to add the values you want to see.
     ls_filt_vals-values = ls_all_vals-DOMVALUE_L.
     ls_filt_vals-text = ls_all_vals-DDTEXT.
     append ls_filt_vals to lt_filt_vals.

"<<<<Populate list with values for your DropDownByKey

">>>> create attribute to be bound to selectedKey-property of your DropDownByKey
data: lr_node_info type ref to IF_WD_CONTEXT_NODE_INFO.
DATA: ls_attribute TYPE wdr_context_attribute_info.

lr_node_info = WD_CONTEXT->GET_NODE_INFO( ).

ls_attribute-name = 'ANYUNIQUENAME'.
ls_attribute-type_name = 'YOUR TYPE'. "
ls_attribute-value_help_mode = '0'."Automatisch
ls_attribute-value_set = lt_filt_vals.

"Add attribute to context:
if lr_node_info->HAS_ATTRIBUTE( 'ANYUNIQUENAME' ).
   attribute_info = ls_attribute ).

"bind attribute to your uielement:

Hope this helps. Keep me informed.



0 Kudos

I did something very similar to what ismail suggested, specifically I get the domain values, filter them on basis of my criteria then re-bind to the existing node. Thanks!