Get Example source ABAP code based on a different SAP table
• BEGIN OF ENUM TYPES • END OF ENUM TYPES
TYPES>, BEGIN OF ENUM enum_type> Short Reference >
ABAP_SYNTAX 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$].>
ABAP Addition 1 ... STRUCTURE struc> 2 ... BASE TYPE dtype> 3 ... VALUE ${IS INITIAL$}$|val>
What does it do? 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:
Name enum_type>>. The enumerated type, like any data type defined with TYPES>, can be used with its name enum_type>, for example, after a TYPE> addition or in suitable constructor expressions>. It acts as a complete type in typing> of field symbols or actual parameters.
Base type> The base type> determines the data type of the enumerated constants in the value set of the enumerated type and the technical type of enumerated variables.
If the BASE TYPE> addition is not specified, the default base type is i>.
The BASE TYPE> addition can be used to explicitly define the base type; all flat elementary data types, including CDS simple types>, that are no longer than 16 bytes can be specified for dtype>.
Enumerated constants Each enumerated value val1>, val2>, ... is declared by a separate TYPES> statement. However, it does not define a data type, and an enumerated constant that contains the enumerated value is defined instead. The data type of each constant is the enumerated type enum >. The technical data type for the enumerated value is the base type. Each name val1>, val2>, ... must adhere strictly to the naming conventions>.
If the STRUCTURE> addition is not specified, each enumerated constant is a separate data object with the respective name val1>, val2>, .... The enumerated constants are declared in the namespace and validity area of the current context (procedure, class, program), and each name must be unique within the enumerated type as well as in the entire current context.
The STRUCTURE> addition creates a constant structure struc > with the components val1>, val2>, ... as an enumerated structure> in the current context. The enumerated values are stored in the components of this structure. The individual enumerated constants or the constant enumerated structure can be used> in certain read positions. In classes they belong, like all constants, to the static attributes and can be addressed accordingly using the component selectors =>> and ->>.
Enumerated values The enumerated values, that is, the content of the enumerated constants, are determined as follows:
If the VALUE> addition is not specified, the base type must be numeric and the enumerated constants val1>, val2>, and so on are filled with the enumerated values 0, 1, and so on, from left to right.
The VALUE> addition is used to assign explicit type-compliant enumerated values to the enumerated constants. The addition must be specified either for all or for none of the enumerated constants val1>, val2>, .... The IS INITIAL> addition must be specified for exactly one constant. Each enumerated value must be unique within the enumerated type. The order of the specified values is not important. For non-numeric base types, the VALUE> addition must be specified for each enumerated constant. 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>.
Latest notes:
If STRUCTURE> is not specified, an elementary type enum> is declared, and a single data object is declared for each enumerated value of the value set. Each TYPES> statement for defining an enumerated value val> has a similar effect to a declaration. CONSTANTS val TYPE enum_type VALUE ...>
An enumerated type is always an elementary data type and is included in the generic type simple>>. Likewise, the associated type description class CL_ABAP_ENUMDESCR>> is a subclass of CL_ABAP_ELEMDESCR>>.
The statements for defining an enumerated type are usually summarized in a chained statement>.
In a type pool>, the names of the enumerated constants, in addition to the type name enum_type>, must have the name of the type pool as a prefix.
Enumerated types are currently only supported in the ABAP language:
Enumerated types cannot currently be defined globally in the ABAP Dictionary. The direct import of allowed values from database tables is currently not supported. NON_V5_HINTS
Enumerated types are not currently supported by classic dynpros>.
For more information about usage, see enumerated objects>. ABAP_HINT_END
ABAP_EXAMPLE_VX5 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. ABEXA 00717 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 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. ABEXA 00718 ABAP_EXAMPLE_END • STRUCTURE TYPES
ABAP Addition
What does it do? 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>.
Latest notes:
If STRUCTURE> is specified, an elementary type enum> and a structured data object struc> are declared. With regard to the structure, the TYPES> statement has the following effect: CONSTANTS: BEGIN OF struc, val1 TYPE enum_type VALUE ... val2 TYPE enum_type VALUE ... val3 TYPE enum_type VALUE ... ... END OF struc.>
If STRUCTURE> is specified, the enumerated values of the enumerated type can be addressed using struc-val1>, struc-val2 >, .... Additionally, the structure can be addressed as a whole, with the rules for structures whose components have enumerated types.
The enumerated type enum> is an elementary type, even if STRUCTURE> is specified.
In a type pool>, the name of the enumerated structure, in addition to the type name enum_type>, must have the name of the type pool as a prefix. This is not necessary for the components. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 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. ABEXA 00719 ABAP_EXAMPLE_END • BASE TYPE TYPES
ABAP Addition
What does it do? 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 user-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:
All numeric types>
The character-like types> c> and n> with a maximum length of 8, but no text strings
the byte-like type> x> with a maximum length of 16, but no byte strings
The date types and time types> If the BASE TYPE> addition is not specified, the base type i > is used.
Latest notes:
The base type describes how each enumerated value of the value set is stored internally, but it is not the type of the associated enumerated constant that can be used in a program. Its type is the enumerated type enum> itself.
If an explicitly specified base type is not numeric, the VALUE> addition must be used for each enumerated value of the value set.
The explicit definition of a base type other than i> is usually unnecessary.
To access an enumerated value of the value set in accordance with its representation in the base type, the conversion operator CONV> can be used. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 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>. ABEXA 00720 ABAP_EXAMPLE_END • VALUE TYPES • IS INITIAL TYPES
ABAP Addition
What does it do? 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.
If the base type is numeric, VALUE> can be specified.
If the base type is not numeric, VALUE> must be specified. The same applies to the VALUE> addition as to the statements CONSTANTS>> and DATA>>:
IS INITIAL> generates the initial value of the base type.
val> can either be specified as a literal or as an already defined constant. 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.
ABAP_EXAMPLE_VX5 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. ABEXA 00721 ABAP_EXAMPLE_END