原理
利用计时器类CL_GUI_TIMER,不断的循环调用,步骤如下
- 实例化定时器,并针对定时器的finished事件进行监听
- 在at selection output处更改屏幕元素的属性和值,同时开始运行定时器
- 定时结束,触发finished事件,通过设置function code, 屏幕逻辑流再次回到at selection output。
个人猜测:自定义屏幕和ALV,也可以实现定时刷新,实现循环调用定时器以及触发PBO即可;但是看了某些文章,好像不推荐使用这个定时器类,原因未知,ALV也不是UI5开发的那种看板,我觉得定时刷新没啥意思,花里胡哨。
参考代码
parameters : p_time type i default 3.
class lcl_event definition.
public section.
methods m_timer_finished for event finished of cl_gui_timer.
endclass.
class lcl_event implementation.
method m_timer_finished.
" cl_gui_cfw=>set_new_ok_code(
" exporting
" new_code = 'REFR').
"触发新的屏幕逻辑流,实现屏幕刷新
call function 'SAPGUI_SET_FUNCTIONCODE'
exceptions
others = 0.
endmethod. "handle_finished
endclass. "lcl_event IMPLEMENTATION
initialization.
data(lo_timer) = new cl_gui_timer( ).
lo_timer->interval = 1.
data(lo_event) = new lcl_event( ).
set handler lo_event->m_timer_finished for lo_timer.
at selection-screen output.
if lo_timer is bound.
lo_timer->run( ).
p_time = p_time - 1.
endif.
if p_time le 0.
lo_timer->cancel( ).
endif.