ABAP Keyword Documentation → ABAP - Reference → Data Interfaces and Communication Interfaces → ABAP and XML → asXML - Canonical XML Representation → asXML, Examples of Mappings
asXML, Mapping of UUIDs
The example demonstrates the mapping of UUIDs onto XML schema data types.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: system_uuid TYPE REF TO if_system_uuid,
uuid TYPE xsduuid_char,
uuid1 TYPE xsduuid_char,
uuid2 TYPE xsduuid_char,
xml_xstring TYPE xstring,
exc_trafo TYPE REF TO cx_transformation_error,
exc_prev TYPE REF TO cx_root,
msg TYPE string.
FIELD-SYMBOLS <uuid> TYPE sysuuid_c32.
system_uuid = cl_uuid_factory=>create_system_uuid( ).
TRY.
uuid = system_uuid->create_uuid_c32( ).
ASSIGN uuid TO <uuid>.
CALL TRANSFORMATION id SOURCE uuid1 = uuid
uuid2 = <uuid>
RESULT XML xml_xstring.
cl_abap_browser=>show_xml( xml_xstring = xml_xstring ).
CATCH cx_uuid_error.
RETURN.
CATCH cx_transformation_error.
RETURN.
ENDTRY.
TRY.
CALL TRANSFORMATION demo_uuid SOURCE XML xml_xstring
RESULT uuid1 = uuid1
uuid2 = uuid2.
CATCH cx_transformation_error INTO exc_trafo.
MESSAGE exc_trafo TYPE 'I' DISPLAY LIKE 'E'.
IF exc_trafo->previous IS NOT INITIAL.
exc_prev = exc_trafo->previous.
MESSAGE exc_prev TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDTRY.
msg = `UUID1 = ` && uuid1.
MESSAGE msg TYPE 'I'.
msg = `UUID2 = ` && uuid2.
MESSAGE msg TYPE 'I'.
Description
In this example a UUID is created and passed with the data types XSDUUID_CHAR and SYSUUID_C32 to the predefined identity transformation ID. The UUID of the type XSDUUID_CHAR is recognized as such and converted into the corresponding XML schema data type. However, the UUID of the type SYSUUID_C32 is understood as a normal text field and passed unconverted following the corresponding rules for the mapping of elementary ABAP types.
An attempt is made at the deserialization of the XML document created with the help of the Simple Transformation DEMO_UUID, to convert both nodes into ABAP UUIDs of type XSDUUID_CHAR. This only works for the first node, which exists in the correct XML schema data type. In the case of the second node, which exists as unformatted text, an exception occurs.
The example shows that it is possible to work with XML schema data types without having to use conversions that you have programmed yourself. However, it also shows that when using XML schema data types it is important to pay attention to the correct assignment of data types.