简体   繁体   English

获取平均时间 - ABAP

[英]Get the Mean of Time - ABAP

Is there a way in ABAP to get the mean of a time set? ABAP 中有没有办法获取时间集的平均值?

eg: An event occurred at the following times例如:事件发生在以下时间

  • 08:30 08:30
  • 08:45 08:45
  • 09:00 09:00

If you take the mean time the event occurred from the above data set, it;s 08:45.如果您从上述数据集中获取事件发生的平均时间,则为 08:45。 Is there a way to calculate this in ABAP?有没有办法在 ABAP 中计算这个?

The methods I used was to convert the time to Unix format.我使用的方法是将时间转换为 Unix 格式。 This mean that I could get the average by normal division.这意味着我可以通过正常除法得到平均值。

Following is the FM used to convert to Unix time;以下是用于转换为Unix时间的FM;

    CALL METHOD CL_PCO_UTILITY=>CONVERT_ABAP_TIMESTAMP_TO_JAVA(
      EXPORTING
        IV_DATE      = LD_IV_DATE
        "IV_MSEC      = LD_IV_MSEC
        IV_TIME      = LD_IV_TIME
      IMPORTING
        EV_TIMESTAMP = IN_UNIX_2 ).

Input: Date and Time Output: DateTime in Unix format输入:日期和时间输出:Unix 格式的日期时间

Then just add the average to 19700101 date.然后只需将平均值添加到 19700101 日期。

Can be done with the following FM;可以用下面的FM来完成;

  CALL FUNCTION 'TIMESTAMP_DURATION_ADD' "
    EXPORTING
      TIMESTAMP_IN  = 19700101000000            " timestamp     UTC Time Stamp in Short Form (YYYYMMDDhhmmss)
      TIMEZONE      = 'UTC'                     " timezone      Time Zone
      UNIT          = 'S'                       " t006-msehi    Unit of measurement
      DURATION      = IN_RUN_AVG
    IMPORTING
      TIMESTAMP_OUT = IN_AVG_FINAL              " timestamp     UTC Time Stamp in Short Form (YYYYMMDDhhmmss)
    .  "  TIMESTAMP_DURATION_ADD

This method can be used since the Unix time is time count in seconds from 1970/01/01可以使用此方法,因为 Unix 时间是以秒为单位的时间计数,从 1970/01/01 开始

do this:做这个:

data: lv_clock type sy-uzeit, lv_type type sy-uzeit.数据:lv_clock 类型 sy-uzeit,lv_type 类型 sy-uzeit。

Get time.抓紧时间。 lv_time = sy-uzeit. lv_time = sy-使用时间。

your code...你的代码...

get time.得到时间。 lv_clock = sy-uzeit. lv_clock = sy-使用时间。

lv_clock = lv_clock - lv_time. lv_clock = lv_clock - lv_time。

write: / lv_clock.写:/lv_clock。

Or, you can use the function 'TIMESTAMP_DURATION_ADD'或者,您可以使用 function 'TIMESTAMP_DURATION_ADD'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM