[ABAP] Klassenbasierter Enumerator (bis NW 7.50)

Bis NW 7.50 sind beispielsweise folgende Varianten möglich. Ab NW 7.51: Link

Variante 1: Integer

CLASS lcl_enum DEFINITION FINAL.

  PUBLIC SECTION.

    TYPES: ty_enum TYPE i.

    CLASS-DATA: standard TYPE ty_enum VALUE 1 READ-ONLY.
    CLASS-DATA: high TYPE ty_enum VALUE 2 READ-ONLY.
    CLASS-DATA: low TYPE ty_enum VALUE 3 READ-ONLY.

ENDCLASS.

CLASS lcl_enum IMPLEMENTATION.

ENDCLASS.

START-OF-SELECTION.

  DATA: lv_al TYPE lcl_enum=>ty_enum.

  lv_al = lcl_enum=>standard.

  CASE lv_al.
    WHEN lcl_enum=>standard.
      WRITE: / lcl_enum=>standard.
    WHEN lcl_enum=>high.
      WRITE: / lcl_enum=>high.
    WHEN lcl_enum=>low.
      WRITE: / lcl_enum=>low.
  ENDCASE.

Variante 2: String

CLASS lcl_enum DEFINITION FINAL.

  PUBLIC SECTION.

    TYPES: ty_enum TYPE string.

    CLASS-DATA: standard TYPE ty_enum VALUE 'STANDARD' READ-ONLY.
    CLASS-DATA: high TYPE ty_enum VALUE 'HIGH' READ-ONLY.
    CLASS-DATA: low TYPE ty_enum VALUE 'LOW' READ-ONLY.

ENDCLASS.

CLASS lcl_enum IMPLEMENTATION.

ENDCLASS.

START-OF-SELECTION.

  DATA: lv_al TYPE lcl_enum=>ty_enum.

  lv_al = lcl_enum=>low.

  CASE lv_al.
    WHEN lcl_enum=>standard.
      WRITE: / lcl_enum=>standard.
    WHEN lcl_enum=>high.
      WRITE: / lcl_enum=>high.
    WHEN lcl_enum=>low.
      WRITE: / lcl_enum=>low.
  ENDCASE.