Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Simple Transformations →  ST - Structure of ST Programs 

ST - Example of an ST Program

The following simple example illustrates the basic structure of an ST program.

<tt:transform template="tmpl1"
  xmlns:tt="http://www.sap.com/transformation-templates"
  <tt:root name="ROOT1"/>
  <tt:root name="ROOT2"/>
  <tt:template name="tmpl1">
    <X0>
      <X1>
        <tt:value ref="ROOT1"/>
      </X1>
      <X2>
        <tt:value ref="ROOT2"/>
      </X2>
    </X0>
  </tt:template>
</tt:transform>

A single template, tmpl1, is defined as the main template. Two data roots, ROOT1 and ROOT2, are declared. The template contains two subelements, X1 and X2 of an element X0, which are given the values of the data roots during serialization (or whose values are given to the data roots during deserialization) using the tt:value command.

The following ABAP program, for example, could call the transformation:

DATA xml_string TYPE string.
DATA source1(10) TYPE c VALUE 'Field1'.
DATA source2(10) TYPE c VALUE 'Field2'.
CALL TRANSFORMATION ...
  SOURCE root1 = source1
         root2 = source2
  RESULT XML xml_string.
cl_abap_browser=>show_xml( xml_string = xml_string ).

The result in xml_string is then:

<X0>
  <X1>Field1</X1>
  <X2>Field2</X2>
</X0>

The following symmetrical reverse transformation would be possible using the above simple transformation:

DATA result1 LIKE source1.
DATA result2 LIKE source2.
CALL TRANSFORMATION ...
  SOURCE XML xml_string
  RESULT root1 = result1
         root2 = result2.

result1 and result2 then have the same contents as source1 and source2.

Other versions: 7.31 | 7.40 | 7.54