AS ABAP Release 758, ©Copyright 2024 SAP SE. All rights reserved.
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 →rel_exp - Comparison Type of Byte-Like Data Objects
The following tables show the comparison types for comparisons between byte-like data 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.
Comparisons with Numeric Data Types
| - | xstring, x |
| decfloat16, decfloat34 | decfloat34 |
| f | f |
| p | p |
| int8 | int8 |
| i, s, b | i |
Length Adjustments
The comparison type p has 31 places and the number of decimal places for the operand of type p.
Hint
In conversions of byte-like data types to any numeric type except int8, only the last four bytes are respected. In the case of int8, the last 8 bytes are respected.
Example
Since the decimal places are lost in the conversion between numeric and byte-like types, the comparison for inequality is true.
TYPES pack TYPE p LENGTH 6 DECIMALS 2.
DATA pack TYPE pack VALUE '1234.56'.
FINAL(hex) = CONV xstring( pack ).
IF hex <> pack.
cl_demo_output=>display( |{ CONV pack( hex ) } <> { pack }| ).
ENDIF.
Comparisons with Character-Like Data Types
| - | xstring | x |
| string | string | string |
| c | string | c |
| n | p | p |
Length Adjustments
Example
The comparison uses the appropriate conversion rules to convert the hexadecimal content FF00 of hex to the string FF00, which is then compared with FFxx. The operands are not equal.
DATA hex TYPE x LENGTH 2.
DATA text TYPE c LENGTH 4.
hex = 'FF00'.
text = 'FFxx'.
IF hex <> text.
cl_demo_output=>display( |{ hex } <> { text } | ).
ENDIF.
Comparisons with Byte-Like Data Types
| - | xstring | x |
| xstring | xstring | xstring |
| x | xstring | x |
Length Adjustments
Example
Before the comparison, the appropriate conversion rules are used to convert the content of FFxx from text to the hexadecimal value FF00 in the helper variable hex_helper, and this value is compared with the content of hex.
DATA hex TYPE x LENGTH 2.
DATA text TYPE c LENGTH 4.
hex = 'FF00'.
text = 'FFxx'.
...
DATA hex_helper TYPE x LENGTH 2.
hex_helper = text.
IF hex = hex_helper.
cl_demo_output=>display( |{ hex } = { hex_helper } | ).
ENDIF.
Comparisons with Date Types, Time Types, or Time Stamp Types
| - | xstring, x |
| d, t | i |
| utclong | - |
Example
A hexadecimal number that is the result of the conversion of a valid date is equal to this date.
FINAL(date) = cl_demo_date_time=>get_user_date( ).
FINAL(hex) = CONV xstring( date ).
ASSERT hex = date.
cl_demo_output=>display( |{ date } { hex }| ).