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

rel_exp - Comparing Character-Like Data Types

The following tables show the comparison types for comparisons between character-like data types and other data types. If the type of an operand is not the same as the comparison type, then it is converted to this type. If no comparison type is specified for a combination, then no comparison is possible.

Comparisons with Numeric Data Types

- string, c, n d,t
decfloat34 decfloat34 decfloat34
decfloat16 decfloat34 decfloat34
f f f
p p p
i i i
s i i
b i i

Value Ranges and Length Adjustments

Comparisons with Character-Like Data Types

- string c n d t
<string string string p string string
c string c p c c
n p p n n n
d string c n d -
t string c n - t

Length Adjustments

Note

For comparisons between text fields of the type c and text strings of the type string, note that trailing blanks are ignored by conversions from c to string. This can have unexpected results. The conversion operator CONV can be used here to force other comparison types (see the example after the link).

Example

In the following comparison, the comparison type is c and the comparison takes places in the current code page, in accordance with the binary representation. In most code pages, "a" is greater than "Z". See also the example for CONVERT TEXT.

IF 'a' > 'Z'.
  cl_demo_output=>display_text( `'a' > 'Z'` ).
ELSE.
  cl_demo_output=>display_text( `'a' < 'Z'` ).
ENDIF.

Example

The following comparison is false, which is probably unexpected. The value returned by boolc has the type string and includes a blank, whereas the constant abap_false has the type c. For the comparison, the value of abap_false is converted to an empty string, since the blank it contains is ignored.

IF boolc( 1 = 2 ) = abap_false.
  cl_demo_output=>display_text( 'yes' ).
ELSE.
  cl_demo_output=>display_text( 'no' ).
ENDIF.

Comparisons with Byte-Like Data Types

- string c n d,t
xstring string string p i
x string c p i

Length Adjustments