5-Enumeration in ABAP 7.51

lightA simple use case of enumeration

 

 


A possible use case of enumeration objects is to compare and branch the program depending on the provided enumeration constants.The post shows a simple use case.


 

CODE:
CLASS lcl_enum DEFINITION.

PUBLIC SECTION.
TYPES: BEGIN OF ENUM t_vowels,
                    a,e,i,o,u,
               END OF ENUM t_vowels.
CLASS-METHODS: main IMPORTING iv_vowel TYPE t_vowels.

ENDCLASS.

CLASS lcl_enum IMPLEMENTATION.
METHOD main.
CASE iv_vowel.
      WHEN a.
               WRITE:/ ‘Vowel: A’.
      WHEN e.
              WRITE:/ ‘Vowel: E’.
     WHEN i.
             WRITE:/ ‘Vowel: I’.
     WHEN o.
            WRITE:/ ‘Vowel: O’.
     WHEN u.
              WRITE:/ ‘Vowel: U’.
     WHEN OTHERS.
ENDCASE.

ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
lcl_enum=>main( lcl_enum=>a ).
lcl_enum=>main( lcl_enum=>o ).


OUTPUT:

1.jpg


 

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s