Skip to content

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

Simple Transformation, Example of an ST Program

Symmetrical serialization and deserialization of a nested structure.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(out) = cl_demo_output=>new(
      )->begin_section( `Serialization` ).
    DATA source1(10) TYPE c VALUE 'Field1'.
    DATA source2(10) TYPE c VALUE 'Field2'.
    CALL TRANSFORMATION demo_st_program
      SOURCE root1 = source1
             root2 = source2
      RESULT XML DATA(xml).
    out->write_xml( xml ).

    out->next_section( `Deserialization` ).
    DATA result1 LIKE source1.
    DATA result2 LIKE source1.
    CALL TRANSFORMATION demo_st_program
      SOURCE XML xml
      RESULT root1 = result1
             root2 = result2.
    out->write_data( result1
      )->write_data( result2
      )->display( ).


The called transformation DEMO_ST_PROGRAM shows the principal structure of an ST program:

<?sap.transform simple?>
<tt:transform template="tmpl1"
  <tt:root name="ROOT1"/>
  <tt:root name="ROOT2"/>
  <tt:template name="tmpl1">
        <tt:value ref="ROOT1" />
        <tt:value ref="ROOT2" />

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 in serializations (or whose values are given to the data roots in deserializations) using the command tt:value. After the deserialization, result1 and result2 have the same content as source1 and source2.