Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Expressions and Functions for Conditions →  log_exp - Logical Expressions →  rel_exp - Comparison Expressions →  rel_exp - Comparison Rules →  rel_exp - Comparing Elementary Data Types →  rel_exp - Comparison Type of Elementary Data Objects 

rel_exp - Comparison Type of Date Fields, Time Fields, and Time Stamp Fields

The following tables show the comparison types for comparisons between date/time types and other data types. If the type of an operand is not the same as the comparison type, it is converted to this type. The comparison rules for the comparison types determine how the comparison is performed. If no comparison type is specified for a combination, then no comparison is possible.

Other versions: 7.31 | 7.40 | 7.54

Comparisons with Numeric Data Types

- d, t utclong
decfloat16, decfloat34 decfloat34 -
f f -
p p -
int8 int8 -
i, s, b i -


Example

During the comparisons, the content of the system field sy-datlo is converted to the number of days since 01/01/0001 and compared with the content of days.

DATA(days) = CONV decfloat34( sy-datlo ). 
cl_demo_input=>request( CHANGING field = days ). 

cl_demo_output=>display( 
  COND #( WHEN days > sy-datlo THEN |{ days } > { sy-datlo }| 
          WHEN days < sy-datlo THEN |{ days } < { sy-datlo }| 
                               ELSE |{ days } = { sy-datlo }| ) ).

Comparisons with Character-Like Data Types

- d, t utclong
string string utclong
c c utclong
n n -

Length Adjustments

  • For comparisons between data types c, n, or string on the one hand and d on the other, the longer field is truncated on the right to the length of the shorter field, as long as only blanks are cut off.

  • For comparisons between data types c or n on the one hand and t on the other, the longer field is truncated on the right to the length of the shorter field, as long as only blanks are cut off.

  • Lengths are not adjusted for comparisons between the data type string and the data type t.

Example

Comparison of any text string with the content of the system field sy-datlo.

DATA(text) = CONV string( sy-datlo ). 
cl_demo_input=>request( CHANGING field = text ). 

cl_demo_output=>display( 
  COND #( WHEN text > sy-datlo THEN |{ text } > { sy-datlo }| 
          WHEN text < sy-datlo THEN |{ text } < { sy-datlo }| 
                               ELSE |{ text } = { sy-datlo }| ) ).

Example

A time stamp formatted as a character string with the formatting option TIMESTAMP can be converted to utclong and compared with a time stamp field. Instead of ISO, SPACE could also be specified.

DATA(ts) = utclong_current( ). 
DATA(text) = |{ ts TIMESTAMP = ISO }|. 
ASSERT ts = text.

Comparisons with Byte-Like Data Types

- d, t utclong
x, xstring i -


Example

A hexadecimal number that is the result of the conversion of a valid time is equal to this time.

DATA(hex) = CONV xstring( sy-timlo ). 

ASSERT hex = sy-timlo. 
cl_demo_output=>display( |{ sy-timlo } { hex }| ).

Comparisons with Date Types/Time Types/Time Stamp Types

- d t utclong
d d - -
t - t -
utclong - - utclong


Example

The time generated by adding the value 86399 to the current time is compared with the current time. It is smaller than the current time.

IF CONV t( sy-timlo + 86399 ) < sy-timlo. 
  cl_demo_output=>display( |CONV t( sy-timlo + 86399 ) < sy-timlo| ). 
ENDIF.

Example

A later time stamp is always greater than an earlier time stamp.

DATA(ts) = utclong_current( ). 
WAIT UP TO 1 SECONDS. 
ASSERT utclong_current( ) > ts.