ABAP – Refresh ALV GRID and keep position and current cell

Home / SAP / ABAP Coding / ABAP – Refresh ALV GRID and keep position and current cell

Since I’ve been rebuilding my Renovation product into the old school Dynpro, it’s meant relearning a few tricks.  Today, my trick was to keep the position, selections and current cell after refreshing the data with new data or updated date.  First off, I need to thank this post for the great info.

Here’s the basics.  Before you refresh the table, you will need to perform the following on your ALV grid.

  dataes_row_no  type lvc_s_roid.
  dataes_row_info  type lvc_s_row.
  dataes_col_info  type lvc_s_col.
  datafes_row_no  type lvc_s_roid.
  datafes_row_id  type lvc_s_row.
  datafes_col_id  type lvc_s_col.
  datamt_cells type lvc_t_ceno.
  datamt_rows type lvc_t_row.

  grid->get_scroll_info_via_id(
  importing
    es_row_no   es_row_no
es_row_info 
es_row_info
es_col_info 
es_col_info
).

  grid->get_current_cell(
    importing
*        e_row     = e_row
*        e_value   = e_value
*        e_col     = e_col
      es_row_id fes_row_id
es_col_id 
fes_col_id
es_row_no 
fes_row_no
).

  grid->get_selected_rows(
  importing
    et_index_rows mt_rows
*            et_row_no     = et_row_no
    ).
  if mt_rows[] is initial.
    grid->get_selected_cells_id(
    importing  et_cells mt_cells ).
  endif.

Now, there are multiple ways to refresh the table, I use set_table_for_first_display, but the post example uses refresh_table_display.  Either way, after you do your refresh, then run the following to set the position and selections.

    if mt_cells[] is not initial.
      grid->set_selected_cells_idit_cells mt_cells   ).
    else.
      grid->set_selected_rows(
      it_index_rows            mt_rows
*        it_row_no                = it_row_no
*        is_keep_other_selections = is_keep_other_selections
      ).
    endif.

  grid->set_scroll_info_via_id(
  is_row_info es_row_info
is_col_info 
es_col_info
is_row_no   
es_row_no
).

    grid->set_current_cell_via_idis_row_id fes_row_id
is_column_id 
fes_col_id
is_row_no 
fes_row_no ).
  refreshmt_rows[]mt_cells[].

Thanks for reading,

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *