cancel
Showing results for 
Search instead for 
Did you mean: 

Get Selections From ALV on Multiple Selection Mode

Former Member
0 Kudos

Hi,

How can i get values of selected rows from ALV that has selection '0..n' (multiple selection) ?

Can somebody help me pls?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

uday_gubbala2
Active Contributor

Hi Nurullah,

Steps to make multiple rows selectable in ALV:

1) Create the selection property of the node that you are binding to the DATA node as o..n

2) Un-check the, "Initialization Lead Selection" checkbox for the node which you are using to bind to the DATA node

3) In the WDDOINIT method specify the ALV's selection mode as MULTI_NO_LEAD. It is important that you set the selection mode to MULTI_NO_LEAD or else in the end you would be capturing 1 row lesser than the total number of rows the user has selected. This is because 1 of the rows would have the LeadSelection property & our logic wouldnt be reading the data for that row. Check the example code fragment as shown below:

DATA lo_value TYPE REF TO cl_salv_wd_config_table.
  lo_value = lo_interfacecontroller->get_model( ).

  CALL METHOD lo_value->if_salv_wd_table_settings~set_selection_mode
    EXPORTING
      value = cl_wd_table=>e_selection_mode-MULTI_NO_LEAD.

Steps to get the multiple rows selected by the user

In order to get the multiple rows which were selected by the user you will just have to call the get_selected_elements method of if_wd_context_node. So as you can see its no different from how you would get the multiple rows selected by the user in a table ui element. First get the reference of the node which you have used to bind to the ALV & then call this method on it. Check the example code fragment below:

METHOD get_selected_rows .
  DATA: temp TYPE string.

  DATA: lr_node TYPE REF TO if_wd_context_node,
            wa_temp  TYPE REF TO if_wd_context_element,
            ls_node1 TYPE wd_this->element_node_flighttab,
            lt_node1 TYPE wd_this->elements_node_flighttab.

  lr_node = wd_context->get_child_node( name = 'NODE_FLIGHTTAB' ).
" This would now contain the references of all the selected rows
  lt_temp = lr_node->get_selected_elements( ).

    LOOP AT lt_temp INTO wa_temp.
" Use the references to get the exact row data
      CALL METHOD wa_temp->get_static_attributes
        IMPORTING
          static_attributes = ls_node1.
      APPEND ls_node1 TO lt_node1.
      CLEAR ls_node1.
    ENDLOOP.
ENDMETHOD.

Hope this helps resolve your problem.

Regards,

Uday

Former Member
0 Kudos

Thank you very much Uday,

but i have a problem here ;

" This would now contain the references of all the selected rows
  lt_temp = lr_node->get_selected_elements( ).

Can you explain more pls?

Thanks again.

uday_gubbala2
Active Contributor
0 Kudos

Hi Rustam,

When you want to work with multiple selection on a table/ALV then you will have to go for a concept called SELECTION because using LeadSelection you can only always select 1 element (row). So there is a methog get_selected_elements in the interface if_wd_context_node. Whenever you make any multiple selection in an table/ALV the system would change the corresponding properties in the attached context node. So you first need to get a reference of the node that you have bound to your ALV like as shown below.

DATA: lr_node TYPE REF TO if_wd_context_node.
lr_node = wd_context->get_child_node( name = 'NODE_FLIGHTTAB' ).

You then need to call the method get_selected_elements using this node reference.

lt_temp = lr_node->get_selected_elements( ).

This method returns back the selected rows in the format of CL_WDR_CONTEXT_ELEMENT. You need to convert it into the normal data format using the get_static_attributes method of if_wd_context_node as shown below:

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.

When you complete with the loops execution lt_node1 will contain the information from all the rows selected by the user. Hope that helps resolve your doubt.

Regards,

Uday

Former Member
0 Kudos

Thanks Uday,

Which type do i need to define 'lt_temp'?

Former Member
0 Kudos

hi,

Please explain:

lo_value = lo_interfacecontroller->get_model( ).

What do I write in place of "lo_interfacecontroller"?

Thank you in advance.

Former Member
0 Kudos

HI,

PLEASE EXPLAIN :

HOW TO READ FROM DATA FROM "wa_temp"??

THANK YOU IN ADVANCE

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Nurullah,

i have a table, which is not an ALV table. It should be possible to multiple select the rows, after selecting rows, the checkboxes on thiese rows should be selected automatcally.

So i want to do these in my onselect event of my table:

1- get the selected rows from the context node

2- a certain checkbox on each of these selected rows should be checked (this should be visible on the Browser).

Thanx and regards

Haleh

Former Member
0 Kudos

Hi,

There is event methods like onLeadSelect and onSelect for your table. You can create with this event then you can get selected rows if you read the node of your table on this methods.

i wish i helped you.

Regards.

Former Member
0 Kudos

Yes I think I understand where you mean. I am working on it. Thanx for your reply. Also these advices in this thread are good. If I can not get through, then i will post my question an a seperate question.

Maybe you can tell me how can i post a new question, still i couldn't see any Button or Icon on the forum page.

thanx

Haleh

Former Member
0 Kudos

Go to forum (etc. Web Dynpro ABAP) which you want to post a new thread then use the link 'Post New Thread' top of the threads.

Good Lucks.

Former Member
0 Kudos

OK, Thank you for your assistance.

Former Member
0 Kudos

the reason for the dump was "get_static_attributes" (created code by wizard fpr reading the contxt node).

Should I continue the steps from DOINIT event? Is the process just the same as ALV table?

Thank you

Haleh

Former Member
0 Kudos

What do you want to do?

Former Member
0 Kudos

sorry forgot something, i didn't do anything in the DOINIT event till now.

Regards, Haleh

Former Member
0 Kudos

Did you solve your problem?

Former Member
0 Kudos

Hi Experts,

is there any differences between Multiple Selection Moder for ALV Table and normal table?

My table is not a ALV table. I did the steps up to the third step suggested by Uday in this thread. I did the 3.d step only by the table properties and changed the selection mode property from suto to muliNoLead. Now I get a dump each time i selected a row in the table.

The text of the error is something like this: access over 'NULL' object reference not possible

Would you help me in this issue please?

Thank you and regards

Haleh

Former Member
0 Kudos

Thank you very much Uday,

i define lt_temp with WDR_CONTEXT_ELEMENT_SET type and it is solved.

Thanks again.

Regards.