上篇文章(
利用SAP定时器自动刷新ALV)中介绍了类cl_gui_timer的使用,这里继续使用该类来演示对LIST的自动刷新,以与网上通行的使用函数RFC_PING_AND_WAIT的刷新方法作个对比。
代码如下,需要说明的是,由于cl_gui_timer是SAPGUI的一个控件,必须使用CALL METHOD cl_gui_cfw=>set_new_ok_code来触发USER-COMMAND事件,而不是SET USER-COMMAND语句,大家不妨试下。
REPORT z04_gui_timer.
CLASS lcl_event_handler DEFINITION DEFERRED.
DATA: go_timer TYPE REF TO cl_gui_timer,
go_evt_hndl TYPE REF TO lcl_event_handler,
gt_spfli TYPE TABLE OF spfli WITH HEADER LINE.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT * INTO TABLE gt_spfli
FROM spfli UP TO 30 ROWS.
PERFORM list_output.
PERFORM init_timer.
*&---------------------------------------------------------------------*
*& USER-COMMAND
*&---------------------------------------------------------------------*
AT USER-COMMAND.
IF sy-ucomm = 'RFSH'.
sy-lsind = sy-lsind - 1.
PERFORM list_output.
ENDIF.
*&---------------------------------------------------------------------*
*& Form LIST_OUTPUT
*&---------------------------------------------------------------------*
FORM list_output.
DATA: ls_spfli LIKE LINE OF gt_spfli.
NEW-PAGE WITH-TITLE LINE-SIZE 60.
WRITE: /5 'CARRID', AT 30 'CONNID'.
LOOP AT gt_spfli.
WRITE: / gt_spfli-carrid UNDER 'CARRID',
gt_spfli-connid UNDER 'CONNID'.
ENDLOOP.
ENDFORM. " LIST_OUTPUT
*&---------------------------------------------------------------------*
*& 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.
DELETE gt_spfli INDEX 1.
* SET USER-COMMAND 'RFSH'.
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 = 3. "设置间隔为3秒
CALL METHOD go_timer->run "激活定时器
EXCEPTIONS
OTHERS = 9.
ENDFORM. " INIT_TIMER
阅读(4911) | 评论(7) | 转发(1) |