• 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

    以上。

  • 相关阅读:
    从安装、管理到防御_阿里云安骑士全向测评
    云架构师前(钱)景这么好_我们该如何转型?这有两位阿里云云架构总监多年心得
    Infrastructure_as_Code——Kubernetes一键编排实践
    大中华地区(含港澳台)空气质量接口参加阿里云API_as_a_Service_大赛
    E-MapReduce集群启停HDFS/YARN服务
    云服务器ECS还原安全组规则功能介绍_安全组规则的备份与还原
    E-MapReduce集群中HDFS服务集成Kerberos
    FastReport中如何加入自定义函数
    查找算法总结
    八大排序算法总结
  • 原文地址:https://www.cnblogs.com/datie/p/11435862.html
Copyright © 2020-2023  润新知