Radio button by index in webdynpro ABAP

Working with radio button by index in web dynpro ABAP

+ -

RadioButtonByIndex: It is a Ui element, which creates radio button group with dynamic number of radio buttons.

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

Step2: Create context.

Go to main view, go to context , create a node RBG_INDEX with cardinality (0 - n), create two attributes MTART ->TYPE-> MARA-MATRT, TEXT -> TYPE -> CHAR30.

Step3:Design Layout.

Go to layout, create RadioButtonGroupByIndex UI element, bing text property to attribute MTART of node RBG_INDEX, create action method for ON_SELECT .

Create another UI element TextView, bind text property to attribute SELECTED of node RBG_INDEX.

Radio Button by Index

Step4: Go to action method and add below code.

 DATA LO_ND_RBG_INDEX TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA LT_RBG_INDEX TYPE WD_THIS->ELEMENTS_RBG_INDEX. "internal table
  DATA LS_RBG_INDEX TYPE wd_this->ELEMENT_RBG_INDEX. "work area

*   navigate from <context> to <rbg_index> via lead selection
  LO_ND_RBG_INDEX = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_RBG_INDEX ).

*   @TODO handle non existant child
*   IF lo_nd_RBG_INDEX IS INITIAL.
*   ENDIF.
**add radio buttons
  LS_RBG_INDEX-TEXT = 'Radio 1'.
  APPEND LS_RBG_INDEX TO LT_RBG_INDEX.
  CLEAR LS_RBG_INDEX.
  LS_RBG_INDEX-TEXT = 'Radio 12'.
  APPEND LS_RBG_INDEX TO LT_RBG_INDEX.
  CLEAR LS_RBG_INDEX.
  LS_RBG_INDEX-TEXT = 'Radio 3'.
  APPEND LS_RBG_INDEX TO LT_RBG_INDEX.
  CLEAR LS_RBG_INDEX.
  LS_RBG_INDEX-TEXT = 'Radio 4'.
  APPEND LS_RBG_INDEX TO LT_RBG_INDEX.
  CLEAR LS_RBG_INDEX.
*  * @TODO compute values
*  * e.g. call a model function
*
  LO_ND_RBG_INDEX->BIND_TABLE( NEW_ITEMS = LT_RBG_INDEX SET_INITIAL_ELEMENTS = ABAP_TRUE ).

Step5: Go to actions tab, double click on ON_SELECT, add below code.

DATA LO_ND_RBG_INDEX TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA LO_EL_RBG_INDEX TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_RBG_INDEX TYPE WD_THIS->ELEMENT_RBG_INDEX.
  DATA LV_TEXT TYPE WD_THIS->ELEMENT_RBG_INDEX-TEXT.

*   navigate from <CONTEXT> to <RBG_INDEX> via lead selection
  LO_ND_RBG_INDEX = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_RBG_INDEX ).

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

*   get element via lead selection
  LO_EL_RBG_INDEX = LO_ND_RBG_INDEX->GET_ELEMENT( ).
*   alternative access  via index
*   lo_el_RBG_INDEX = lo_nd_RBG_INDEX->get_element( index = 1 ).
*   @TODO handle not set lead selection
  IF LO_EL_RBG_INDEX IS INITIAL.
  ENDIF.

*   get single attribute
  LO_EL_RBG_INDEX->GET_ATTRIBUTE(
    EXPORTING
      NAME =  `TEXT`
    IMPORTING
      VALUE = LV_TEXT ).


  DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT.
  DATA LS_CONTEXT TYPE WD_THIS->ELEMENT_CONTEXT.
  DATA LV_SELETEXT TYPE WD_THIS->ELEMENT_CONTEXT-SELETEXT.

* get element via lead selection
  LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ).

* @TODO handle not set lead selection
  IF LO_EL_CONTEXT IS INITIAL.
  ENDIF.

* @TODO fill attribute
* lv_seletext = 1.
  IF LV_TEXT = 'Radio 1'.
    LV_SELETEXT = 'Radio 1 selected'.
  ELSEIF LV_TEXT = 'Radio 2'.
    LV_SELETEXT = 'Radio 2 selected'.
  ELSEIF LV_TEXT = 'Radio 3'.
    LV_SELETEXT = 'Radio 3 selected'.
  ELSEIF LV_TEXT = 'Radio 4'.
    LV_SELETEXT = 'Radio 4 selected'.
  ENDIF.
* set single attribute
  LO_EL_CONTEXT->SET_ATTRIBUTE(
    NAME =  `SELETEXT`
    VALUE = LV_SELETEXT ).

Step7:Activate, 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 6 People out of 12 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →