Skip to content

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 Calculation Expressions 

rel_exp - Comparison Type of String Expressions

String expressions can be used as operands in comparison expressions with the following:

It is possible to compare a string expression with a single operand of any elementary data type or with another string expression. With regard to the conversion of the elementary expression by string, two cases can be distinguished:

  • If a string expression is compared with an individual operand in a generic logical expression, the comparison type is string. The individual operand is implicitly regarded as an embedded expression of a string template and formatted as a text string before the comparison in accordance with the associated predefined format.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • The result of the formatting of an individual operand differs from the result of a simple conversion for some data types. An example is the type decfloat34.

  • The results of general logical expressions and logical expressions in WHERE conditions for internal tables may differ for comparisons with string expressions, since both the formatting and the comparison type play a role.

Example

This example demonstrates the effect of different comparison types. The first comparison is true, since the character-like operand is converted to the type of the numeric operand (in accordance with the rule for comparing character-like data types) and the number value is compared. However, the second comparison is also true, since the numeric operand is formatted as a text string and the internal representation of the code page used is compared-

ASSERT `02` > 1. 
ASSERT |02| < 1.

Example

The example demonstrates the effect of different formatting and different rules. All comparisons are true. An elementary operand of type decfloat34 is compared with a text string and a string expression. For the comparison with the text string, the left-hand side is also converted to the type string and the values of both sides are the same. For the comparison with the chain, the left-hand side is formatted differently and the values of both sides are different. The third comparison shows explicitly how the elementary operand is handled during the comparison with the chain. In contrast, the WHERE conditions LOOP statements convert both sides to the numeric comparison type decfloat34. The output shows the difference between simple conversion and formatting as an embedded expression.

DATA decf TYPE decfloat34 VALUE '0.00000004'. 
DATA itab LIKE TABLE OF decf. 
APPEND decf TO itab. 

ASSERT decf       =  CONV string( decf ). 
ASSERT decf       <> CONV string( decf ) && ``. 
ASSERT |{ decf }| <> CONV string( decf ) && ``. 

LOOP AT itab TRANSPORTING NO FIELDS 
             WHERE table_line = CONV string( decf ). 
ENDLOOP. 
ASSERT sy-subrc = 0. 

LOOP AT itab TRANSPORTING NO FIELDS 
            WHERE table_line = CONV string( decf ) && ``. 
ENDLOOP. 
ASSERT sy-subrc = 0. 

cl_demo_output=>display( 
  |CONV string( decf ):\t{ CONV string( decf ) }\n| && 
  |{ `|{ decf }|` }:\t\t{ decf }| ).