ABAP:利用SAP定时器自动刷新LIST


ABAP:利用SAP定时器自动刷新LIST

上篇文章( 利用SAP定时器自动刷新ALV)中介绍了类cl_gui_timer的使用,这里继续使用该类来演示对LIST的自动刷新,以与网上通行的使用函数RFC_PING_AND_WAIT的刷新方法作个对比。
代码如下,需要说明的是,由于cl_gui_timer是SAPGUI的一个控件,必须使用 CALLMETHODcl_gui_cfw=>set_new_ok_code来触发USER-COMMAND事件,而不是SETUSER-COMMAND语句,大家不妨试下。
<!--StartFragment --> <!--StartFragment -->REPORTz04_gui_timer.
CLASSlcl_event_handlerDEFINITIONDEFERRED.

DATA:go_timerTYPEREFTOcl_gui_timer,
go_evt_hndlTYPEREFTOlcl_event_handler,
gt_spfliTYPETABLEOFspfliWITHHEADERLINE.
*&---------------------------------------------------------------------*
*&START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
<!--StartFragment -->SELECT*INTOTABLEgt_spfli
FROMspfliUPTO30ROWS.
PERFORMlist_output.
PERFORMinit_timer.
*&---------------------------------------------------------------------*
*&USER-COMMAND
*&---------------------------------------------------------------------*
ATUSER-COMMAND.
IFsy-ucomm='RFSH'.
sy-lsind=sy-lsind-1.
PERFORMlist_output.
ENDIF.
*&---------------------------------------------------------------------*
*&FormLIST_OUTPUT
*&---------------------------------------------------------------------*
FORMlist_output.
DATA:ls_spfliLIKELINEOFgt_spfli.
NEW-PAGEWITH-TITLELINE-SIZE60.
WRITE:/5'CARRID',AT30'CONNID'.
LOOPATgt_spfli.
WRITE:/gt_spfli-carridUNDER'CARRID',
gt_spfli-connidUNDER'CONNID'.
ENDLOOP.
ENDFORM."LIST_OUTPUT
*&---------------------------------------------------------------------*
*&CLASSlcl_event_handlerDEFINITION
*&---------------------------------------------------------------------*
CLASSlcl_event_handlerDEFINITION.
PUBLICSECTION.
METHODS:
handle_timerFOREVENTfinishedOFcl_gui_timer.
ENDCLASS."lcl_event_handlerDEFINITION
*&---------------------------------------------------------------------*
*&CLASSlcl_event_handlerIMPLEMENTATION
*&---------------------------------------------------------------------*
CLASSlcl_event_handlerIMPLEMENTATION.
METHODhandle_timer.
DELETEgt_spfliINDEX1.
<!--StartFragment -->*SETUSER-COMMAND'RFSH'.
CALLMETHODcl_gui_cfw=>set_new_ok_code
EXPORTING
new_code='RFSH'.
CALLMETHODgo_timer->run"必须重新激活定时器
EXCEPTIONS
OTHERS=9.
ENDMETHOD."handle_timer
ENDCLASS."lcl_event_handlerIMPLEMENTATION
*&---------------------------------------------------------------------*
*&FormINIT_TIMER
*&---------------------------------------------------------------------*
FORMinit_timer.
<!--StartFragment --> CHECKgo_timerISINITIAL.
CREATEOBJECTgo_timer
EXCEPTIONS
OTHERS=9.
CREATEOBJECTgo_evt_hndl.
SETHANDLERgo_evt_hndl->handle_timerFORgo_timer.

go_timer->interval=3."设置间隔为3秒
CALLMETHODgo_timer->run"激活定时器
EXCEPTIONS
OTHERS=9.
ENDFORM."INIT_TIMER

来源:http://blog.chinaunix.net/u2/86821/showart_2057764.html

你可能感兴趣的:(.net,Blog,UP,Go)