Skip to content

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

log_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.

Other versions: 7.31 | 7.40 | 7.54

Comparisons with Numeric Data Types

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

When the types string, c, and n are compared with whole numbers of the types int8, i, s, and b, a strict conversion to a comparison type does not take place. The content of the character-like operand must meet the prerequisites for a conversion to a numeric value, however this value must be within a value range and there must be no exception due to an overflow. A comparison of this type always produces the right result, regardless of the value range of the numeric data type.

Length Adjustments

The comparison type p has 31 decimal places and the number of places in the decimal portion in the operand of type p.

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

  • Operands with a different length of data type string never match. If the contents of the operands match for the length of the shorter operand, the shorter operand is smaller than the longer one. Otherwise the surplus places in the longer field are truncated on the right, and then the content is compared.

  • For comparisons between two operands of data type c, the shorter field is converted to the longer field, with blanks used as filler on the right.

  • For comparisons between two operands of data type n, the shorter field is converted to the longer field, with the character "0" used as filler on the left.

  • 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 truncated.

  • 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 truncated.

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

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.


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'. 
  WRITE / `'a' > 'Z'`. 
ELSE. 
  WRITE / `'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. 
  WRITE 'yes'. 
ELSE. 
  WRITE '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

  • When data type c is compared with x or xstring, the shorter field is adjusted to the length of the longer field after conversions from x to c or xstring to string. Blanks are used as filler on the right.

  • Lengths are not adjusted for comparisons between the data type string and x or xstring.