CLASS lcl_enum_colors DEFINITION FINAL.
PUBLIC SECTION.
* Parametertyp
TYPES: BEGIN OF ty_col_enum,
col_name TYPE string,
value TYPE i,
END OF ty_col_enum.
* Konstanten vom Typ des Parameters
CLASS-DATA: co_red TYPE ty_col_enum READ-ONLY.
CLASS-DATA: co_green TYPE ty_col_enum READ-ONLY.
CLASS-DATA: co_blue TYPE ty_col_enum READ-ONLY.
* Klassenkonstruktor
CLASS-METHODS:
class_constructor.
ENDCLASS.
CLASS lcl_enum_colors IMPLEMENTATION.
* Vorbelegung der Konstanten
* wird immer beim allerersten Aufruf eines Klassenelementes (Funktion, Variable, Konstante ...) ausgeführt
METHOD class_constructor.
co_red = VALUE #( col_name = 'COL_RED'
value = 1 ).
co_green = VALUE #( col_name = 'COL_GREEN'
value = 2 ).
co_blue = VALUE #( col_name = 'COL_BLUE'
value = 3 ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
* Variablen vom Typ Enum
DATA: lv_color_green TYPE lcl_enum_colors=>ty_col_enum.
DATA: lv_color_red TYPE lcl_enum_colors=>ty_col_enum.
DATA: lv_color_blue TYPE lcl_enum_colors=>ty_col_enum.
* Variablen mit konstanten Werten vorbelegen
lv_color_green = lcl_enum_colors=>co_green.
lv_color_red = lcl_enum_colors=>co_red.
lv_color_blue = lcl_enum_colors=>co_blue.
* Werteausgabe
WRITE: / lv_color_green-col_name, lv_color_green-value.
WRITE: / lv_color_red-col_name, lv_color_red-value.
WRITE: / lv_color_blue-col_name, lv_color_blue-value.
* Wertevergleich
IF lv_color_green = lcl_enum_colors=>co_green.
WRITE: / 'Ok.'.
ELSE.
WRITE: / 'Not ok.'.
ENDIF.
IF lv_color_green = lcl_enum_colors=>co_red.
WRITE: / 'Ok.'.
ELSE.
WRITE: / 'Not ok.'.
ENDIF.
IF lcl_enum_colors=>co_red = lcl_enum_colors=>co_blue.
WRITE: / 'Ok.'.
ELSE.
WRITE: / 'Not ok.'.
ENDIF.