SAP CONVERSION ENUMERATED



Get Example source ABAP code based on a different SAP table
  



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 must apply 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 c and string. In this case, the following conversion rule applies: The name and length of the enumerated constant or the component of the enumerated structure in which the current value of the source field is stored during the definition of the enumerated type, are assigned to the target field in uppercase letters.
This type of conversion to a character-like type can produce unexpected results. This is particularly common in operand positions in which implicit conversions take place.
BEGIN_SECTION VERSION 5 OUT For this reason, a conversion of this type produces a message from the extended program check if it is known statically. This message can be hidden using the pragma ##types.
END_SECTION VERSION 5 OUT
There is no reverse conversion rule for assignments between character-like source fields and enumerated variables. There is however, a special rule for the conversion operator CONV that enables the actual value of an enumerated object to be read in accordance with its basis type.
Assignments between enumerated data objects and data objects that are not enumerated data objects lead to a syntax error or the runtime error UC_OBJECTS_NOT_CONVERTIBLE.



Latest notes:

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 RTTC methods is never identical to a type defined using TYPES. A type description object created for an existing enumerated type using RTTC methods, however, describes this type.
Enumerated objects with enumerated types can be listed in all read positions where an implicit conversion to a character-like data type c or string takes place. They cannot be listed in operand positions where the operand must have a character-like data type.
For an enumerated object, the ABAP Debugger displays the name of the value that is converted into a character-like type.
When converting 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.
To assign a type-dependent initial value to enumerated variables, the statement CLEAR or a constructor expression VALUE #( ) can be used on the right side of an assignment.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The enumerated values of the enumerated structure p of an enumerated type planet are loaded into an internal table whose line type is the enumerated type. Each line is then converted to the character-like type string and this is added to the internal table planet_names.
ABEXA 00912
ABAP_EXAMPLE_END