ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Date and Time Processing → Time Stamps → Time Stamp Field with Time Stamp Type → Time Stamp Functions
utclong_diff - Time Stamp Function
Other versions:
7.31 | 7.40 | 7.54
Syntax
... utclong_diff( high = time_stamp2
low = time_stamp1 ) ...
Effect
This function calculates the time difference between the values of two time stamp fields time_stamp2
and time_stamp1
. The return value has the type decfloat34
and contains the precise difference in seconds rounded to seven decimal places. If the time stamp in
time_stamp2
is later than the time stamp in time_stamp1
,
the result is positive. If the values are identical, the result is 0. In all other cases, the result is negative.
Time stamp fields of the type utclong
containing valid time stamps must be passed to the arguments high
and low
. time_stamp2
and time_stamp1
are
time-stamp-like expression positions. An initial time stamp is handled like the lowest possible value of a time stamp.
Notes
- The system class CL_ABAP_UTCLONG contains a method DIFF with multiple output parameters for days, hours, minutes, and seconds (across which the time difference is spread) instead of just one return parameter.
- If the function
utclong_diff
is used as an operand of an arithmetic expression, the calculation typedecfloat34
is produced.
- If the function
utclong_diff
is used as the right side of an assignment or other operand positions in which the return value is converted, the decimal places are converted in accordance with the general conversion rules for source field typedecfloat34
, if necessary, and are not cut off. If the decimal places are to be cut off, the built-in functiontrunc
can be applied to the return value.
Example
Calculates the time interval in microseconds between successive time stamps from an internal table.
DATA time_stamps TYPE TABLE OF utclong WITH EMPTY KEY.
time_stamps = VALUE #( FOR i = 1 UNTIL i > 11
( utclong_current( ) ) ).
cl_demo_output=>write( time_stamps ).
TYPES diffs TYPE TABLE OF decfloat34 WITH EMPTY KEY.
cl_demo_output=>display(
VALUE diffs( FOR _ts IN time_stamps FROM 2 INDEX INTO i
( utclong_diff(
high = _ts
low = time_stamps[ i - 1 ] ) * 1000000 ) ) ).
Exceptions
Handleable Exceptions
CX_SY_CONVERSION_NO_DATE_TIME
-
Cause: A time stamp specified for
high
orlow
is invalid.
Runtime error:INVALID_UTCLONG
Non-Handleable Exceptions
-
Cause: An argument without a time stamp type is passed to
high
orlow
.
Runtime error:TCHK_TYPE_LOAD