Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  CONV - Conversion Operator →  CONV - Conversion of Enumerated Types 

Conversion Operator, Enumerated Types

This example demonstrates the use of the conversion operator CONV for enumerated types.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    TYPES:
      BEGIN OF ENUM planet,
        mercury,
        venus,
        earth,
        mars,
        jupiter,
        saturn,
        uranus,
        neptune,
      END OF ENUM planet.

    DATA number TYPE i.
    cl_demo_input=>request( CHANGING field = number ).

    TRY.
        DATA(planet) = CONV planet( CONV i( earth ) + number ).
        cl_demo_output=>display( planet ).
      CATCH cx_sy_conversion_no_enum_value.
        cl_demo_output=>display( 'Enter a number between -2 and 5' ).
    ENDTRY.

Description

The inner conversion operator CONV return the value of the enumerated constant earth in the base type i of the enumerated type planet. An entered value is added to this. Applying the conversion operator to the result determines a planet, which has the entered distance of earth.