ABAP-利用定时器自动刷新屏幕
*&---------------------------------------------------------------------* *& Report Y_XB_TEST1 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT Y_XB_TEST1 NO STANDARD PAGE HEADING. CLASS lcl_event_handler DEFINITION DEFERRED. DATA: go_timer TYPE REF TO cl_gui_timer, go_evt_hndl TYPE REF TO lcl_event_handler, gv_datum TYPE sy-datum, gv_uzeit TYPE sy-uzeit. *&---------------------------------------------------------------------* *& START-OF-SELECTION *&---------------------------------------------------------------------* START-OF-SELECTION. gv_datum = sy-datum. gv_uzeit = sy-uzeit. PERFORM list_output. PERFORM init_timer. *&---------------------------------------------------------------------* *& USER-COMMAND *&---------------------------------------------------------------------* AT USER-COMMAND. IF sy-ucomm = 'RFSH'. sy-lsind = sy-lsind - 1. PERFORM list_output. ENDIF. *&---------------------------------------------------------------------* *& CLASS lcl_event_handler DEFINITION *&---------------------------------------------------------------------* CLASS lcl_event_handler DEFINITION. PUBLIC SECTION. METHODS: handle_timer FOR EVENT finished OF cl_gui_timer. ENDCLASS. "lcl_event_handler DEFINITION *&---------------------------------------------------------------------* *& CLASS lcl_event_handler IMPLEMENTATION *&---------------------------------------------------------------------* CLASS lcl_event_handler IMPLEMENTATION. METHOD handle_timer. CALL METHOD cl_gui_cfw=>set_new_ok_code EXPORTING new_code = 'RFSH'. CALL METHOD go_timer->run "必须重新激活定时器 EXCEPTIONS OTHERS = 9. ENDMETHOD. "handle_timer ENDCLASS. "lcl_event_handler IMPLEMENTATION *&---------------------------------------------------------------------* *& Form INIT_TIMER *&---------------------------------------------------------------------* FORM init_timer. CHECK go_timer IS INITIAL. CREATE OBJECT go_timer EXCEPTIONS OTHERS = 9. CREATE OBJECT go_evt_hndl. SET HANDLER go_evt_hndl->handle_timer FOR go_timer. go_timer->interval = 5. "设置间隔为10秒 CALL METHOD go_timer->run "激活定时器 EXCEPTIONS OTHERS = 9. ENDFORM. " INIT_TIMER *&---------------------------------------------------------------------* *& Form LIST_OUTPUT *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM list_output . DATA: datediff TYPE p, timediff TYPE p DECIMALS 2. datediff = sy-datum - gv_datum. timediff = ( sy-uzeit - gv_uzeit ) / 60. WRITE: /5 '本次开始时间:' ,AT 30 gv_datum , AT 45 gv_uzeit. WRITE: /5 '本次运行时长:' ,AT 30 datediff LEFT-JUSTIFIED, AT 38 '天' , at 45 timediff LEFT-JUSTIFIED , AT 51 '分'. ENDFORM.