Problem:
I have editable ALV, after edit I refresh ALV, but problem is, that position is set to position 1.1. I need to keep cursor at edited position.
Answer:
In order to refresh the ALV and keep the scroll position, read the scroll position before refresh and set the scroll position after the refresh..
The codes:
*&---------------------------------------------------------------------*
*& Form refresh_table_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM refresh_table_display .
DATA: li_rows TYPE lvc_s_roid,
li_col TYPE lvc_s_col,
lws_row_id TYPE lvc_s_roid,
lws_col_id TYPE lvc_s_col,
ls_col TYPE lvc_s_col,
ls_num TYPE lvc_s_roid.
* Get the latest field position
CALL METHOD c_grid->get_current_cell
IMPORTING
es_col_id = li_col
es_row_no = li_rows.
CALL METHOD c_grid->get_scroll_info_via_id
IMPORTING
es_col_info = ls_col
es_row_no = ls_num.
* refresh ALV
CALL METHOD c_grid->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc = 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Position back to the latest field
CALL METHOD c_grid->set_scroll_info_via_id
EXPORTING
is_col_info = ls_col
is_row_no = ls_num.
lws_row_id-row_id = li_rows-row_id.
lws_col_id-fieldname = li_col-fieldname.
CALL METHOD c_grid->set_current_cell_via_id
EXPORTING
is_column_id = lws_col_id
is_row_no = lws_row_id.
ENDFORM. " refresh_table_display
No comments :
Post a Comment