Report z_alv_auto_refresh.
*> ************************************** *******************************
* This report displays user's info (sm04) using the FM :*
* Reuse_alv_list_display *
* The list is auto-refreshed (refresh time: 5 seconds )*
*---------------------------------------------------------------------*
Type-pools: slis. "ALV global types
Data:
Gt_user like uinfo occurs 0 with header line. "User Info in sm04
*---------------------------------------------------------------------*
Start-of-selection.
Perform f_read_data.
Perform f_display_data.
*---------------------------------------------------------------------*
* Form f_lire_data
*---------------------------------------------------------------------*
Form f_read_data.
Refresh gt_user.
* Get user's info
Call function 'thusrinfo'
Tables
Usr_tabl = gt_user.
* Wait in a task
Perform f_call_rfc_wait.
Endform. "f_read_data
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
Form f_display_data.
Define m_sort.
Add 1 to ls_sort-spos.
Ls_sort-fieldname = & 1.
Append ls_sort to lt_sort.
End-of-definition.
Define m_event_exit.
Clear ls_event_exit.
Ls_event_exit-ucomm = & 1.
Ls_event_exit-after = 'x '.
Append ls_event_exit to lt_event_exit.
End-of-definition.
Data:
Ls_layout type slis_layout_alv,
Lt_sort type slis_t_sortinfo_alv,
Ls_sort type slis_sortinfo_alv,
Lt_event_exit type slis_t_event_exit,
Ls_event_exit type slis_event_exit.
* Build sort table
M_sort 'zeit '.
* Build event exit table
M_event_exit '& NTE'. "Refresh
Ls_layout-zebra = 'x '.
Ls_layout-colwidth_optimize = 'x '.
Call function 'reuse _ alv_list_display'
Exporting
I _callback_program = sy-cprog
I _callback_user_command = 'user _ command'
Is_layout = ls_layout
I _structure_name = 'uinfo'
It_sort = lt_sort
It_event_exit = lt_event_exit
Tables
T_outtab = gt_user.
Endform. "f_display_data
*---------------------------------------------------------------------*
* Form user_command *
*---------------------------------------------------------------------*
Form user_command using I _ucomm type syucomm
Is_selfield type slis_selfield. "# EC called
Case I _ucomm.
When' & NTE '.
Perform f_read_data.
Is_selfield-refresh = 'x '.
Set User-command '& opt'. "optimize columns width
Endcase.
Endform. "user_command
*---------------------------------------------------------------------*
* Form f_call_rfc_wait
*---------------------------------------------------------------------*
Form f_call_rfc_wait.
Data lv_mssg (80). "# EC needed
* Wait in a task
Call function 'rfc _ ping_and_wait 'starting new task '001'
Ming f_task_end on end of task
Exporting
Seconds = 5 "Refresh time
Busy_waiting = space
Exceptions
Resource_failure = 1
Communication_failure = 2 message lv_mssg
System_failure = 3 message lv_mssg
Others = 4.
Endform. "f_call_rfc_wait
*---------------------------------------------------------------------*
* Form f_task_end
*---------------------------------------------------------------------*
Form f_task_end using u_taskname.
Data lv_mssg (80). "# EC needed
* Processing ing task results
Receive results from function 'rfc _ ping_and_wait'
Exceptions
Resource_failure = 1
Communication_failure = 2 message lv_mssg
System_failure = 3 message lv_mssg
Others = 4.
Check sy-subrc EQ 0.
Set User-command '& nte'. "Refresh
Endform. "f_task_end
* ************** End of program z_alv_auto_refresh *********************
Related connection: http://blog.csdn.net/CompassButton/archive/2006/09/09/1198709.aspx
Source: http://www.sap-basis-abap.com/abap/auto-refresh-alv-list.htm