ABAP Keyword Documentation → ABAP - Reference → Data Interfaces and Communication Interfaces → ABAP and XML → Simple Transformations → ST - Examples
Simple Transformation for Internal Tables
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_xstring TYPE xstring.
SELECT *
FROM scarr
INTO CORRESPONDING FIELDS OF TABLE carrier_tab.
CALL TRANSFORMATION demo_st_table
SOURCE carriers = carrier_tab
RESULT XML xml_xstring.
cl_abap_browser=>show_xml( xml_xstring = xml_xstring
title = 'XML' ).
CALL TRANSFORMATION demo_st_table
SOURCE carriers = carrier_tab
RESULT XML xml_xstring
OPTIONS xml_header = 'NO'.
cl_abap_browser=>show_html( html_xstring = xml_xstring
title = 'HTML'
buttons = 'X'
check_html = ' ' ).
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:
<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 document as literals.
The result of the transformation is displayed using the CL_ABAP_BROWSER class, first as an XML file, and then as a formatted HTML file.