-3

I have an ALV in container on screen 0100. It's created via class CL_SALV_TABLE.

The problem is that I can't get selected row via go_alv_dms->get_selections( )->get_selected_rows( ) after pressing a button on the screen (2 on the screenshot).

I can access the selected rows with no problem if the button is in the ALV status bar (1 on the screenshot) though. It seems like pressing the button outside of ALV cleans selections of it.

enter image description here

Register selection when show ALV:

  ...
  lo_selections = go_alv_dms->get_selections( ).
  lo_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
  lo_events = go_alv_dms->get_event( ).
  CREATE OBJECT go_handler.
  SET HANDLER go_handler->on_user_command2 FOR lo_events.
  ...

PAI of the screen button logic:

 go_handler->on_user_command2( gv_ok_0100 ).

Method on_user_command2:

    case gv_ok_0100.
      when 'OK'.
         ...
         lt_rows = go_alv_dms->get_selections( )->get_selected_rows( ).
         ...
    ENDCASE.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Nikito_Os
  • 1
  • 1
  • 1
  • 3
  • That should work like a charm. I don't understand your remark about "pressing the button outside of ALV [which works as you say] cleans selections", what does it bring to your question? (of course, getting the selected rows shouldn't unselect them). Did you reach your code when you press the buton in the ALV-owned toolbar? If no, then you didn't call cl_gui_cfw=>dispatch in the PAI. If yes, please provide a short standalone code so that we can copy it and reproduce your problem. (note that it's a matter of a 30-lines program to demonstrate that it should work "like a charm", as I said). – Sandra Rossi Apr 14 '18 at 05:34
  • Yes, I reach my code when I press the buton in the ALV-owned toolbar. I added the code to the question. – Nikito_Os Apr 16 '18 at 06:35

2 Answers2

1
DATA gr_alv TYPE REF TO cl_salv_table.
DATA it_rows TYPE salv_t_row.
... 
gr_alv->get_metadata( ). " Call this method before getting selected rows
it_rows = gr_alv->get_selections( )->get_selected_rows( ).

Reference: https://answers.sap.com/questions/4693234/getselectedrows-returns-nothing.html

double-beep
  • 5,031
  • 17
  • 33
  • 41
0

After listening to the opinions of colleagues and searching for an answer on the Internet, I came to the conclusion that this is class CL_SALV_TABLE restriction. I rewrote the program on class CL_ALV_GRID and it's earned. I like CL_SALV_TABLE and will be glad if someone refutes my statement.

Nikito_Os
  • 1
  • 1
  • 1
  • 3