Simple Transformation Example

Serialization of a nested structure. In the following ABAP program section, a nested structure struc1 is serialized to xml_string with the Simple Transformation st_trafo and deserialized with the same transformation.

DATA: BEGIN OF struc1,
        col1 TYPE c LENGTH 10 VALUE 'ABCDEFGHIJ',
        col2 TYPE i VALUE 111,
        BEGIN OF struc2,
          col1 TYPE d VALUE '20040126',
          col2 TYPE t VALUE '084000',
        END OF struc2,
      END OF struc1.

DATA: xml_string TYPE string,
      result     LIKE struc1.

TRY.

    CALL TRANSFORMATION st_trafo
      SOURCE para = struc1
      RESULT XML xml_string.

    ...

    CALL TRANSFORMATION st_trafo
      SOURCE XML xml_string
      RESULT para = result.

  CATCH cx_st_error.

    ...

ENDTRY.

The Simple Transformation st_trafo has the following form:


<tt:transform template="temp"
    xmlns:tt="http://www.sap.com/transformation-templates"
    version="0.1">

  <tt:root name="PARA"/>

  <tt:template name="temp">
    <X>
      <X1>
        <tt:value ref="PARA.COL1" />
      
      <X2>
        <tt:value ref="PARA.COL2" />
      
      <X3>
        <X1>
          <tt:value ref="PARA.STRUC2.COL1" />
        
        <X2>
          <tt:value ref="PARA.STRUC2.COL2" />
        
      
    </X>
  

The transformation consists of a Template temp that defines the structure of the XML document and establishes relationships between value nodes and components of the structure. The result of the transformation is as follows (line breaks and indentations were inserted for clarification purposes):

<X>
  <X1>ABCDEFGHIJ
  <X2>111
  <X3>
    <X1>2004-01-26
    <X2>08:40:00
  
</X>

The conversion of elementary data types is the same as for asXML. The reverse transformation generates the same content in the structure result as in struc1.