Usage of RowRepeater UI element
Scope: This document teaches you that how to use RowRepeter UI element.
Example: Here i’m going to design a view for a Exam which has Question & Objective answers. After review goes to read only mode and Submit will get enabled. After Submit Question & selected Answer will be shown below of the section.
Lets Start:
1. Create a Node(ND_MAIN) & sub node(ND_OPTIONS) (both are 0..n cardinality) shown like below. a node to display output(after submit) ND_OUTPUT. And an attribute to set read only of Radio buttons & enable for Submit Button (RENABLE).
2. Attributes like below
| ND_MAIN
| ND_OPTIONS
— OPTION (STRING)
— QUESTION (STRING)
— SNO (NUMC2)
3. Go to Layout and insert RowRepeater UI element.
4. Create a TransperentContainer under RR UI.
4.1
. TransparentContainer->Lable(SNO)->TextView(QUESTION).
4.2. RadioButtonGroupByIndex(OPTION).
snap shown below.
5. Layout view will be like below.
6. Please note After submit button only Below RowRepeater will get display.
7. Now make bindings of first RowRepeater(ROW_RP) with ND_MAIN(DataSource) & ND_OPTIONS and corresponding elements.
8. And make bindings of Second RowRepeater(ROW_REP) ND_OUTPUT. and corresponding elements.
9. Make data binding of ReadOnly property of RadioButtonGroupByIndex with RENABLE & also bind same for Enable property of Submit Button.
10. Now Go to WDDOINIT of MAIN view. and write the below code.
DATA lo_nd_nd_main TYPE REF TO if_wd_context_node.
DATA lo_el_nd_main TYPE REF TO if_wd_context_element.
DATA ls_nd_main TYPE wd_this->element_nd_main.
DATA lt_nd_main TYPE wd_this->elements_nd_main.
* navigate from <CONTEXT> to <ND_MAIN> via lead selection
lo_nd_nd_main = wd_context->get_child_node( name = wd_this->wdctx_nd_main ).
* lo_nd_nd_main->bind_structure( ls_nd_main ).
* get element via lead selection
* lo_el_nd_main = lo_nd_nd_main->get_element( ).
ls_nd_main-sno = 01.
ls_nd_main-question = ‘What is the capital of India?’.
APPEND ls_nd_main TO lt_nd_main.
ls_nd_main-sno = 02.
ls_nd_main-question = ‘What is your Profession?’.
APPEND ls_nd_main TO lt_nd_main.
ls_nd_main-sno = 03.
ls_nd_main-question = ‘Howmany states are there in India?’.
APPEND ls_nd_main TO lt_nd_main.
ls_nd_main-sno = 04.
ls_nd_main-question = ‘Did you learnt anything through this?’.
APPEND ls_nd_main TO lt_nd_main.
lo_nd_nd_main->bind_table( new_items = lt_nd_main set_initial_elements = abap_true ).
DATA lo_nd_nd_options TYPE REF TO if_wd_context_node.
DATA lt_nd_options TYPE wd_this->elements_nd_options.
DATA ls_nd_options TYPE wd_this->element_nd_options.
* navigate from <CONTEXT> to <ND_OPTIONS> via lead selection
lo_nd_nd_options = wd_context->path_get_node( path = `ND_MAIN.1.ND_OPTIONS` ). “” It represents Index = 1 of Parent Node(ND_MAIN).
ls_nd_options-option = ‘Hyderabad’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ‘New Delhi’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ‘Chennai’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ‘Kolkata’.
APPEND ls_nd_options TO lt_nd_options.
lo_nd_nd_options->bind_table( new_items = lt_nd_options set_initial_elements = abap_true ).
REFRESH: lt_nd_options.
* navigate from <CONTEXT> to <ND_OPTIONS> via lead selection
lo_nd_nd_options = wd_context->path_get_node( path = `ND_MAIN.2.ND_OPTIONS` ). “” It represents Index = 2 of Parent Node(ND_MAIN).
ls_nd_options-option = ‘IT Software’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ‘Business’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ‘Cultivation’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ‘Brokerage’.
APPEND ls_nd_options TO lt_nd_options.
lo_nd_nd_options->bind_table( new_items = lt_nd_options set_initial_elements = abap_true ).
REFRESH: lt_nd_options.
* navigate from <CONTEXT> to <ND_OPTIONS> via lead selection
lo_nd_nd_options = wd_context->path_get_node( path = `ND_MAIN.3.ND_OPTIONS` ). “” It represents Index = 3 of Parent Node(ND_MAIN).
ls_nd_options-option = ’23’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ’29’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ’30’.
APPEND ls_nd_options TO lt_nd_options.
ls_nd_options-option = ’28’.
APPEND ls_nd_options TO lt_nd_options.
lo_nd_nd_options->bind_table( new_items = lt_nd_options set_initial_elements = abap_true ).
REFRESH: lt_nd_options.
* navigate from <CONTEXT> to <ND_OPTIONS> via lead selection
lo_nd_nd_options = wd_context->path_get_node( path = `ND_MAIN.4.ND_OPTIONS` ). “” It represents Index = 4 of Parent Node(ND_MAIN).
lo_nd_nd_options->bind_table( new_items = lt_nd_options set_initial_elements = abap_true ).
REFRESH: lt_nd_options.
**** Enable Editing.
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_renable TYPE wd_this->element_context-renable.
* get element via lead selection
lo_el_context = wd_context->get_element( ).
* @TODO fill attribute
lv_renable = abap_false.
* set single attribute
lo_el_context->set_attribute(
name = `RENABLE`
value = lv_renable ).
11. Now come to REVIEW action. (which are created for test). and write the below code. Here just am enabling Submit Button.
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_renable TYPE wd_this->element_context-renable.
* 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_renable = abap_true.
* set single attribute
lo_el_context->set_attribute(
name = `RENABLE`
value = lv_renable ).
12. Now come to SUBMIT Action. and write the below code.
DATA lo_nd_nd_main TYPE REF TO if_wd_context_node.
DATA lo_el_nd_main TYPE REF TO if_wd_context_element.
DATA lt_nd_main TYPE wd_this->elements_nd_main.
DATA ls_nd_main TYPE wd_this->element_nd_main.
* navigate from <CONTEXT> to <ND_MAIN> via lead selection
lo_nd_nd_main = wd_context->get_child_node( name = wd_this->wdctx_nd_main ).
lo_nd_nd_main->get_static_attributes_table( IMPORTING table = lt_nd_main ).
DATA lo_nd_nd_output TYPE REF TO if_wd_context_node.
DATA lt_nd_output TYPE wd_this->elements_nd_output.
DATA ls_nd_output TYPE wd_this->element_nd_output.
DATA lo_nd_nd_options TYPE REF TO if_wd_context_node.
DATA lo_el_nd_options TYPE REF TO if_wd_context_element.
DATA ls_nd_options TYPE wd_this->element_nd_options.
LOOP AT lt_nd_main INTO ls_nd_main.
lo_el_nd_main = lo_nd_nd_main->get_element( index = sy-tabix ).
lo_nd_nd_options = lo_el_nd_main->get_child_node( name = ‘ND_OPTIONS’ ).
lo_el_nd_options = lo_nd_nd_options->get_element( ).
IF lo_el_nd_options IS NOT INITIAL.
* get all declared attributes
lo_el_nd_options->get_static_attributes(
IMPORTING
static_attributes = ls_nd_options ).
ENDIF.
**** Populating Output Value Table.
CONCATENATE ls_nd_main-sno ls_nd_main-question INTO ls_nd_output-question SEPARATED BY ‘.’.
CONCATENATE ‘Ans:’ ls_nd_options-option INTO ls_nd_output-answer SEPARATED BY space.
APPEND ls_nd_output TO lt_nd_output.
CLEAR: ls_nd_output, ls_nd_options, ls_nd_main.
ENDLOOP.
* navigate from <CONTEXT> to <ND_OUTPUT> via lead selection
lo_nd_nd_output = wd_context->get_child_node( name = wd_this->wdctx_nd_output ).
lo_nd_nd_output->bind_table( new_items = lt_nd_output set_initial_elements = abap_true ).
13. Create WebDynPro application and test the application.
Output Snaps are shown below.
Before Input:
After Input:
After REVIEW:
After SUBMIT: Final Output.