DATA: RCL_REFRESH_TIMER TYPE REF TO CL_GUI_TIMER,
G_REFRESH_INTERVAL TYPE I,
E_GRID TYPE REF TO CL_GUI_ALV_GRID.
*---------------------------------------------------------------------*
* CLASS lcl_autorefresh_timeout DEFINITION
*---------------------------------------------------------------------*
* ID 11731 *
*---------------------------------------------------------------------*
CLASS LCL_AUTOREFRESH_TIMEOUT DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
HANDLE_AUTOREFRESH_TIMEOUT
FOR EVENT FINISHED
OF CL_GUI_TIMER
IMPORTING SENDER.
ENDCLASS. "lcl_autorefresh_timeout DEFINITION
*&---------------------------------------------------------------------*
*& Class (Implementation) lcl_autorefresh_timeout
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS LCL_AUTOREFRESH_TIMEOUT IMPLEMENTATION.
METHOD HANDLE_AUTOREFRESH_TIMEOUT.
* DATA: S_RFSH TYPE RNREFRESH,
* L_RFSH_TIME(10) TYPE N.
PERFORM FRM_GET_DATA. " 需要作的事情
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = E_GRID.
CALL METHOD E_GRID->CHECK_CHANGED_DATA.
* RS_SELFIELD-REFRESH = 'X'.
CALL METHOD RCL_REFRESH_TIMER->RUN
EXCEPTIONS
OTHERS = 99.
ENDMETHOD. "handle_autorefresh_timeout
ENDCLASS. "lcl_autorefresh_timeout
*&---------------------------------------------------------------------*
*& Form SHOW_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SHOW_ALV .
CREATE OBJECT RCL_REFRESH_TIMER
EXCEPTIONS
OTHERS = 99.
G_REFRESH_INTERVAL = 600.
RCL_REFRESH_TIMER->INTERVAL = G_REFRESH_INTERVAL.
CALL METHOD RCL_REFRESH_TIMER->RUN
EXCEPTIONS
OTHERS = 99.
SET HANDLER LCL_AUTOREFRESH_TIMEOUT=>HANDLE_AUTOREFRESH_TIMEOUT
FOR RCL_REFRESH_TIMER.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = L_REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_ALVSTATUS'
IS_LAYOUT = L_LAYOUT
I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'
IT_FIELDCAT = G_FIELDCAT[]
I_SAVE = 'A'
TABLES
T_OUTTAB = IT_TAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
G_REFRESH_INTERVAL TYPE I,
E_GRID TYPE REF TO CL_GUI_ALV_GRID.
*---------------------------------------------------------------------*
* CLASS lcl_autorefresh_timeout DEFINITION
*---------------------------------------------------------------------*
* ID 11731 *
*---------------------------------------------------------------------*
CLASS LCL_AUTOREFRESH_TIMEOUT DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
HANDLE_AUTOREFRESH_TIMEOUT
FOR EVENT FINISHED
OF CL_GUI_TIMER
IMPORTING SENDER.
ENDCLASS. "lcl_autorefresh_timeout DEFINITION
*&---------------------------------------------------------------------*
*& Class (Implementation) lcl_autorefresh_timeout
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS LCL_AUTOREFRESH_TIMEOUT IMPLEMENTATION.
METHOD HANDLE_AUTOREFRESH_TIMEOUT.
* DATA: S_RFSH TYPE RNREFRESH,
* L_RFSH_TIME(10) TYPE N.
PERFORM FRM_GET_DATA. " 需要作的事情
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = E_GRID.
CALL METHOD E_GRID->CHECK_CHANGED_DATA.
* RS_SELFIELD-REFRESH = 'X'.
CALL METHOD RCL_REFRESH_TIMER->RUN
EXCEPTIONS
OTHERS = 99.
ENDMETHOD. "handle_autorefresh_timeout
ENDCLASS. "lcl_autorefresh_timeout
*&---------------------------------------------------------------------*
*& Form SHOW_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SHOW_ALV .
CREATE OBJECT RCL_REFRESH_TIMER
EXCEPTIONS
OTHERS = 99.
G_REFRESH_INTERVAL = 600.
RCL_REFRESH_TIMER->INTERVAL = G_REFRESH_INTERVAL.
CALL METHOD RCL_REFRESH_TIMER->RUN
EXCEPTIONS
OTHERS = 99.
SET HANDLER LCL_AUTOREFRESH_TIMEOUT=>HANDLE_AUTOREFRESH_TIMEOUT
FOR RCL_REFRESH_TIMER.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = L_REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_ALVSTATUS'
IS_LAYOUT = L_LAYOUT
I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'
IT_FIELDCAT = G_FIELDCAT[]
I_SAVE = 'A'
TABLES
T_OUTTAB = IT_TAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDFORM. " SHOW_ALV
-------------------------------
手动更新数据
-------------------------------
FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
**手动的刷新
CASE SY-UCOMM.
WHEN 'REFRESH'.
PERFORM FRM_GET_DATA.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = E_GRID.
CALL METHOD E_GRID->CHECK_CHANGED_DATA.
RS_SELFIELD-REFRESH = 'X'.
ENDCASE.