ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Enumerated Objects
Enumerated Objects, Use
This example demonstrates the use of enumerated types.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA: size TYPE cl_demo_wrap_browser=>size
VALUE cl_demo_wrap_browser=>sz-l,
format TYPE cl_demo_wrap_browser=>format
VALUE cl_demo_wrap_browser=>fmt-l.
cl_demo_input=>add_field( EXPORTING text = `Size (S, M, L, XL)`
CHANGING field = size ).
cl_demo_input=>request( EXPORTING text = `Format (L, P)`
CHANGING field = format ).
cl_demo_wrap_browser=>show( html = html
size = size
format = format ).
Description
The program calls the method SHOW of class CL_DEMO_WRAP_BROWSER . Two enumerated types are defined as follows in this class:
BEGIN OF ENUM size STRUCTURE sz,
s, m, l, xl,
END OF ENUM size STRUCTURE sz.
TYPES:
BEGIN OF ENUM format STRUCTURE fmt,
l, p,
END OF ENUM format STRUCTURE fmt.
The use of enumeration
structures means that the same name l
can occur twice. Method SHOW wraps method SHOW_HTML of class CL_ABAP_BROWSER:
cl_abap_browser=>show_html(
html_string = html
size = SWITCH #( size
WHEN sz-s THEN cl_abap_browser=>small
WHEN sz-m THEN cl_abap_browser=>medium
WHEN sz-l THEN cl_abap_browser=>large
WHEN sz-xl THEN cl_abap_browser=>xlarge )
format = SWITCH #( format
WHEN fmt-l THEN cl_abap_browser=>landscape
WHEN fmt-p THEN cl_abap_browser=>portrait )
buttons = abap_true ).
ENDMETHOD.
The input parameters size
and format format
of
the method have the same enumerated types and can only contain their enumerated values. These are mapped
to the corresponding constants of class CL_ABAP_BROWSER. These constants can be regarded as a workaround for real enumerated types, which were not available when CL_ABAP_BROWSER was developed.
Enumerated values can be specified for the size and format when the program is executed. The values
are passed internally to the program by deserializing the character-like values into the local enumerated
variables size
and format
. The exception for invalid
values is caught internally; here the enumerated variables are initialized, which corresponds to the values of the enumeration constants sz-s
and fmt-l
.