Ansicht
Dokumentation

ABENCONV_CONSTRUCTOR_ENUM - CONV CONSTRUCTOR ENUM

ABENCONV_CONSTRUCTOR_ENUM - CONV CONSTRUCTOR ENUM

General Data in Customer Master   CPI1466 during Backup  
This documentation is copyright by SAP AG.
SAP E-Book

CONV, Conversion of Enumerated Types

If the constructor expression CONV is used on enumerated types, the following rules apply:

... 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.

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.

Example

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.

Example

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.

Example

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.

Conversion Operator, Enumerated Types






Addresses (Business Address Services)   General Data in Customer Master  
This documentation is copyright by SAP AG.

Length: 6309 Date: 20240423 Time: 142638     sap01-206 ( 90 ms )