ABAP Keyword Documentation → ABAP − Reference → Declarations → Declaration Statements → Data Types and Data Objects → Declaring Data Objects → DATA
DATA - TYPE, LIKE enum
Other versions:
7.31 | 7.40 | 7.54
Syntax
DATA enum_var { {TYPE enum_type}
| {LIKE enum_dobj} }
[VALUE val|{IS INITIAL}]
[READ-ONLY].
Effect
Declares an enumerated variable. An enumerated variable is declared by:
-
TYPEreference to an enumerated typeenum_type -
LIKEreference to a data object with enumerated type The following options are possible:
- Enumerated constants of an enumerated type
- Existing enumerated variables
The data type of an enumerated variable is its enumerated type. The enumerated type prescribes the enumerated values that an enumerated variable can contain. The assignment rules for enumerated types and the allowed operand positions for enumerated variables ensure that only valid enumerated values can be assigned to an enumerated variable.
The technical type of the enumerated value in an enumerated variable is the base type of the enumerated type. It is always a flat, elementary type with a maximum length of 16 bytes.
Note
For more information about using enumerated variables, see enumerated objects.
Example
In this example, three enumerated variables are declared:
-
color1by aTYPEreference to the enumerated typecolors -
color2by aLIKEreference tocolor1 -
color3by an inline declaration with reference to the enumerated typecolors
Each enumerated variable is assigned a valid value. The output shows the name of the assigned enumerated
constant for each enumerated variable, and the actual value. A special rule for the conversion operator CONV applies to the latter.
TYPES:
BEGIN OF ENUM colors,
red, blue, green,
END OF ENUM colors.
DATA color1 TYPE colors VALUE red.
DATA color2 LIKE color1 .
color2 = blue.
DATA(color3) = VALUE colors( ).
color3 = green.
cl_demo_output=>display(
|{ color1 }: { CONV i( color1 ) }\n| &&
|{ color2 }: { CONV i( color2 ) }\n| &&
|{ color3 }: { CONV i( color3 ) }| ).