Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  asXML - Canonical XML Representation →  asXML, Examples of Mappings 

asXML, Mapping of UUIDs

The example demonstrates the mapping of UUIDs to XML schema data types.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: uuid        TYPE xsduuid_char,
          uuid1       TYPE xsduuid_char,
          uuid2       TYPE xsduuid_char,
          exc_trafo   TYPE REF TO cx_transformation_error,
          exc_prev    TYPE REF TO cx_root.

    FIELD-SYMBOLS <uuid> TYPE sysuuid_c32.

    TRY.
        uuid = cl_uuid_factory=>create_system_uuid(
          )->create_uuid_c32( ).
        ASSIGN uuid TO <uuid>.
        CALL TRANSFORMATION id SOURCE uuid1 = uuid
                                     uuid2 = <uuid>
                               RESULT XML DATA(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.
    MESSAGE `UUID1 = ` && uuid1 TYPE 'I'.
    MESSAGE `UUID2 = ` && uuid2 TYPE 'I'.

Description

In this example, a UUID is created and passed to the predefined identity transformation ID with the data types XSDUUID_CHAR and SYSUUID_C32. The UUID of the type XSDUUID_CHAR is detected accordingly and converted to the associated XML schema data type. However, the UUID of the type SYSUUID_C32 is understood as a regular text field and passed unconverted in accordance with the corresponding rules for the mapping of elementary ABAP types.

When the new XML data is deserialized using the simple transformation DEMO_UUID, an attempt is made to convert both nodes to 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 is raised.

The example shows that it is possible to work with XML schema data types without having to use self-defined conversions. However, it also shows that when using XML schema data types it is important to pay attention to the correct assignment of data types.