Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member194669
Active Contributor
0 Kudos

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.
  endcase.
  clear ok_code.
endmodule.                             

then


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.
    endif..
  endif.
  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

11 REPLIES 11

Former Member
0 Kudos

Hi Dear,

I have some clue regarding your problem but that is in simple Alv not in oops.

declare a first field of your internal table i.e. you are passing to alv as cell type c.

then in layout

add

gs_layout-box_fieldname = 'SEL'.

pass this layout to alv.

then you are able to get exact row number.

LOOP AT gt_gi INTO gs_gi WHERE sel = 'X'.

gs_gi-sel = ' '.

APPEND gs_gi TO gt_gi.

CLEAR gs_gi.

ENDLOOP.

Hope this clue will help you.

Regards,

Vijay

0 Kudos

Vijay,

Your suggestion will not work. and i am not using field catalog.

Any more suggestions ?

0 Kudos

Hi,

Maybe:

instead of:

gr_table->get_metadata( ).

p_i_rows = gr_selections->get_selected_rows( )

do:

lv_sel = gr_table->get_selections( ).

lv_row = lv_sel->get_selected_rows( ).

where

DATA: lv_sel TYPE REF TO cl_salv_selections.

DATA: lv_row TYPE salv_t_row.

Best regards

0 Kudos

Without using


  gr_table->get_metadata( ).

I will not get the selected rows info from Frontend

Former Member
0 Kudos

Hi Dear ,

In morning I gave you some inputs , repeating the same .

You need to get the index , and after this you have to re-display the ALV and then get index again.

check this will work .

0 Kudos

Harsh,

You had provide with suggestion to use class CL_GUI_ALV_GRID class , Here i am using OM model SALV class. so your suggestion will not work

Former Member
0 Kudos

Sugession :

After ENDCASE statement , in your first block of code .

Please display the resultant internal table again .

it will start working .

0 Kudos

Harsh,

If you checked my code i given in my first thread, I am refreshing the display


 gr_table->refresh( ).

former_member194669
Active Contributor
0 Kudos

All,

This is my previous thread.

Any takers ?

Clemenss
Active Contributor
0 Kudos

Hi @rs,

In your form f_show_history, you

refresh : p_i_rows. clear : p_i_rows.
  gr_selections = gr_table->get_selections( ).
  gr_selections->set_selected_rows( p_i_rows ).

First you clear the p_i_rows table, then you use it to set the selected rows. I'd say setting nothing as selected may result in nothing selected.

May be this is the reason.

Regards,

Clemens

0 Kudos

Make sure that you don't re-create the table instance at PBO! Only create it once! This was my fault why the rows only work for the first time!

IF lr_table IS INITIAL.
    CALL METHOD cl_salv_table=>factory
      EXPORTING
        r_container  = cl_gui_container=>default_screen
      IMPORTING
        r_salv_table = lr_table
      CHANGING
        t_table      = gt_outtab.
ELSE
     lr_table->refresh( ).
ENDIF.