Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  asXML - Canonical XML Representation →  asXML - Mapping of ABAP Data Types →  asXML - Mapping of Reference Variables and Objects →  asXML - Anonymous Data Objects 

Serialization to Heap or Embedded

This example demonstrates serializations of an anonymous data object to asXML and to asJSON.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(out) = cl_demo_output=>new(
      )->begin_section( `Serialization of Data Reference Variable` ).

    DATA dref TYPE REF TO string.
    dref = NEW #( `contents` ).

    out->begin_section( `Contents in Heap`
      )->begin_section( `asXML` ).
    CALL TRANSFORMATION id SOURCE dref = dref
                           RESULT XML DATA(xml_heap).
    out->write_xml( xml_heap
      )->next_section( `asJSON` ).
    DATA(writer_heap) = cl_sxml_string_writer=>create(
                          type = if_sxml=>co_xt_json ).
    CALL TRANSFORMATION id SOURCE dref = dref
                           RESULT XML writer_heap.
    out->write_json( writer_heap->get_output( )
      )->end_section( ).

    out->next_section( `Contents Embedded`
      )->begin_section( `asXML` ).
    CALL TRANSFORMATION id SOURCE dref = dref
                           RESULT XML DATA(xml_embedded)
                           OPTIONS data_refs = `embedded`.
    out->write_xml( xml_embedded
      )->next_section(`asJSON` ).
    DATA(writer_embedded) = cl_sxml_string_writer=>create(
                          type = if_sxml=>co_xt_json ).
    CALL TRANSFORMATION id SOURCE dref = dref
                           RESULT XML writer_embedded
                           OPTIONS data_refs = `embedded`.
    out->write_json( writer_embedded->get_output( )
      )->display( ).

Description

The identity transformation ID to serialize an anonymous data object to asXML and to asJSON, once with and once without the transformation option data_refs = embedded.