cancel
Showing results for 
Search instead for 
Did you mean: 

Questions/Problems with DropDownByKey (Class cl_wd_dropdown_by_key)

Former Member
0 Kudos

Hi everybody,

can anyone provide me with some sample code how to create a DropDownByKey-List?

I don´t get it how to bind the values to the DropDown-List ...

I know that I have to create a node and an attribute, set the attributes and then

create the DropDown-List.

But I can´t find some code where all this is explained ...

I hope someone can help me,

Regards

Christian

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Christian,

You dont have to go for the dynamic dropdown creation and all that unless really required. You should only go for that dynamic ui manipulation only when you cannot design the same at design time. I will explain you below the procedure for using DropDownByKey in your component.

I have 1 context node by name INPUT. Below are its properties:

Cardinality: 1..1

Selection: 0..1

Initialization Lead Selection: The box is checked (You get the error message in your component coz this isnt set)

Singleton: The box is checked

Now I have 2 attributes CARRID & CONNID under this node of the types SFLIGHT-CARRID & SFLIGHT-CONNID.

Now within my WDDOINIT method I fill my 2 dropdowns with values like shown below:

data: wd_node type ref to if_wd_context_node,
        wd_node_info type ref to if_wd_context_node_info,

** Internal table & workareas to hold possible values for carrid & connid
        lt_carrid_values type standard table of wd_this->element_input-carrid,
        lt_connid_values type standard table of wd_this->element_input-connid,
        wa_carrid type wd_this->element_input-carrid,
        wa_connid type wd_this->element_input-connid,

** Internal table & workareas to hold name & value pairs
        wa_carrid_valueset type wdr_context_attr_value,
        wa_connid_valueset type wdr_context_attr_value,
        lt_carrid_valueset type standard table of wdr_context_attr_value,
        lt_connid_valueset type standard table of wdr_context_attr_value.

  wd_node = wd_context->get_child_node( name = 'INPUT' ).


  select distinct carrid from sflight into table lt_carrid_values.
  select distinct connid from sflight into table lt_connid_values.

  loop at lt_carrid_values into wa_carrid.
    wa_carrid_valueset-value = wa_carrid.
    wa_carrid_valueset-text  = wa_carrid.
    append wa_carrid_valueset to lt_carrid_valueset.
    clear wa_carrid_valueset.
  endloop.

  loop at lt_connid_values into wa_connid.
    wa_connid_valueset-value = wa_connid.
    wa_connid_valueset-text  = wa_connid.
    append wa_connid_valueset to lt_connid_valueset.
    clear wa_connid_valueset.
  endloop.


  wd_node_info = wd_node->get_node_info( ).

  wd_node_info->set_attribute_value_set( exporting name      = 'CARRID'
                                                   value_set = lt_carrid_valueset ).

  wd_node_info->set_attribute_value_set( exporting name      = 'CONNID'
                                                   value_set = lt_connid_valueset ).

The selectedKey property of my dropdowns are bound to the 2 attributes CARRID & CONNID under node INPUT.

Regards,

Uday

Answers (5)

Answers (5)

uday_gubbala2
Active Contributor
0 Kudos

Hi Christian,

As a reference you can try go through this [free sample version|http://www.sap-press.de/download/dateien/1079/sappress_web_dynpro_for_abap.pdf] of Ulli Hoffman's textbook Web Dynpro For ABAP. Go through section 3.3.1 "Using Dropdown Lists". Hope that this helps resolve your problem.

Regards,

Uday

Former Member
0 Kudos

Hello,

I still got some problems with this topic.

I will discribe what I have done:

1. I created a node named "DROPIT" and an attribute called "DROPDOWN".

The type of the attribute is WDR_CONTEXT_ATTR_VALUE

2. In WDDOINIT I got the following coding:

DATA: lr_dropdown_node TYPE REF TO if_wd_context_node,

lr_dropdown_node_info TYPE REF TO if_wd_context_node_info,

lr_element_info TYPE wdr_context_attribute_info,

lt_value_set TYPE TABLE OF wdr_context_attr_value,

ls_value_set TYPE wdr_context_attr_value.

lr_dropdown_node = wd_context->get_child_node( 'DROPIT' ).

lr_dropdown_node_info ?= lr_dropdown_node->get_node_info( ).

lr_element_info = lr_dropdown_node_info->get_attribute( name = 'DROPDOWN' ).

ls_value_set-value = '1'.

ls_value_set-text = 'Value 1'.

APPEND ls_value_set TO lt_value_set.

ls_value_set-value = '2'.

ls_value_set-text = 'Value 2'.

APPEND ls_value_set TO lt_value_set.

lr_dropdown_node_info->set_attribute_value_set( EXPORTING name = 'DROPDOWN'

value_set = lt_value_set ).

3.In WDDOMODIFYVIEW the following coding is implemented:

lr_drop_down = cl_wd_dropdown_by_key=>new_dropdown_by_key( id = field_id

bind_selected_key = 'DROPIT.DROPDOWN' ).

lr_label = cl_wd_label=>new_label( label_for = field_id

text = attributes_value ).

cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_drop_down ).

cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_label ).

lr_group->add_child( the_child = lr_label ).

lr_group->add_child( lr_drop_down ).

4. As a result, I get the following message:

"The lead selection has not been set. MAINVIEW"

The cardinality of the Node "DROPIT" is 0..n.

I have no idea, what this message means and how to solve it ...

Thanks for your help

Christian

Former Member
0 Kudos

Hi,

You can refer this code.

Here I am populating drop down by key with values as shown.

method WDDOINIT .

DATA : node_info TYPE REF TO if_wd_context_node_info,

value1 TYPE wdy_key_value,

set TYPE wdy_key_value_table,

k1 type string value 'M',

v1 type string value 'MAGO',

k2 type string value 'S',

v2 type string value 'Saurav'.

*

value1-key = k1.

value1-value = v1.

APPEND value1 to set.

value1-key = k2.

value1-value = v2.

APPEND value1 to set.

node_info = wd_context->get_node_info( ).

node_info = node_info->get_child_node('FOR_DROP').

node_info->set_attribute_value_set( name = 'DROP_KEY' value_set = set ).

Here DROP_KEY is context attribute which is binded to drop down by key UI Element.

FOR_DROP is context node.

Thanx.

Edited by: saurav mago on Mar 3, 2009 9:47 AM

arjun_thakur
Active Contributor
0 Kudos

Hi Christian

- Create a node with cardinality 0:n then create an attribute.

- Bind the attribute with the drop down by key UI element.

- Populate the value in the node. For that plz refer the code

 DATA: value TYPE wdy_key_value,
        value_set TYPE wdy_key_value_table.

  DATA: node_info          TYPE REF TO if_wd_context_node_info,
        litab_healthinform TYPE TABLE OF t578w.

  FIELD-SYMBOLS: <pin_f> TYPE t578w.

  CLEAR value_set.

  node_info = wd_context->get_node_info( ).
  node_info = node_info->get_child_node( `CN_TABLE` ).

select * from t578w into corresponding field of  litab_healthinform. "Write logic to get data from database


  APPEND INITIAL LINE TO litab_healthinform .
  LOOP AT litab_healthinform ASSIGNING <pin_f> .
    IF <pin_f>-sprsl EQ sy-langu AND
      <pin_f>-sbjkt EQ '08'.
      value-key = <pin_f>-wtfld.
      value-value = <pin_f>-stext.

      INSERT value INTO TABLE value_set.
    ENDIF.
  ENDLOOP.

  node_info->set_attribute_value_set( name = `ZBLDGROUP` value_set =
value_set ).

I hope it helps.

Regards

Arjun

abhimanyu_lagishetti7
Active Contributor
0 Kudos

you have to assign value list to the attribute using the code, put this in wddoinit

DATA: LR_node TYPE REF TO IF_WD_CONTEXT_NODE.

DATA: LR_INFO TYPE REF TO IF_WD_CONTEXT_NODE_INFO.

DATA: LT_VALUESET TYPE STANDARD TABLE OF WDR_CONTEXT_ATTR_VALUE.

DATA: LS_VALUESET TYPE WDR_CONTEXT_ATTR_VALUE.

LR_NODE = WD_CONTEXT->GET_CHILD_NODE(

<NODE NAME> ).

LR_INFO = LR_RRHDR->GET_NODE_INFO( ).

LS_VALUESET-VALUE = '1'.

LS_VALUESET-TEXT = 'FIRST VALUE'.

APPEND LS_VALUESET TO LT_VALUESET.

LS_VALUESET-VALUE = '2'.

LS_VALUESET-TEXT = 'SECOND VALUE'.

APPEND LS_VALUESET TO LT_VALUESET.

LR_INFO->SET_ATTRIBUTE_VALUE_SET( NAME = '<ATTRIBUTE NAME>'

VALUE_SET = LT_VALUESET ).

activate and run the application

Abhi