2008年(49)
分类:
2008-06-24 13:20:57
该程序通过 RFC_PING_AND_WAIT和手动触发报表的user command事件,来完成每隔一个时间段报表刷新一次。(有两个按钮,t-code分别是start和 end)
RFC_PING_AND_WAIT 实际不做任何事,只是实现一个时间等待,把调用它的线程阻断一段时间。
CALL FUNCTION 'RFC_PING_AND_WAIT'
STARTING NEW TASK '001'
PERFORMING on_finished ON END OF TASK
EXPORTING
seconds = 3
busy_waiting = ' '.
starting new task 'XXXXX' 表示函数在子线程里进行,即异步。
PERFORMING xxxxx ON END OF task 是指定子线程的回调函数(在子线程里执行,所以子线程里不能调用窗体等,如message)虽然可以调用ALV,但ALV出现之后回阻断当前线程。所以不能做到ALV每隔一段时间刷新。
注意:回调函数是在子线程里调用,所以回调函数中不能出现任何和画面有关的代码,如ALV,write语句,message等等,只能有数据处理代码和 SET USER-COMMAND这种事件触发代码。
REPORT z_temp_demo8.
SET PF-STATUS 'MY_STATUS'.
DATA: opend(1).
DATa: BEGIN OF itab occurs 0,
name(10),
END OF itab.
START-OF-SELECTION.
WRITE:/ '.........'.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'START'.
IF opend <> 'X'.
opend = 'X'.
PERFORM trigger.
ENDIF.
WHEN 'END'.
opend = 'Z'.
WHEN 'TRIGGER'.
IF opend = 'X'.
PERFORM trigger.
ENDIF.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form on_finished
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->TASKNAME text
*----------------------------------------------------------------------*
FORM on_finished USING taskname.
SET USER-COMMAND 'TRIGGER'.
ENDFORM. "when_finished
*&---------------------------------------------------------------------*
*& Form triger
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM trigger.
write: / sy-uzeit.
sy-lsind = 0.
CALL FUNCTION 'RFC_PING_AND_WAIT'
STARTING NEW TASK '001'
PERFORMING on_finished ON END OF TASK
EXPORTING
seconds = 3
busy_waiting = ' '.
ENDFORM. "triger