SAP NetWeaver AS ABAP Release 752, ©Copyright 2017 SAP AG. All rights reserved.
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 Numeric Data Objects
The following tables show the comparison types for comparisons between numeric 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.
Note
If a decimal floating point number is involved in a comparison, the comparison is always made with the type decfloat34.
Comparisons with Numeric Data Types
| - | decfloat16, decfloat34 | f | p | int8 | i | s | b |
| decfloat16, decfloat34 | decfloat34 | decfloat34 | decfloat34 | decfloat34 | decfloat34 | decfloat34 | decfloat34 |
| f | decfloat34 | f | f | f | f | f | f |
| p | decfloat34 | f | p | p | p | p | p |
| int8 | decfloat34 | f | p | int8 | int8 | int8 | int8 |
| i | decfloat34 | f | p | int8 | i | i | i |
| s | decfloat34 | f | p | int8 | i | s | s |
| b | decfloat34 | f | p | int8 | i | s | b |
Value Ranges and Length Adjustments
Example
The result of this example comes as a surprise at first, but is caused by the fact that the value 0.15 cannot be represented exactly as a binary floating point number.
cl_demo_output=>display(
COND #( ...
WHEN CONV f( '0.15' ) = CONV decfloat34( '0.15' )
THEN `OK`
ELSE `Surprise, surprise ...` ) ).
Comparisons with Character-Like Data Types
| - | decfloat16, decfloat34 | f | p | int8 | i, s, b |
| string, c, n | decfloat34 | f | p | int8 | i |
Value Ranges and Length Adjustments
Example
Both comparisons are true. The comparison type of the first comparison is character-like and different strings do not match. The comparison type of the second comparison, on the other hand, is numeric due to the numeric literal -1. The string 1- contains a number in commercial notation, which is converted to an integer number with the value -1.
IF '-1' <> '1-'.
cl_demo_output=>write( |'-1' <> '1-'| ).
ENDIF.
IF -1 = '1-'.
cl_demo_output=>write( |-1 = '1-'| ).
ENDIF.
cl_demo_output=>display( ).
Comparisons with Byte-Like Data Types
| - | decfloat16, decfloat34 | f | p | int8 | i, s, b |
| xstring, x | decfloat34 | f | p | int8 | i |
Length Adjustments
The comparison type p has 31 places and the number of decimal places in the operand of type p.
Note
In conversions of byte-like data types to any numeric type except int8, all bytes are ignored except for the final four. In the case of int8, the final 8 bytes are respected.
Example
The comparison is true for all valid integer numbers of the type i. In the comparison, the byte string created from a number is converted to the original number.
DATA(num) = -2147483648.
cl_demo_input=>request( CHANGING field = num ).
DATA(hex) = CONV xstring( num ).
IF hex = num.
cl_demo_output=>display( hex ).
ENDIF.
Comparisons with Date/Time Types
| - | decfloat16, decfloat34 | f | p | int8 | i, s, b |
| d,t | decfloat34 | f | p | int8 | i |
Example
A valid time specified in sy-timlo is converted to the number of seconds since midnight in the comparisons. This number is compared with the number of seconds that corresponds to noon.
cl_demo_output=>display(
COND #( WHEN sy-timlo < 43200 THEN 'AM'
WHEN sy-timlo => 43200 THEN 'PM' ) ).