Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  ST - Simple Transformations →  ST - Examples 

Simple Transformation, Internal Table

The example demonstrates the serializing of an internal table.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: BEGIN OF carrier_wa,
            carrid   TYPE scarr-carrid,
            carrname TYPE scarr-carrname,
            url      TYPE scarr-url,
          END OF carrier_wa,
          carrier_tab LIKE TABLE OF carrier_wa,
          xml  type xstring,
          html type string.

    SELECT *
           FROM scarr
           INTO CORRESPONDING FIELDS OF TABLE @carrier_tab.

    CALL TRANSFORMATION demo_st_table
                        SOURCE carriers = carrier_tab
                        RESULT XML xml.
    cl_demo_output=>write_xml( xml ).

    CALL TRANSFORMATION demo_st_table
                        SOURCE carriers = carrier_tab
                        RESULT XML html
                        OPTIONS xml_header = 'NO'.
    cl_demo_output=>write_html( html ).

    cl_demo_output=>display( ).

Description

An internal table, carrier_tab, is filled with data from the database table SCARR and is transformed to XML using the simple transformation DEMO_ST_TABLE. The ST program is as follows:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="CARRIERS"/>
  <tt:template>
    <html>
      <body>
        <h2>Carriers:</h2>
        <table border="2">
          <tr>
            <td><b>Id</b></td>
            <td><b>Name</b></td>
            <td><b>Homepage</b></td>
          </tr>
          <tt:loop ref=".CARRIERS">
            <tr><td>
                <tt:value ref="$ref.carrid"/>
              </td>
              <td>
                <tt:value ref="$ref.carrname"/>
              </td>
              <td>
               <a><tt:attribute name="href" value-ref="$ref.url" />
                 <tt:value ref="$ref.url"/></a>
              </td>
            </tr>
          </tt:loop>
        </table>
      </body>
    </html>
  </tt:template>
</tt:transform>

The transformation uses the ST statement tt:loop to serialize the other internal tables row by row. HTML tags are inserted into the XML data as literals.

The result of the transformation is first shown as an XML file and then as formatted HTML data further below.