6-Enumeration in ABAP 7.51

lightEnumeration 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.


1

OUTPUT:

2


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.


3

OUTPUT:

4


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s