ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Enumerated Objects
Enumerated Objects, Deserialization
This example demonstrates how a dynamically created XML file is deserialized to an enumerated object.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA input TYPE c LENGTH 3 VALUE 'XL'.
cl_demo_input=>request( CHANGING field = input ).
input = to_upper( input ).
TYPES:
BEGIN OF ENUM size,
s, m, l, xl, xxl,
END OF ENUM size.
DATA(xml) =
cl_abap_conv_codepage=>create_out( )->convert(
`<asx:abap version="1.0"` &&
` xmlns:asx="http://www.sap.com/abapxml">` &&
` <asx:values>` &&
` <ENUM>` && input && `</ENUM>` &&
` </asx:values>` &&
`</asx:abap>` ) ##no_text.
DATA size TYPE size.
TRY.
CALL TRANSFORMATION id
SOURCE XML xml
RESULT enum = size.
CATCH cx_transformation_error INTO DATA(exc).
cl_demo_output=>display( exc->previous->get_text( ) ).
RETURN.
ENDTRY.
cl_demo_output=>display( |Name: { size
}\nValue: { CONV i( size ) }| ).
FIELD-SYMBOLS <fs> TYPE size.
ASSIGN (input) TO <fs>.
IF sy-subrc <> 0.
cl_demo_output=>display( `Wrong name` ).
RETURN.
ENDIF.
ASSERT size = <fs>.
Description
The composition of a a byte string means that it can represent an XML file in asXML format for an enumerated
object of the enumerated type size
and is deserialized as such. Any invalid entries raise an exception.
Next, the dynamic assignment of a name to a field symbol is displayed. This is successful but the prerequisite
here is that the enumerated type size
is known in the current context. However, the XML file can be serialized in an enumerated object without static knowledge of the enumerated type.