cancel
Showing results for 
Search instead for 
Did you mean: 

How to create DropDown with Key and Text

Former Member
0 Kudos

Hi at all,

I can create a drop down based on a key field in a context node.

How can I create a drop down field based on a key field and additional the text corresponding to the key?

I have a context node with cardinality 0...n containing the key field and a describing text field.

The key fields are shown at activating the drop down button, but not the describing text.

Thx for all answers.

Dirk

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you can use Drop Down by Index in your case to get the text in the list box.

Former Member
0 Kudos

Hi,

thanks for your very quick answer.

I can bind the property "Texts" to the context field containing the description but this shows only the description in the list and the selected value.

I want to see the key and description in table form in the list and only the key should be displayed as selected value.

Thanks for answers.

Dirk

Former Member
0 Kudos

>

> Hi,

>

> thanks for your very quick answer.

>

> I can bind the property "Texts" to the context field containing the description but this shows only the description in the list and the selected value.

>

> I want to see the key and description in table form in the list and only the key should be displayed as selected value.

>

> Thanks for answers.

>

>

> Dirk

Hi,

i think then the possible solution would be value help. I am afraid that you cannot have the two columns in your DDBK or DDBI.

gill367
Active Contributor
0 Kudos

Or second method will be using DDBI only where you need to change the value of text attribute to text + key by iterating over

all the elements of the node and then binding the text to TEXTs property of the DDBI

thanks

Sarbjeet SIngh

Former Member
0 Kudos

Nearly perfect Sarbjeet,

I implemented the coding like this:

DATA: lo_nd_dropdown_fakiv  TYPE REF TO if_wd_context_node,
        lo_el_dropdown_fakiv  TYPE REF TO if_wd_context_element,
        lt_dropdown_fakiv     TYPE TABLE OF wd_this->element_dropdown_fakiv,
        ls_dropdown_fakiv     LIKE LINE OF lt_dropdown_fakiv.

  DATA: lo_nd_dealer TYPE REF TO if_wd_context_node,
        lt_valueset TYPE TABLE OF wdr_context_attr_value,
        ls_valueset TYPE wdr_context_attr_value,
        lr_node_info TYPE REF TO if_wd_context_node_info.

  lo_nd_dropdown_fakiv = wd_context->get_child_node( name = wd_this->wdctx_dropdown_fakiv ).

  SELECT domvalue_l ddtext
    FROM dd07t
    INTO TABLE lt_dropdown_fakiv
    WHERE domname = '/GICOM/FAKIV'
      AND ddlanguage = sy-langu.

  IF sy-subrc = 0.
    lo_nd_dropdown_fakiv->bind_table(
      EXPORTING
        new_items            = lt_dropdown_fakiv
        ).
  ENDIF.

  lo_nd_dealer = wd_context->get_child_node( name = wd_this->wdctx_dropdown_fakiv ).

  lr_node_info = lo_nd_dealer->get_node_info( ).

  LOOP AT lt_dropdown_fakiv INTO ls_dropdown_fakiv.
    ls_valueset-value = ls_dropdown_fakiv-domvalue_l.
    CONCATENATE ls_dropdown_fakiv-domvalue_l ls_dropdown_fakiv-ddtext INTO ls_valueset-text SEPARATED BY space.
    APPEND ls_valueset TO lt_valueset.
  ENDLOOP.

  lr_node_info->set_attribute_value_set(
    EXPORTING
      name = 'DOMVALUE_L'
      value_set = lt_valueset
      ).

When I start the application the list of the drop down shows "key + value" but when I choose an entry "key + value" is selected. Is it possible to display only the key as the choosen entry?

gill367
Active Contributor
0 Kudos

I am not getting the requirement here,

Are you saying you will select something in the dropdown and dynamically at the runtime that entry should change its

displayed form to key only..

means we have dropwon as A alpha

B Beta

C gamma

Now if you select B beta in the dropdown then it should change to B menas then dropdown will be like

A Alpha

B <<<<------ Selected

C Gamma

is it this what you are asking.

It is quite a task to achieve ........

for this i think you have to use dropdown by index.

there do one thing

your node will have text and value attribute separte ..

then iterate throught the elements of the node and change the values of text to text + value

and then change the value of text attribute to text = value for the current element on the onselect action event handler of the

dropdown by index.

Thanks

Sarbjeet

Former Member
0 Kudos

Perfect. Solved!

Answers (1)

Answers (1)

gill367
Active Contributor
0 Kudos

in that case you can use value set..

loop at the context node for all the element of the desired node and create a valueset for one attribute which you can use in

dropdown by key for the property selected key.

there in teh key wirte the simple key and for text write key + text.

DATA lo_nd_dealer TYPE REF TO if_wd_context_node.
lo_nd_dealer = wd_context->get_child_node( name = wd_this->wdctx_dealer ).
  Data : lt_valueset type table of wdr_context_attr_value,
         ls_valueset type wdr_context_attr_value,
         lr_node_info type ref to if_wd_context_node_info,
         wa_dealr type zdealer.
 
 lr_node_info = lo_nd_dealer->get_node_info( ).
 
 Do 5 times.                                                 "here you can itereate for fetching all the elemets of the node 
   ls_valueset-value = sy-index.                   " and set the value of key and text
   ls_valueset-text = sy-index.
   append ls_valueset to lt_valueset.
   enddo.
 
   lr_node_info->set_attribute_value_set(
   name = 'NAME'
   value_set = lt_valueset ).

Thanks

Sarbjeet