2

I need to return to a specific line in ALV in the code with cl_gui_alv_grid. I use set_current_cell_via_id, it works, but only a cell is selected. How to programatically select the full row?

result of cl_gui_alv_grid set_current_cell_via_id

Thanks

Full code:

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gt_t005t TYPE TABLE OF t005t.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF gr_alvgrid IS NOT BOUND.
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM t005t INTO TABLE gt_t005t WHERE spras = 'E'.
    gr_alvgrid->set_table_for_first_display(
        EXPORTING i_structure_name = 'T005T'
        is_layout = VALUE #( sel_mode = 'D' )
        CHANGING it_outtab = gt_t005t ).
  ENDIF.
  DATA sroid TYPE lvc_s_roid.
  DATA irow TYPE i VALUE 2.
  SROID-ROW_ID = iRow.
  CALL METHOD gr_alvgrid->set_current_cell_via_id
    EXPORTING
      IS_ROW_NO = SROID.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Manul74
  • 139
  • 1
  • 6

1 Answers1

5

Use the method SET_SELECTED_ROWS to achieve this result:

result of method SET_SELECTED_ROWS of cl_gui_alv_grid

Full code:

DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gt_t005t TYPE TABLE OF t005t.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF gr_alvgrid IS NOT BOUND.
    CREATE OBJECT gr_alvgrid
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM t005t INTO TABLE gt_t005t WHERE spras = 'E'.
    gr_alvgrid->set_table_for_first_display(
        EXPORTING i_structure_name = 'T005T'
        is_layout = VALUE #( sel_mode = 'D' )
        CHANGING it_outtab = gt_t005t ).
  ENDIF.
  gr_alvgrid->set_selected_rows( it_row_no = VALUE lvc_t_roid( ( row_id = 2 ) ) ).
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48