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 - Comparison of Enumerated Types

An operand with an enumerated type can only be compared with enumerated objects of the same enumerated type. There is no implicit conversion. The values of the operands are compared according to the rules that apply to the elementary base type of the enumerated type.

Other versions: 7.31 | 7.40 | 7.54


Note

An operand of an enumerated type cannot be compared directly with a character-like operand of the type c or string, even though there is a conversion rule for this case. In this case, helper variables or the conversion operator CONV can be used to execute an explicit conversion.


Example

In the first two comparisons, enumerated objects of the enumerated type number are compared with each other. The third comparison shows how an operand with an enumerated type can be converted so that it can be compared like a character.

TYPES: 
  BEGIN OF ENUM number, 
    n0, n1 , n2 , n3, n4, n5, n6, n7, n8, n9, 
  END OF ENUM number. 

DATA: num2 TYPE number VALUE n2, 
      num5 TYPE number VALUE n5. 

IF num2 < num5. 
  cl_demo_output=>write( |num2 < num5| ). 
ENDIF. 

IF num2 > n0. 
  cl_demo_output=>write( |num2 > n0| ). 
ENDIF. 

IF CONV string( n7 ) = `N7`. 
  cl_demo_output=>write( |CONV string( n7 ) = `N7`| ). 
ENDIF. 

cl_demo_output=>display( ).