Conversion Rules for Enumerated Types
An enumerated type is a special elementary data type. Variables of this type are enumerated variables, which can only contain the enumerated values that are defined for the enumerated type. For this reason, source fields and target fields must be fully compatible in assignments between enumerated types, with one exception. The compatibility applies to the enumerated type itself. The base type of the enumerated type is not relevant.
The only exception to this rule is the assignment of source fields with enumerated types to character-like
variables of the types
string. In this case, the following conversion rule applies:
There is no reverse conversion rule for assignments between character-like source fields and enumerated variables.
7.31 | 7.40 | 7.54
- The following enumerated objects are possible as operands in assignments between enumerated types:
- Source fields can be enumerated constants or components of enumerated structures and enumerated variables.
- Target fields can be enumerated variables.
- To be compatible, the source field and target field must have exactly the same enumerated type. An enumerated type created using
is never identical to a type defined using
TYPES. A type description object created for an existing enumerated type using RTTC methods, however, does describe this type.
- Enumerated objects with enumerated types can be used in all
reading positions where an implicit conversion
to a character-like data type
stringtakes place. They cannot be used in operand positions where the operand has to have a character-like data type.
- The ABAP Debugger displays the name of the value, converted into a character-like type, for an enumerated object.
- When converted to a character-like type, the direct name of the enumerated constant is always used in the context of the declaration with a maximum of 30 characters. It is not prefixed with the name of an
enumerated structure with the structure component selector
-), nor with any class name with the class component selector (
=>). Therefore, the conversion of enumerated objects of different enumerated types can have the same result if the names of the enumerated constants match.
- The actual value of an enumerated object can be read, according to its
base type, using the conversion operator
The enumerated values of the enumerated structure
p of an enumerated type
planet are loaded into an internal table whose row type is the enumerated
type. Each row is then converted to the character-like type
string and this is added to the internal table
TYPES: BEGIN OF ENUM planet STRUCTURE p, mercury, venus, earth, mars, jupiter, saturn, uranus, neptune, END OF ENUM planet STRUCTURE p. DATA planets TYPE SORTED TABLE OF planet WITH UNIQUE KEY table_line. DO. ASSIGN COMPONENT sy-index OF STRUCTURE p TO FIELD-SYMBOL(<p>). IF sy-subrc <> 0. EXIT. ENDIF. planets = VALUE #( BASE planets ( <p> ) ). ENDDO. DATA planet_names TYPE SORTED TABLE OF string WITH UNIQUE KEY table_line. planet_names = VALUE #( BASE planet_names FOR enum IN planets ( CONV string( enum ) ) ). cl_demo_output=>display( planet_names ).