Skip to Content
Sep 10, 2009 at 01:44 PM

SALV - ALV selected row Index - Not getting in second time


I am having a ALV grid using CL_SALV_TABLE class. and its have PF-status button "Display" and user select a line and press "Display" button system will display a PDF document from content server.

The following is the code i am using for getting index of selected row.

My problem is user select a line for the first time i am getting the index, but user select second time i am not getting the index

module user_command_0300 input.
  call method cl_gui_cfw=>dispatch.
  case ok_code.
    when c_hist.
      perform f_show_history.
    when others.
  clear ok_code.


form f_show_history.
  data : p_wa_rows    type int4.
  data : p_i_rows     type salv_t_row.
  gr_table->get_metadata( ).
  p_i_rows = gr_selections->get_selected_rows( )." Here Its failing in second time. P_I_ROWS showing blank second time
  clear: wa_output.
  read table p_i_rows into p_wa_rows index 1.
  if sy-subrc eq 0.
    read table i_output into wa_output index p_wa_rows.
    if sy-subrc eq 0.
      perform f_display_document.
  refresh : p_i_rows. clear : p_i_rows.
  gr_selections = gr_table->get_selections( ).
  gr_selections->set_selected_rows( p_i_rows ).
  gr_table->refresh( ).
  call method cl_gui_cfw=>set_new_ok_code( new_code = 'REFR' ).
endform.                                 " F_show_history

PS : I don't want to place the button in the ALV application toolbar