Enumeration run time information with new class- CL_ABAP_ENUMDESCR
Enumeration object details can be found by using new RTTI class-CL_ABAP_ENUMDESCR. It gives out the enumeration base type and the member names and its values. The post shows a simple demo on how to find the enumeration details using new RTTI class-CL_ABAP_ENUMDESCR.
CODE:
TYPES: BEGIN OF ENUM t_vowels, ” by default base type is “I”
a,e,i,o,u,
END OF ENUM t_vowels.
” Pass any one enum member to the method ( describe_by_data )
DATA(lr_enum_descr) = CAST cl_abap_enumdescr(
cl_abap_typedescr=>describe_by_data( a ) ).
WRITE:/ lr_enum_descr->kind.
WRITE:/ lr_enum_descr->type_kind.
WRITE:/ lr_enum_descr->base_type_kind.
ULINE.
LOOP AT lr_enum_descr->members ASSIGNING FIELD-SYMBOL(<fs_members>).
WRITE:/ <fs_members>-name, <fs_members>-value.
ENDLOOP.
OUTPUT:
CODE: Here defined another enum with base type as c. when base type is declared other than default it is mandatory to assign values to each enum member and first member should have a value as INITIAL.
TYPES: BEGIN OF ENUM t_vowels BASE TYPE c,
a VALUE IS INITIAL,
e VALUE ‘P’,
i VALUE ‘Q’,
o VALUE ‘R’,
u VALUE ‘S’,
END OF ENUM t_vowels.
DATA(lr_enum_descr) = CAST cl_abap_enumdescr(
cl_abap_typedescr=>describe_by_data( a ) ).
WRITE:/ lr_enum_descr->kind.
WRITE:/ lr_enum_descr->type_kind.
WRITE:/ lr_enum_descr->base_type_kind.
uline.
LOOP AT lr_enum_descr->members ASSIGNING FIELD-SYMBOL(<fs_members>).
WRITE:/ <fs_members>-name, <fs_members>-value.
ENDLOOP.
OUTPUT: