We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!
TYPES BEGIN OF ENUM enum_type
$[STRUCTURE struc$]
$[BASE TYPE dtype$].
TYPES val1 $[VALUE IS INITIAL$],
TYPES val2 $[VALUE val$],
TYPES val3 $[VALUE val$],
...
TYPES END OF ENUM enum_type
$[STRUCTURE struc$].
1. ... STRUCTURE struc
2. ... BASE TYPE dtype
3. ... VALUE ${IS INITIAL$}$|val
Definition of an enumerated type enum_type. An enumerated type describes enumerated variables, that is, elementary data objects that can only have certain enumerated values. These values are defined in the form of enumerated constants val1, val2, ... in the definition of the enumerated type as its value set. Enumerated variables and enumerated constants are both enumerated objects.
The statements for defining an enumerated type are introduced with a TYPES BEGIN OF ENUM statement and end with a TYPES END OF ENUM statement. Between these are TYPES statements for defining the value set of the enumerated type. At least one enumerated value must be defined. No other statements are allowed.
The definition of an enumerated type includes:
Special conversion rules apply to enumerated types that ensure only the enumerated values defined in the enumerated type can be assigned to an enumerated variable.
Definition of an enumerated type planet without using optional additions. The base type is i
and the enumerated values of the enumerated constants mercury, venus, ... are 0 to 7.
The enumerated variable planet is declared with the enumerated type planet. It can only be assigned the enumerated values defined in the enumerated type.
The enumerated type number comprises the same value set as the fixed values of the domain
DEMO_NUMBERS. This is checked by the assignment of each domain fixed value to an enumerated variable number of the enumerated type number. The necessary
conversions are performed.
... STRUCTURE struc
If the STRUCTURE addition is specified, no separate enumerated constant is created for each enumerated value val1, val2, .... Instead, a constant enumerated structure struc is declared in the namespace and validity area of the current context (procedure, class, program). The TYPES statements for the enumerated values val1, val2, ... define the components of the structure in the order they appear. They have the names val1, val2, ..., and each has the enumerated type enum. The components of the structure are special enumerated objects.
Definition of an enumerated type planet using the optional STRUCTURE addition. This declares
a constant enumerated structure p that can be addressed in the program, is declared with the
components mercury, venus, ... with the base type i and the enumerated values 0
to 7. The enumerated variable planet is declared with the enumerated type planet. It can only be assigned the enumerated values declared in the enumerated type.
... BASE TYPE dtype
The BASE TYPE addition defines an explicit base type dtype for the enumerated values of the value set of the enumerated type enum. All built-in and self-defined flat elementary data types that are no longer than 16 bytes can be specified. This includes the following built-in ABAP types and all dictionary types that are mapped to them:
If the BASE TYPE addition is not specified, the base type i is used.
Declaration of an enumerated type bool in a class boolean with explicit specification of the base type abap_bool from the type pool
ABAP. Unlike a variable of type abap_bool,
an enumerated variable of type boolean=>bool can only have the enumerated values abap_true
and abap_false. However, it is also not necessary to specify the base type explicitly in this example and usage of the class shown would also work with the implicit base type i.
... VALUE ${IS INITIAL$}$|val
The VALUE addition can be used to assign explicit enumerated values to the enumerated constants val1, val2, ... of the value set of the enumerated type enum. The VALUE addition must either be specified for all or for none of them. IS INITIAL must be specified for exactly one enumerated constant. An enumerated value val that matches the base type must be specified for all other enumerated constants.
The same applies to the VALUE addition as to the statements CONSTANTS and DATA:
Each enumerated value can only occur once within the value set of an enumerated type. If the VALUE addition is not specified, the enumerated values of the value set are set to 0, 1, 2, and so on, from left to right. If it is specified explicitly, the enumerated values do not have to be sorted by size.
In the following enumerated type, the planets are in alphabetical order. The explicit assignment of enumerated values, however, corresponds to their order in the solar system. Accordingly, the logical expression after ASSERT is true. The order of the components of the structure p, on the other hand, corresponds to the order of definition. The enumerated value is determined using the conversion operator CONV, to which a special rule applies.
Leave us your contact details and we will call you back. Fields marked with * are mandatory.
We offer holistic SAP solutions from a single source to shape digital change and develop new business areas.
Switzerland
Schaffhausen
Germany
Mannheim, Düsseldorf, Munich
USA
Haverhill
Greece
Thessaloniki