zoukankan      html  css  js  c++  java
  • SAP状态栏中进程条实现[SAPGUI_PROGRESS_INDICATOR/CL_PROGRESS_INDICATOR]

    在执行一些数据量大的程序时,通常在程序下方的状态栏中加一个秒表用来显示进度,供用户了解程序运行到什么程度。实现方法有如下两种:

    1, SAPGUI_PROGRESS_INDICATOR

    常用而古老的方法,调用SAPGUI_PROGRESS_INDICATOR函数,指定函数的两个参数

    • percentage :百分比的数值,用来控制秒表的指针,0到100之间的数字。
    • text:状态栏显示的文本

    2017-02-13_14-45-57

    例子代码:

    选择画面输入循环次数,每次循环等待1秒,然后更新进步条的秒表指针和文本。

    REPORT ztest_progress.
    
    DATA: g_perc TYPE p.
    DATA: g_stxt TYPE string.
    DATA: g_sperc(3) TYPE c.
    
    PARAMETERS: p_times TYPE i DEFAULT  5.
    
    g_perc = 0.
    DO p_times TIMES.
      WAIT UP TO 1 SECONDS.
      CLEAR:g_stxt.
      g_perc = sy-index / p_times * 100.
      g_sperc = g_perc.
      CONCATENATE '已经完成了'  g_sperc '%' INTO g_stxt.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = g_perc     "百分比的数值,用来控制秒表的指针。
          text       = g_stxt.    "状态栏显示的文本。
    
    ENDDO.

    运行效果:

    2017-02-13_14-48-43

    2, CL_PROGRESS_INDICATOR

    SAP还提供了更方便快捷的类CL_PROGRESS_INDICATOR中的方法PROGRESS_INDICATE来实现这个进度条。

    2017-02-13_14-53-22

    这个类方法其实也是调用了SAPGUI_PROGRESS_INDICATOR函数,只不过是更友好的封装了一下。

    CL_PROGRESS_INDICATOR=>PROGRESS_INDICATE有两种显示模式:

    • 立即显示
    • 每隔10秒更新一下进度条

    通过参数i_output_immediately控制('X' = Display Progress Immediately ).

    立即显示的例子:

    PARAMETERS: p_times1 TYPE i DEFAULT  5. "Immediately
    
    DO p_times1 TIMES.
    
      cl_progress_indicator=>progress_indicate(
        EXPORTING
           i_text               = | Output immediately { sy-index } / { p_times1 } |
    *    i_msgid              = i_msgid    " Message Class (If I_TEXT is not transferred)
    *    i_msgno              = i_msgno    " Message Number (If I_TEXT is not transferred)
    *    i_msgv1              = i_msgv1    " Message Variable (Maximum of 50 Characters)
    *    i_msgv2              = i_msgv2    " Message Variable (Maximum of 50 Characters)
    *    i_msgv3              = i_msgv3    " Message Variable (Maximum of 50 Characters)
    *    i_msgv4              = i_msgv4    " Message Variable (Maximum of 50 Characters)
          i_processed          = sy-index    " Number of Objects Already Processed
          i_total              = p_times1    " Total Number of Objects to Be Processed
          i_output_immediately = abap_true    " X = Display Progress Immediately
    *  importing
    *    e_progress_sent      = e_progress_sent    " X = Progress Information Was Displayed
      ).
      WAIT UP TO 1 SECONDS.
    
    ENDDO.

    运行效果:

    2017-02-13_15-02-48

    每隔10秒显示的例子:

    PARAMETERS:  p_times1 TYPE i DEFAULT  20. "Once per 10 seconds.
    DO p_times1 TIMES.
    
      cl_progress_indicator=>progress_indicate(
        EXPORTING
           i_text               = | Output once per 10 seconds { sy-index } / { p_times1 } |
    *    i_msgid              = i_msgid    " Message Class (If I_TEXT is not transferred)
    *    i_msgno              = i_msgno    " Message Number (If I_TEXT is not transferred)
    *    i_msgv1              = i_msgv1    " Message Variable (Maximum of 50 Characters)
    *    i_msgv2              = i_msgv2    " Message Variable (Maximum of 50 Characters)
    *    i_msgv3              = i_msgv3    " Message Variable (Maximum of 50 Characters)
    *    i_msgv4              = i_msgv4    " Message Variable (Maximum of 50 Characters)
          i_processed          = sy-index    " Number of Objects Already Processed
          i_total              = p_times1    " Total Number of Objects to Be Processed
          i_output_immediately = abap_false    " X = Display Progress Immediately
    *  importing
    *    e_progress_sent      = e_progress_sent    " X = Progress Information Was Displayed
      ).
    
      WAIT UP TO 1 SECONDS.
    ENDDO.

    运行效果:

    2017-02-13_16-01-48

    以上。

  • 相关阅读:
    vault学习笔记
    rabbit搭建
    安装windows虚拟机
    Java Unknown named curve: 1.3.132.0.10
    文件操作,读文件或者写文件
    Java 中带参无返回值方法的使用
    Java 中无参无返回值方法的使用
    mac系统如何显示和隐藏文件
    解决JSP页面显示乱码
    Java 中无参带返回值方法的使用
  • 原文地址:https://www.cnblogs.com/datie/p/11435862.html
Copyright © 2011-2022 走看看