I created a simple ALV report displaying the data of my customized table through Function Module REUSE_ALV_GRID_DISPLAY. I also created a screen for the details view when you double click on a record from ALV. On this screen you could change the record details as you want and save it. When the user clicked on the save button, he will be automatically return to the ALV screen.
Now, what I want is when the user returns back from details view to ALV screen, I want the ALV to refresh automatically without clicking the refresh button on the application toolbar.
When I googled for the solution, I mostly came up with OOP(Object Oriented Programming) codes, wherein you declare an object with reference to the CL_GUI_ALV_GRID to create an ALV. In my case this is not applicable since I’ve already started my ALV code through function module. Fortunately I stumbled upon http://www.sap-basis-abap.com/abap/auto-refresh-alv-list.htm that provides a simple code for ALV auto refresh every 5 seconds.
In my case, I only have to add a a single line of codes in the form i used for the i_callback_user_command parameter of the REUSE_ALV_GRID_DISPLAY function module.
Below is my code for calling the REUSE_ALV_GRID_DISPLAY function module.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = gd_repid
i_callback_pf_status_set = ‘F_STATUS’
i_callback_user_command = ‘F_USER_COMMAND’
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_callback_top_of_page = ‘TOP_OF_PAGE’
it_sort = lt_sort
TABLES
t_outtab = it_comm.
And below is the code for the form F_USER_COMMAND:
FORM f_user_command USING UCOMM LIKE SY-UCOMM v_selfld TYPE slis_selfield.
some codes here for processing the user command
PERFORM f_get_data. “codes for retrieving data for ALV
v_selfld-refresh = ‘X’. “codes I added for auto refresh
ENDFORM.