Using drop down by key in webdynpro ABAP


Working with Drop Down by Key in Web Dynpro for ABAP to display drop down list using domain fixed values.


Drop Down by Index in Web Dynpro ABAP

Step1: Go to SE80, create a web dynpro component ZSAPN_DDK.

Drop Down by Index in Web Dynpro ABAP

A popup will come provide some description and enter, save in a local object.

Drop Down by Index in Web Dynpro ABAP

Step2: Double click on main menu, click on change, go to context tab, right click on context, create->node.

Drop Down by Index in Web Dynpro ABAP

A popup will come provide name as DDK, cardinality (1 – 1) and enter.

Drop Down by Index in Web Dynpro ABAP

Step3: Right click on node DDK, create->attribute, provide name as GENDER -> TYPE -> GENDER and enter.

Drop Down by Index in Web Dynpro ABAP

Drop Down by Index in Web Dynpro ABAP

Similarly create another attribute SELECTED -> TYPE -> CHAR30.

Drop Down by Index in Web Dynpro ABAP

Step4: Go to layout tab, right click on ROOTUIELEMENTCONTAINER -> Insert element.

Drop Down by Index in Web Dynpro ABAP

A popup will come, provide id: DDK, type: DropDownByKey and enter.

Drop Down by Index in Web Dynpro ABAP

Create binding by clicking on bind icon.

Drop Down by Index in Web Dynpro ABAP

A popup will come, select GENDER and enter.

Drop Down by Index in Web Dynpro ABAP

Similarly right click on ROOTUIELEMENTCONTAINER, insert element id: Test, type: TextView and enter.

Drop Down by Index in Web Dynpro ABAP

A popup will come select ‘SELECTED’, enter.

Drop Down by Index in Web Dynpro ABAP

Select DDK UI element, create action method.

Drop Down by Index in Web Dynpro ABAP

Step5: Go to actions tab, double click on ‘ON_SELECT’ method and add below code.

Drop Down by Index in Web Dynpro ABAP

  DATA LO_ND_DDK TYPE REF TO IF_WD_CONTEXT_NODE.
  DATA LO_EL_DDK TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_DDK TYPE WD_THIS->ELEMENT_DDK.
  DATA LV_GENDER TYPE WD_THIS->ELEMENT_DDK-GENDER.

*   navigate from  to  via lead selection
  LO_ND_DDK = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_DDK ).

*   @TODO handle non existant child
*   IF lo_nd_ddk IS INITIAL.
*   ENDIF.

*   get element via lead selection
  LO_EL_DDK = LO_ND_DDK->GET_ELEMENT( ).
*   @TODO handle not set lead selection
  IF LO_EL_DDK IS INITIAL.
  ENDIF.

*   get single attribute
  LO_EL_DDK->GET_ATTRIBUTE(
    EXPORTING
      NAME =  `GENDER`
    IMPORTING
      VALUE = LV_GENDER ). "get selected drop down
  DATA LV_TEXT TYPE WD_THIS->ELEMENT_DDK-SELECTED.
  IF LV_GENDER = 'M'.
    LV_TEXT = 'Male Selected'.
  ELSEIF LV_GENDER = 'F'.
    LV_TEXT = 'Female selected'.
  ELSEIF LV_GENDER = 'N'.
    LV_TEXT = 'Neutral selected'.
  ENDIF.
*   get single attribute
  LO_EL_DDK->SET_ATTRIBUTE(
    EXPORTING
      NAME =  `SELECTED`
      VALUE = LV_TEXT ). "set text

Step6: Save, activate the component, create application and test.


Learner Questions

No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question


    Was this lesson helpful to you? Yes No 16 People out of 19 think this lesson helpful

    Lesson Navigation

    ←Previous Chapter
    Next Chapter →