Skip to Content

Very often Webdynpro developers are required to find the index of the row that the user is dealing with currently .

1. The most basic scenario is when we need to find the row index for selected row of the table on the action of “onLeadSelect” . In this case the row selectable 

     property of the table is set to true .

     The steps are as follows :

  • Create an action for onLeadSelect of the table . Give a name and check the check box ‘Transfer UI Event Parameters’.

         1.JPG

  • To the action (under Actions tab), add the parameters (click on the small box next to search button ) CONTEXT_ELEMENT,NEW_ROW_ELEMENT and OLD_ROW_ELEMENT

           2.JPG

  • Now go to the methods tab and click on the method name corresponding to the action.
  • Select the above three parameters

              3.JPG

  • Now go to the method code and write the following piece of code (please note that flight_list is the name of the table node) :

     data lo_nd_flight_list type ref to if_wd_context_node.

     data lo_el_flight_list type ref to if_wd_context_element.
     data ls_flight_list type wd_this->element_flight_list.
     data lv_connectid type wd_this->element_flight_list-airlineid.
     data ld_index type i value 0 .
*
*   navigate from <CONTEXT> to <FLIGHT_LIST> via lead selection
     lo_nd_flight_list = wd_context->path_get_node( path = `BAPI_FLIGHT_GETLIST.CHANGING.FLIGHT_LIST` ).

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

*   get element via lead selection

     ld_index = NEW_ROW_ELEMENT->GET_INDEX( ).

  • ld_index would give the index of the concerned row  .

2. The second scenario is when we need to find the index of the row on click of a button outside the table .

    To achieve this , we need the following code (please note that flight_list is the name of the table node) :

     DATA lo_nd_flight_list TYPE REF TO if_wd_context_node.

     DATA lo_el_flight_list TYPE REF TO if_wd_context_element.
     DATA ls_flight_list TYPE wd_this->element_flight_list.
     data currindex type i value 0.

*   navigate from <CONTEXT> to <FLIGHT_LIST> via lead selection
     lo_nd_flight_list = wd_context->path_get_node( path = `BAPI_FLIGHT_GETLIST.CHANGING.FLIGHT_LIST` ).

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

*   get element via lead selection  GET_LEAD_SELECTION_INDEX
     currindex = lo_nd_flight_list->GET_LEAD_SELECTION_INDEX( ) .

    Now currindex would give the index of the concerned row .

3. Third scenario is when the table’s Row Selectable property is false and there is a Button/Link To Action in the table .On the click of the button or LTA,

   we need to find the index of the row on which the button was clicked .

The following screenshot will help :

4.JPG

Here the row cannot be selected for the table and when the user hits “Click Here”, we need to find the index of that row for which the button was hit .

The procedure is as follows :

  • To the action of the button , add a parameter “CONTEXT_ELEMENT” of type IF_WD_CONTEXT_ELEMENT . This can be done as explained in scenario 1 above .
  • Write the following code in the action of the button :

     DATA lo_nd_flight_list TYPE REF TO if_wd_context_node.

     DATA lo_el_flight_list TYPE REF TO if_wd_context_element.
     DATA ls_flight_list TYPE wd_this->element_flight_list.
     DATA lv_airline TYPE wd_this->element_flight_list-airline.
     DATA SEL_INDEX LIKE SY-INDEX.
*   navigate from <CONTEXT> to <FLIGHT_LIST> via lead selection
     lo_nd_flight_list = wd_context->path_get_node( path = `BAPI_FLIGHT_GETLIST.CHANGING.FLIGHT_LIST` ).

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

*    Get Selected Row

    CALL METHOD CONTEXT_ELEMENT->GET_INDEX
    RECEIVING
    MY_INDEX = SEL_INDEX.

SEL_INDEX will now contain the index of the selected row .

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply