cancel
Showing results for 
Search instead for 
Did you mean: 

Get the selected rows in a Table?

Former Member
0 Kudos

Hi Experts,

I have a table with selection Mode "auto". I am able to multiselect the rows and the first selected row has the lead selection.

After selecting many rows I have to change and process the data of these selected rows in the next view.

How can I find out which rows are selected and then work with that data?

thank you for any help

Best regards

Haleh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

Use the below code to the data of rows selected into an internal table :

        • Data Declaration ********

data : lo_nd type ref to if_wd_context_node,

lo_nd1 type ref to if_wd_context_node,

lt_temp type wdr_context_element_set,

wa_temp type ref to if_wd_context_element,

ls_node1 type sflight,

lt_node1 type STANDARD TABLE OF sflight.

*******Get reference of node ******

lo_nd = wd_context->get_child_node('CN_MAIN'). <CN_MaIN is your node binded to Table>

      • Get the rows selected into lt_temp ***********

CALL METHOD lo_nd->get_selected_elements

RECEIVING

set = lt_temp.

******Get the data of the selected rows into an internal table ********

***Note internal table should be of type node ******

loop at lt_temp INTO wa_temp.

CALL METHOD wa_temp->get_static_attributes

IMPORTING

static_attributes = ls_node1.

APPEND ls_node1 TO lt_node1.

CLEAR ls_node1.

ENDLOOP.

****Finally you have your data in an internal table lt_node1.*****

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Saurav Mago you are correct in your approach to use the element set to read the individual elements. Might I offer an alternative implementation that doesn't require as many data copies. If you had a very large element set and/or a wide context the operation as you have describe would not be the most efficient approach.

This approach uses data references and field-symbols to reduce the amount of data copies that must occur in memory:

DATA lo_nd_cn_main TYPE REF TO if_wd_context_node.
  DATA lt_temp TYPE wdr_context_element_set.
  FIELD-SYMBOLS <wa_temp> LIKE LINE OF lt_temp.
  DATA lt_node1 TYPE wd_this->elements_cn_main.
  FIELD-SYMBOLS <ls_node1> LIKE LINE OF lt_node1.
  data lr_node1 type ref to wd_this->element_cn_main.

  lo_nd_cn_main = wd_context->get_child_node( name = wd_this->wdctx_cn_main ).
  lt_temp = lo_nd_cn_main->get_selected_elements( ).


  LOOP AT lt_temp ASSIGNING <wa_temp>.
    APPEND INITIAL LINE TO lt_node1 ASSIGNING <ls_node1>.
    lr_node1 ?= <wa_temp>->get_static_attributes_ref( ).
    <ls_node1> = lr_node1->*.
  ENDLOOP.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I suppose if you didn't want to deal with data references (as my first example did), then this second variation would still be a more efficent alternative that only uses field-symbols.

DATA lo_nd_cn_main TYPE REF TO if_wd_context_node.
  DATA lt_temp TYPE wdr_context_element_set.
  FIELD-SYMBOLS <wa_temp> LIKE LINE OF lt_temp.
  DATA lt_node1 TYPE wd_this->elements_cn_main.
  FIELD-SYMBOLS <ls_node1> LIKE LINE OF lt_node1.

  lo_nd_cn_main = wd_context->get_child_node( name = wd_this->wdctx_cn_main ).
  lt_temp = lo_nd_cn_main->get_selected_elements( ).

  LOOP AT lt_temp ASSIGNING <wa_temp>.
    APPEND INITIAL LINE TO lt_node1 ASSIGNING <ls_node1>.
    <wa_temp>->get_static_attributes( IMPORTING STATIC_ATTRIBUTES = <ls_node1> ).
  ENDLOOP.

Former Member
0 Kudos

Thank you very much Thomas, Also thank you Saurav,

Sorry for delay, couldn't answer earlier. Thomas I used your last coding without the data references. It works properly and now I have all the data of selected rows of the table in the internal table lt_temp.

Have a nice week

Kind regards

Haleh

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Instead of calling GET_LEAD_SELECTION method on the Node object, call GET_SELECTED_ELEMENTS. This will return an element set (internal table of element object instances) of all selected elements (and via input prameter including_lead_selection, you can also control if that element set does or doesn't include the lead selection as well).