XML Transformation Example with XSLT_TOOL

With ever changing world of integration one language that has stood the test of time is XML. Due to capabilities of XML and large number of system integration requirments, its impertinent for technical consultants to understand the XML transformation capabilities in SAP.  SAP transformations are used to filter and recognize XML data.

SAP transformations can be used for,

  • Deserialization: Process of transforming XML documents to other XML, HTML, Text or ABAP data structures.

  • Serialization: Conversion of ABAP data structures to XML, HTML or text files.

There are several methods to create XML transformations in SAP.

  1. XLS Transformations:

  2. Simple Transformations

Just like any other ABAP program, transformations are also repository objects which could be accessed via SE80. SAP has now provided a graphical tool to create transformations. Graphical transformation program creation wizard could be accessed through transaction XSLT_TOOL.

In this serialization example and we are creating a XML file in the application server with sales order information. XML file holds multiple sales order information with sales order number, sales order type and customer information.

Output file format:

xml-file-format-xslt_tool-abap-transformation
XML File Format

You require access to these transaction codes to generate this XML transformation.

  • SE11 – ABAP Dictionary
  • SE38 – ABAP Editor
  • XSLT_TOOL – Transformation Editor

Step by Step Guide on XML Serialization Using XSLT_TOOL.

 

1. Create table type.

Depending on the XML file format, matching ABAP table type should be created.
Go to transaction SE11.
Create underline data type (structure) which match XML “customer” segment.
abap-data-structure-customer-segment-xml-transformation-xslt_tool
ABAP Data Structure Customer Segment

 

Create data type which correspond to “Order” segment in XML.
abap-data-structure-order-segment-xml-transformation-xslt_tool
ABAP Data Structure Order Segment

 

Create table type.
abap-table-type-xml-transformation-xslt_tool
Create ABAP Table Type

 

2. Create transformation in XSLT_TOOL.

Go to transformation XSLT_TOOL.
Provide name and click create. Set description and transformation type.
abap-transformation-name-xslt_tool
Provide a name and description of the transformation

 

xslt_tool-properties
XSLT_TOOL Properties

 

Select wizard button “Edit Simple Transformation Graphically”.
xslt_tool-access-wizard-edit
XSLT_TOOL Transformation Wizard

 

Right click on root element and select “insert new root”.
xslt_tool-wizard-insert-new-root
XSLT_TOOL Access Wizard Insert Root Element

 

Provide header root element name and table type name.
root-element-table-type-mapping-xslt_tool-abap-xml-transformation
Set root name and table type

 

Drag and drop data root into simple transformation section.
xslt_tool-transformation-abap-wizard
Drag and drop

 

map-asap-structre-xml-xslt_tool-transformation
Map ABAP data structure and XML elements

 

Double click of each element/node and change the name as desired to be shown in XML.
xml-node-name-xslt_tool-transformation
Change how name is shown in XML

 

You can set any element as a attribute of a segment as needed. In this example “order-no’ is set as a attribute of segment “Order”.
Right click on the element and select “Change to attribute”.
XSLT_TOOL-change-element-type
XSLT_TOOL change element type to attribute

 

Save and activate.
Final transformation.
xslt_tool-xml-transformation-abap-created
Transformation

 

3. Create outbound program.

XML-Transformation-Program-Selection-Screen-se38
XML Transformation Program Selection Screen

 

Outbound driver program consist of,
  • Data selection logic. Program select sales order information on sales order creation date selection (Form select_data).
  • Prepare data to XML format (form prepare_data).
  • Call XML transformation created in XSLT_TOOL (Form download_xml). CALL TRANSACTION is a keyword in ABAP to call the transformation created in XSLT_TOOL.
  • Download XML data to file (form download_xml).

 

XML-transformation-program-code
XML Transformation Program Code Includes

 

XML-transformation-program-pode-data-declaration
XML Transformation Program Code Data Declaration

 

Selection-Screen
Selection Screen

 

xslt_tool-transformation-program-main
main form

 

Data-Selection-se38-sql
Data Selection

 

xslt_tool-transformation-abap-program-prepare
Prepare data

 

Transform-Internal-Table-XML
Transform Internal Table to XML

 

xslt_tool-transformation-abap-program-close-dataset
Close Dataset

 

XML file would be downloaded as below.
xslt_tool-transformation-abap-program-output
Created XML

 

If you have any questions on any of the XSLT_TOOL transformation configuration steps, please leave a comment below,

4 Comments

Add a Comment

Your email address will not be published. Required fields are marked *