cancel
Showing results for 
Search instead for 
Did you mean: 

how to get index numbers on rows selected in a table..

Former Member
0 Kudos

Hi friends,

i have a table with 16 rows by default. User can select more than one row at once... But I have a DELETE button on the table.

If user tries to select more than one row( could be many and in anny order ), i wnt to know the index numbers which are been selected../

how to get them pls... can someone tell me.

thanks

Niraja

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor
0 Kudos

Hi Niraja,

I guess that when you select multiple rows & click on the delete button you must be using the method get_selected_elements of if_wd_context_node to get the list of rows selected by the user. This method would return a table of type wdr_context_element_set. Consider the code fragment below for the same exact requirement:

METHOD onactiondelete_selected_rows .
  DATA:  wd_node TYPE REF TO if_wd_context_node,
         lt_node1 TYPE ig_componentcontroller=>elements_node1,
         wa_temp  TYPE REF TO if_wd_context_element,
         lt_temp  TYPE wdr_context_element_set,
         row_number TYPE i VALUE 0.

  wd_node = wd_context->get_child_node( name = 'NODE1' ).

  CALL METHOD wd_node->get_selected_elements
    RECEIVING
      set = lt_temp.

" Remove the selected rows from the context node used for binding to the table
  LOOP AT lt_temp INTO wa_temp.
    wd_node->remove_element( EXPORTING element = wa_temp ).
  ENDLOOP.

" Get the updated data from the context node
  CALL METHOD wd_node->get_static_attributes_table
    EXPORTING
      from  = 1
      to    = 2147483647
    IMPORTING
      table = lt_node1.

" Refresh the table display with the new set of data present at the context node
  wd_node->bind_table( new_items = lt_node1 ).
ENDMETHOD.

If in debugging mode you double click on lt_temp & check its properties you can see that it is a table of references like . So now double click on any 1 of this reference and here you can find an attribute by name M_INDEX which does actually store the index of the row selected by the user. Hope this helps.

Regards,

Uday

Former Member
0 Kudos

Uday, basically i wanted the row's index which are been deleted... not the one which are remained in teh context.

If there are 3 records, user selects record1, and record3, and hits delte.. In this action. i want to know the index 1 and 3..

how to achieve this... pls..

niraja

uday_gubbala2
Active Contributor
0 Kudos

Hi Niraja,

I had actually given you the procedure for getting the same. When you use the get_selected_elements method to fetch the rows selected by the user into an internal table the system would take care of this for you. Just try implement the same and check out in debugging mode. Only the rows selected by the user would be fetched into the internal table and they would also be having the corresponding table index in the M_INDEX attribute.

Regards,

Uday

Former Member
0 Kudos

Uday then what does this method do :

" Get the updated data from the context node

CALL METHOD wd_node->get_static_attributes_table

EXPORTING

from = 1

to = 2147483647

IMPORTING

table = lt_node1.

why are the from and to are numbers: 2147483647. what is thsi?

niraja

uday_gubbala2
Active Contributor
0 Kudos

Well Niraja,

Am sorry guess that there was a small mistake from my end. I will explain it to you below.

First we get the rows which were selected by the user into an internal table using the method get_selected_elements. You then loop through this table & delete the corresponding entries from your context node using the method remove_element. So suppose your table has 100 rows of data then your context node too would be having 100 rows of data in it. Now say the user has selected 10 rows for deletion then you first get the references of these 10 rows & then delete them from your context. So now your context would be having 90 rows of data in it. Your table would then automatically get refreshed as per your context nodes data. So you would just have to use the below coding to fetch the rows selected by the user & delete them from your table:

METHOD onactiondelete_selected_rows .
  DATA:  wd_node TYPE REF TO if_wd_context_node,
         lt_node1 TYPE ig_componentcontroller=>elements_node1,
         wa_temp  TYPE REF TO if_wd_context_element,
         lt_temp  TYPE wdr_context_element_set,
         row_number TYPE i VALUE 0.


  wd_node = wd_context->get_child_node( name = 'NODE1' ).

  CALL METHOD wd_node->get_selected_elements
    RECEIVING
      set = lt_temp.

  LOOP AT lt_temp INTO wa_temp.
    wd_node->remove_element( EXPORTING element = wa_temp ).
  ENDLOOP.
ENDMETHOD.

You wouldnt have to use the rest of the code which I had specified earlier. I have just tried the same in my system and its working fine.

Regards,

Uday

Former Member
0 Kudos

Hi Niraja,

use this mehod to get the index of selected row.

GET_LEAD_SELECTION_INDEX

if you select more than one row then use the following logic to get the indexes of selected rows.

types:begin of ty_index,

v_index type i,

end of ty_index,

ty_t_index type table of ty_index.

data:lt_elements type WDR_CONTEXT_ELEMENT_SET,

ls_elements like line of lt_elements.

data:lt_index type ty_t_index,

ls_index type ty_index.

call method lo_node->get_elements

  • exporting

  • from =

  • to =

receiving

set = lt_elements.

loop at lt_elements into ls_elements.

call method ls_elements->get_index

receiving

my_index = ls_index-v_index .

append ls_index to lt_index.

endloop.

Answers (0)