Before release 7.51, there was no native support for enums in ABAP, but you can simulate the same behavior with a few simple steps:
- Create your "enum" class;
- Set the instance constructor to private;
- Add the static attributes of
TYPE REF TO <your_class>
for each "enum object"; - Create a
CLASS_CONSTRUCTOR
and instantiate each "enum object" with the desired properties.
For instance, if you have a status
enum, you may have a CL_STATUS
class with CL_STATUS=>APPROVED
and CL_STATUS=>REJECTED
enum objects.
Example:
REPORT z_test.
CLASS cl_status DEFINITION
CREATE PRIVATE.
PUBLIC SECTION.
CLASS-DATA: approved TYPE REF TO cl_status,
rejected TYPE REF TO cl_status.
CLASS-METHODS class_constructor.
ENDCLASS.
CLASS cl_status IMPLEMENTATION.
METHOD class_constructor.
approved = NEW cl_status( ).
rejected = NEW cl_status( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA status TYPE REF TO cl_status.
status = cl_status=>approved.
CASE status.
WHEN cl_status=>approved.
MESSAGE 'approved' TYPE 'I'.
WHEN cl_status=>rejected.
MESSAGE 'rejected' TYPE 'I'.
ENDCASE.