Working with Drop Down by Key in Web Dynpro for ABAP to display drop down list using domain fixed values.
Step1: Go to SE80, create a web dynpro component ZSAPN_DDK.
A popup will come provide some description and enter, save in a local object.
Step2: Double click on main menu, click on change, go to context tab, right click on context, create->node.
A popup will come provide name as DDK, cardinality (1 – 1) and enter.
Step3: Right click on node DDK, create->attribute, provide name as GENDER -> TYPE -> GENDER and enter.
Similarly create another attribute SELECTED -> TYPE -> CHAR30.
Step4: Go to layout tab, right click on ROOTUIELEMENTCONTAINER -> Insert element.
A popup will come, provide id: DDK, type: DropDownByKey and enter.
Create binding by clicking on bind icon.
A popup will come, select GENDER and enter.
Similarly right click on ROOTUIELEMENTCONTAINER, insert element id: Test, type: TextView and enter.
A popup will come select ‘SELECTED’, enter.
Select DDK UI element, create action method.
Step5: Go to actions tab, double click on ‘ON_SELECT’ method and add below code.
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.
Step1: Go to SE80, create a web dynpro component ZSAPN_DDK.
A popup will come provide some description and enter, save in a local object.
Step2: Double click on main menu, click on change, go to context tab, right click on context, create->node.
A popup will come provide name as DDK, cardinality (1 – 1) and enter.
Step3: Right click on node DDK, create->attribute, provide name as GENDER -> TYPE -> GENDER and enter.
Similarly create another attribute SELECTED -> TYPE -> CHAR30.
Step4: Go to layout tab, right click on ROOTUIELEMENTCONTAINER -> Insert element.
A popup will come, provide id: DDK, type: DropDownByKey and enter.
Create binding by clicking on bind icon.
A popup will come, select GENDER and enter.
Similarly right click on ROOTUIELEMENTCONTAINER, insert element id: Test, type: TextView and enter.
A popup will come select ‘SELECTED’, enter.
Select DDK UI element, create action method.
Step5: Go to actions tab, double click on ‘ON_SELECT’ method and add below code.
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.