Example of an XSL Transformation

This example shows the serialization of data objects in a string xmlstr using the identical transformation ID. A date field date, a time field time, and a data reference variable dref1 are serialized. The data reference variable points to an anonymous object reference variable, which in turn points to an object of the class c2. Objects serialized in this way can be stored persistently, for example, in a data cluster. After the objects are imported from where they are stored, they are deserialized into further data objects. Following deserialization, dref2 points to another anonymous reference variable, such as dref1. This anonymous data object and the instance of the class c2 to which it points are generated during the deserialization.

PROGRAM xmltst.

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    INTERFACES if_serializable_object.
  PROTECTED SECTION.
    DATA carriers TYPE TABLE OF scarr.
ENDCLASS.

CLASS c2 DEFINITION INHERITING FROM c1.
  PUBLIC SECTION.
    METHODS constructor.
  PRIVATE SECTION.
    DATA lines TYPE i.
    METHODS: serialize_helper
               EXPORTING count TYPE i,
             deserialize_helper
               IMPORTING count TYPE i.
ENDCLASS.

CLASS c2 IMPLEMENTATION.
  METHOD constructor.
    super->constructor( ).
    SELECT * UP TO 2 ROWS
           FROM  scarr
           INTO  TABLE carriers.
  ENDMETHOD.
  METHOD serialize_helper.
    count = LINES( carriers ).
  ENDMETHOD.
  METHOD deserialize_helper.
    lines = count.
  ENDMETHOD.
ENDCLASS.

DATA: oref   TYPE REF TO object,
      dref1  LIKE REF TO oref,
      xmlstr TYPE string,
      date   TYPE d,
      time   TYPE t,
      dref2  LIKE dref1.

...

CREATE DATA dref1 LIKE oref.
CREATE OBJECT dref1->* TYPE c2.

CALL TRANSFORMATION id
                    SOURCE xmldat = sy-datum
                           xmltim = sy-uzeit
                           ref  = dref1
                    RESULT XML xmlstr.
EXPORT obj = xmlstr TO DATABASE indx(hk)
                    ID 'OBJECT'.
...

IMPORT obj = xmlstr FROM DATABASE indx(hk) ID 'OBJECT'.
CALL TRANSFORMATION id
                    SOURCE XML xmlstr
                    RESULT xmldat = date
                           xmltim = time
                           ref = dref2.

The XML document generated in the serialization has the content described below. In this description, line breaks and indents have been added. The element values contains the asXML representations of the three transferred data objects. In the names X-MLDAT and X-MLTIM, "xml" has been replaced by "X-ML". The attribute href of the element REF uses the key "d1" to refer to the representation of the corresponding anonymous data object in the element heap. This uses the key "o3" to refer to the representation of the instance of the class c2, which is also in the element heap. This representation is divided into the object parts for the classes c1 and c2. The object part for c1 contains the representation of the double-line structured internal table carriers. The object part for c2 contains the representation for the output parameter count of the method SERIALIZE_HELPER.

<?xml version="1.0" encoding="iso-8859-1" ?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
  <asx:values>
    <X-MLDAT>2003-04-15</X-MLDAT>
    <X-MLTIM>14:57:53</X-MLTIM>
    <REF href="#d1" />
  </asx:values>
  <asx:heap
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:abap="http://www.sap.com/abapxml/types/built-in"
       xmlns:cls="http://www.sap.com/abapxml/classes/global"
       xmlns:dic="http://www.sap.com/abapxml/types/dictionary">
    <abap:refObject href="#o3" id="d1" />
    <prg:C2
      xmlns:prg="http://www.sap.com/abapxml/classes/program/XMLTST" <br>
      id="o3">
      <local.C1>
        <CARRIERS>
          <SCARR>
            <MANDT>000</MANDT>
            <CARRID>AA</CARRID>
            <CARRNAME>American Airlines</CARRNAME>
            <CURRCODE>USD</CURRCODE>
            <URL>http://www.aa.com</URL>
          </SCARR>
          <SCARR>
            <MANDT>000</MANDT>
            <CARRID>AB</CARRID>
            <CARRNAME>Air Berlin</CARRNAME>
            <CURRCODE>DEM</CURRCODE>
            <URL>http://www.airberlin.de</URL>
          </SCARR>
        </CARRIERS>
      </local.C1>
      <local.C2>
        <COUNT>2</COUNT>
      </local.C2>
    </prg:C2>
  </asx:heap>
</asx:abap>