二维码

[ooalv] ABAP在ALV工具栏显示一个计时器

Twilight发表于 2015-06-29 16:07Twilight 最后回复于 2015-06-29 16:07 [复制链接] 7775 0

其实就是调用一个类,刷新不断ALV界面,下面是来自Sariel的一段代码:
  1. *&---------------------------------------------------------------------*
  2. *& Write by Sariel
  3. *&---------------------------------------------------------------------*
  4. TYPE-POOLS slis.
  5. CLASS lcl_timer_receiver DEFINITION DEFERRED.
  6. DATA: BEGIN OF gt_data OCCURS 0,
  7.         flag TYPE string,
  8.       END OF gt_data.
  9. DATA: gv_text        TYPE smp_dyntxt.
  10. DATA: go_timer       TYPE REF TO cl_gui_timer,
  11.       go_timer_event TYPE REF TO lcl_timer_receiver.
  12. *----------------------------------------------------------------------*
  13. *       CLASS lcl_timer_receiver DEFINITION
  14. *----------------------------------------------------------------------*
  15. CLASS lcl_timer_receiver DEFINITION.
  16.   PUBLIC SECTION.
  17.     METHODS handle_finished FOR EVENT finished OF cl_gui_timer.
  18.   PRIVATE SECTION.
  19.     DATA: lv_mod TYPE i,
  20.           lv_int TYPE i,
  21.           lv_hh  TYPE numc2,
  22.           lv_mm  TYPE numc2,
  23.           lv_ss  TYPE numc2.
  24. ENDCLASS.                    "lcl_timer_receiver DEFINITION
  25. *----------------------------------------------------------------------*
  26. *       CLASS lc_timer_receiver IMPLEMENTATION
  27. *----------------------------------------------------------------------*
  28. CLASS lcl_timer_receiver IMPLEMENTATION.
  29.   METHOD handle_finished.
  30.     CALL METHOD go_timer->run.
  31.     lv_int = lv_int + 1.
  32.     lv_ss = lv_int MOD 60.
  33.     IF lv_int MOD 60 EQ 0.
  34.       lv_mm = lv_mm + 1.
  35.       lv_ss = 0.
  36.     ENDIF.
  37.     IF lv_int MOD 3600 EQ 0 .
  38.       lv_hh = lv_hh + 1.
  39.       lv_mm = 0.
  40.       lv_ss = 0.
  41.     ENDIF.
  42.     gv_text-text = lv_hh && ':' && lv_mm && ':' && lv_ss.
  43.   ENDMETHOD.                    "HANDLE_FINISHED
  44. ENDCLASS.                    "lc_timer_receiver IMPLEMENTATION
  45. *&---------------------------------------------------------------------*
  46. *&      Event  INITIALIZATION
  47. *&---------------------------------------------------------------------*
  48. INITIALIZATION.
  49.   gv_text-text = '00:00:00'.
  50. *&---------------------------------------------------------------------*
  51. *&      Event  START-OF-SELECTION
  52. *&---------------------------------------------------------------------*
  53. START-OF-SELECTION.
  54.   PERFORM frm_dsp_alv.
  55. *&---------------------------------------------------------------------*
  56. *&      Form  FRM_DSP_ALV
  57. *&---------------------------------------------------------------------*
  58. FORM frm_dsp_alv .
  59.   DATA: lt_fcat   TYPE slis_t_fieldcat_alv,
  60.         ls_fcat   TYPE slis_fieldcat_alv,
  61.         ls_layo   TYPE slis_layout_alv,
  62.         lt_events TYPE slis_t_event,
  63.         ls_events TYPE slis_alv_event.
  64.   gt_data-flag = 'SAP顾问圈'.
  65.   APPEND gt_data.
  66.   gt_data-flag = 'bbs.sapclub.cc'.
  67.   APPEND gt_data.

  68.   ls_fcat-fieldname = ls_fcat-seltext_s = 'FLAG'.
  69.   APPEND ls_fcat TO lt_fcat.
  70.   ls_events-name = slis_ev_caller_exit_at_start.  "= CALLER_EXIT
  71.   ls_events-form = slis_ev_caller_exit_at_start.
  72.   APPEND ls_events TO lt_events.
  73.   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  74.     EXPORTING
  75.       i_callback_program       = sy-repid
  76.       i_callback_pf_status_set = slis_ev_pf_status_set  "= PF_STATUS_SET
  77.       is_layout                = ls_layo
  78.       it_fieldcat              = lt_fcat
  79.       it_events                = lt_events
  80.     TABLES
  81.       t_outtab                 = gt_data
  82.     EXCEPTIONS
  83.       program_error            = 1
  84.       OTHERS                   = 2.
  85. ENDFORM.                    " FRM_DSP_ALV
  86. *&---------------------------------------------------------------------*
  87. *&      Form  CALLER_EXIT
  88. *&---------------------------------------------------------------------*
  89. FORM caller_exit USING u_exit TYPE slis_data_caller_exit.
  90.   CREATE OBJECT: go_timer, go_timer_event.
  91.   SET HANDLER go_timer_event->handle_finished FOR go_timer.
  92.   go_timer->interval = 1.
  93. ENDFORM.                    "CALLER_EXIT
  94. *&---------------------------------------------------------------------*
  95. *&      Form  SET_PF_STATUS
  96. *&---------------------------------------------------------------------*
  97. FORM pf_status_set USING t_extab TYPE slis_t_extab.
  98.   CALL METHOD go_timer->run.
  99.   SET PF-STATUS 'PFLIST' EXCLUDING t_extab.
  100. ENDFORM.                    " SET_PF_STATUS
复制代码

程序执行效果:
计时器.jpg
ALV工具栏请注意:
1、复制标准工具栏请参考:ALV报表复制程序标准工具栏
2、一定要定义成动态功能文本,GV_TEXT
动态功能文本.jpg

扩展阅读:SAP ALV自动刷新
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表