Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
chengalarayulu
Active Contributor
0 Kudos

Scope: This document explores that how to read corresponding selected values in a dropdownbyindex in a static Table.

Bulletins to Follow:

1. Create a Node

TABLE and make this cardinalities like below.

2. Create a child node ND_DROP and maintain the below cardinalities.

     Here i've crated a Supply Function to fill the DropDownByIndex node(ND_DROP, TEXT as attribute

). Fill the same like below.

   * data declaration
  DATA lt_nd_drop TYPE wd_this->elements_nd_drop.
  DATA ls_nd_drop LIKE LINE OF lt_nd_drop.
* @TODO compute values
* e.g. call a data providing FuBa

  ls_nd_drop-text = 'Option 1'.
  APPEND ls_nd_drop TO lt_nd_drop.

  ls_nd_drop-text = 'Option 2'.
  APPEND ls_nd_drop TO lt_nd_drop.

  ls_nd_drop-text = 'Option 3'.
  APPEND ls_nd_drop TO lt_nd_drop.

  ls_nd_drop-text = 'Option 4'.
  APPEND ls_nd_drop TO lt_nd_drop.

* bind all the elements
  node->bind_table(
    new_items            =  lt_nd_drop
    set_initial_elements = abap_true ).

3. Create your own columns at Parent Node(

TABLE) level. Here i've taken PERNR & CHECK as two columns.

4. Goto Layout and create Table UI element.

5. Right click on Table and insertTableColumn

6. right click on column and insertCellEditor

7. Take the UI element DropDownByIndex

8. make sure binding with ND_DROP-TEXT to DropDownByIndex UI element TEXTS property.

9. Here i'm villing the Table data at WDDOINIT method. you take this turn at required place.

Code like below.

    DATA lo_nd_table TYPE REF TO if_wd_context_node.

  DATA lt_table TYPE wd_this->elements_table.
  DATA ls_table TYPE wd_this->element_table.

* navigate from <CONTEXT> to <TABLE> via lead selection
  lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).

  ls_table-pernr = 139162.
  ls_table-check = abap_false.
  APPEND ls_table TO lt_table.

  ls_table-pernr = 152224.
  ls_table-check = abap_false.
  APPEND ls_table TO lt_table.

  ls_table-pernr = 681935.
  ls_table-check = abap_false.
  APPEND ls_table TO lt_table.

  ls_table-pernr = 130303.
  ls_table-check = abap_false.
  APPEND ls_table TO lt_table.

  lo_nd_table->bind_table( new_items = lt_table set_initial_elements = abap_true ).

10. Create a button to read data from TABLE and bind to ND_OUTPUT, Action POPULATE_DATA.

11. Now create one more node with ND_OUTPUT, Attributes PERNR, CHECK, SEL_DROP....

Create Attributes also like above mentioned.

12. on Layout create one more TABLE UI element to display output and make binding with ND_OUTPUT.

13. Now write the below code in POPULATE_DATA action.

   ****** Parent Node which bound to Table.
  DATA lo_nd_table TYPE REF TO if_wd_context_node.
  DATA lo_el_table TYPE REF TO if_wd_context_element.
  DATA lt_table TYPE wd_this->elements_table.
  DATA ls_table TYPE wd_this->element_table.

* navigate from <CONTEXT> to <TABLE> via lead selection
  lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).

  lo_nd_table->get_static_attributes_table( IMPORTING table = lt_table ).

****** Child node which bound to DropDownByIndex.
  DATA lo_nd_nd_drop TYPE REF TO if_wd_context_node.
  DATA lo_el_nd_drop TYPE REF TO if_wd_context_element.
  DATA ls_nd_drop TYPE wd_this->element_nd_drop.

***** Reference of Output Node.

  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.

* navigate from <CONTEXT> to <ND_OUTPUT> via lead selection
  lo_nd_nd_output = wd_context->get_child_node( name = wd_this->wdctx_nd_output ).

**** Populate Data into Output Node.
  LOOP AT lt_table INTO ls_table.

**** Parent Node Element.
    lo_el_table = lo_nd_table->get_element( index = sy-tabix ).

****** Child Node reference at parent element index.
    lo_nd_nd_drop = lo_el_table->get_child_node( name = 'ND_DROP' ).

* get element via lead selection
    lo_el_nd_drop = lo_nd_nd_drop->get_element( ).

****** Now corresponding dropdown value exists in LS_ND_DROP.
* get all declared attributes
    lo_el_nd_drop->get_static_attributes(
      IMPORTING
        static_attributes = ls_nd_drop ).

    ls_nd_output-pernr = ls_table-pernr.
    ls_nd_output-check = ls_table-check.
    ls_nd_output-sel_drop = ls_nd_drop-text.

    APPEND ls_nd_output TO lt_nd_output.

    CLEAR: ls_nd_output, ls_table, ls_nd_drop.

  ENDLOOP.

  lo_nd_nd_output->bind_table( new_items = lt_nd_output set_initial_elements = abap_true ).

OUTPUT:

Labels in this area