ABAP - Keyword Documentation →  ABAP - Programming Language →  Program Flow Logic →  Expressions and Functions for Conditions →  Logical Expressions (log_exp) →  Comparison Expressions (rel_exp) →  rel_exp - Comparison Rules →  rel_exp - Comparing Elementary Data Types →  rel_exp - Comparison Type of Elementary Data Objects → 
Mail Feedback

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, no comparison is possible.

Comparisons with Numeric Data Types  

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

Example

The content of the syst_datum type data object date is converted to the number of days since 01/01/0001 in the comparison and compared with the content of days.

FINAL(date) = cl_demo_date_time=>get_user_date( ).
DATA(days) = CONV decfloat34( date ).
cl_demo_input=>request( CHANGING field = days ).

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

Comparisons with Character-Like Data Types  

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

Length Adjustments

Example

Comparison of any text string with the syst_datum type data object date.

FINAL(date) = cl_demo_date_time=>get_user_date( ).
DATA(text) = CONV string( date ).
cl_demo_input=>request( CHANGING field = text ).

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

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.

FINAL(ts) = utclong_current( ).
FINAL(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.

FINAL(time) = cl_demo_date_time=>get_user_time( ).
FINAL(hex) = CONV xstring( time ).

ASSERT hex = time.
cl_demo_output=>display( |{ time } { hex }| ).

Comparisons with Date Types, Time Types, or Time Stamp Types  

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

Example

The time generated through the addition of the value 86399 to the current time is compared with the current time. It is smaller than the current time.

FINAL(time) = cl_demo_date_time=>get_user_time( ).
IF CONV t( time + 86399 ) < time.
  cl_demo_output=>display( |CONV t( time + 86399 ) < time| ).
ENDIF.

Example

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

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