Get Example source ABAP code based on a different SAP table
CONV>, Conversion of Enumerated Types If the constructor expression CONV>> is used on enumerated types >, the following rules apply:
If the argument dobj> is an enumerated object> enum_dobj> and type> corresponds exactly to the base type> base_type> of the enumerated type, the result is the actual enumerated value> of the argument. ... CONV base_type( enum_dobj ) ...>
If type> is an enumerated type enum_type>, the following can be specified for the argument dobj>:
A data object of the same elementary type as the base type> of the enumerated type, with any length and number of decimal places
An expression allowed at this position whose result can be converted to the base type> of the enumerated type If the argument represents a valid enumerated value>, the result is a temporary enumerated variable> with this value. If the value is not valid, an exception CX_SY_CONVERSION_NO_ENUM_VALUE>> occurs. ... CONV enum_type( dobj ) ...> In all other cases, the normal conversion rules> apply to CONV>, where enumerated types can only be converted to the character-like types c> and string> and no types can be converted to enumerated types. Short form:> If the enumerated type of an enumerated object enum_dobj> has the same base type base_type> as any other enumerated type enum_type> and the enumerated value in the enumerated variable is also defined in enum_type>, it is possible, according to the above rules, to nest constructor expressions CONV> as follows: CONV enum_type( CONV base_type( enum_dobj ) )> The following short form can also be used for the nesting: CONV enum_type( enum_dobj )> The result is the enumerated value from enum_dobj> with the data type enum_type>.
Latest notes:
Using CONV> for enumerated types deviates from the rule that CONV> always behaves according to the regular conversion rules in assignments.
If the argument is an enumerated type with a character-like base type>, and this base type is specified as type>, the special rule above applies instead of the general conversion rule. That is, the enumerated value is returned, not the name.
Corresponding rules> apply to the lossless operator EXACT>> . NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 The first three assignments to the fields text1>, text2>, and text3> follow the regular conversion rules> for enumerated type to character-like. The result in each case is the name BLUE>. A direct assignment of the enumerated constant blue> to a field value1> of type i> is not possible. The conversion operator CONV> returns the actual enumerated value 1> for the base type i>. It is also not possible to assign the value 1 of type i> to an enumerated variable color1> with enumerated type color>. However, the conversion operator CONV> returns an enumerated value for the type color> if the argument has the base type i> and a allowed value. ABEXA 00965 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 The short form CONV animal( peach )> of the conversion operator CONV> acts like CONV animal( CONV i( peach ) )> It creates the value 2 from the enumerated constant peach> of the enumerated type fruit>, which can be assigned to the enumerated variable animal> with enumerated type animal>. The output shows the associated name DOG>. ABEXA 00966 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 The example shows the difference between the regular conversion rules> and using the conversion operator CONV> for a character-like base type:
In assignments to result1>, the regular conversion rules apply and the name SECOND> is assigned.
In assignments to result2>, the special rule for CONV > with the specification of the base type applies and the enumerated value aaaaaaaa> is assigned. ABEXA 00967 ABAP_EXAMPLE_END