Standard ALV calls status STANDARD_FULLSCREEN (program SAPLKKBL) in which next/previous/first/last page is deactivated by default. The same program consist another status APPEND which has these buttons activated. Hence we need to overwrite the PF-STATUS call from STANDARD_FULLSCREEN to APPEND.
- Copy the APPEND status of program SAPLKKBL to your custom program using t-code SE41. [In this case I have used the same name for status for my program]
2. Function codes for the page scrolling already exist. Activate your status.
Changes in the custom program
3. Create subroutine SET_PF_STATUS to set the new PF-STATUS. Note, that this is called dynamically through FM REUSE_ALV_GRID_DISPLAY
FORM set_pf_statusUSING rt_extabTYPE slis_t_extab.
SET PF-STATUS 'APPEND'.
ENDFORM. "Set_pf_status
4. Create subroutine USER_COMMAND which will contain the action upon clicking next/previous/first/last page buttons.
Note, function codes for First Page is ‘P--’, Last Page is ‘P++’, Next Page is ‘P+’ and Previous Page is ‘P-’
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
REFRESH lt_data.
CASE r_ucomm.
WHEN 'P--'. "First Page
LOOP AT gt_data INTO lw_data
WHERE page = 1.
APPEND lw_data TO lt_data.
ENDLOOP.
g_page = 1.
WHEN 'P++'. "Last Page
LOOP AT gt_data INTO lw_data
WHERE page = g_lastpage.
APPEND lw_data TO lt_data.
CLEAR lw_data.
ENDLOOP.
g_page = g_lastpage.
WHEN 'P+'. "Next page
IF g_page EQ g_lastpage.
EXIT.
ELSE.
g_page = g_page + 1.
ENDIF.
LOOP AT gt_data INTO lw_data
WHERE page = g_page.
APPEND lw_data TO lt_data.
CLEAR lw_data.
ENDLOOP.
WHEN 'P-'. "Previous Page
IF g_page EQ 1.
EXIT.
ELSE.
g_page = g_page - 1.
ENDIF.
LOOP AT gt_data INTO lw_data
WHERE page = g_page.
APPEND lw_data TO lt_data.
CLEAR lw_data.
ENDLOOP.
ENDCASE.
ENDFORM. "User_command
5. In REUSE_ALV_GRID_DISPLAY, call the subroutine for new PF-STATUS and USER_COMMAND
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = lw_layout
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
6. In SET_PF_STATUS, add code to get to selection screen when clicking Back/Exit/Cancel button
FORM set_pf_status USING gt_extab TYPE slis_t_extab .
SET PF-STATUS 'APPEND'.
IF sy-ucomm EQ '&F03'
OR sy-ucomm EQ '&F12'
OR sy-ucomm EQ '&F15'.
SUBMIT ztrading_boe WITH SELECTION-TABLE gt_seltab VIA SELECTION-SCREEN.
ENDIF.
ENDFORM. "Set_pf_status
7.Populate selection screen values in GT_SELTAB in START-OF-SELECTION. This will retain the selection screen values when clicking Back/Exit/Cancel button
START-OF-SELECTION.
* Get selection screen data
PERFORM get_selections_values.
FORM get_selections_values.
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = sy-repid
TABLES
selection_table = gt_seltab
EXCEPTIONS
not_found = 1
no_report = 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.
ENDFORM. " GET_SELECTIONS_VALUES