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,

Encode Message Payload to Base64 on CPI!

How to use Base64 message encoder in SAP Integration Suite.

Subscribe for more

My First Interface on CPI!

Learn how to develop your first iFlow on SAP Integration Suite within 7 minutes!

Subscribe for more

23 thoughts on “XML Transformation Example with XSLT_TOOL

  1. Mahesh says:

    Hi,
    I have tried with above code and checked in AL11 but it is downloaded as single line. When I opend the file, the file displayed all the data in single line. Please help me.

    • Isuru Fernando says:

      Hi Mashesh, Download the file to your local PC and open it using Chrome, Firefox or any other browser. Make sure your file extension is correct.

    • Isuru Fernando says:

      Hi, You should be able to ignore empty tags using Conditional Transformation expressions. Write a Conditional Transformation Expression to create the tag only if data is not null.

  2. anil says:

    Hi I have a different format of xml.
    which needs to be generated using sap code.
    it has multiple tages with in the same line. how to write code for it

  3. Jonatan Perez says:

    hi there ,
    i have a very large xml transformation with several nodes and atributes , for any reason that i don’t know when i recieve the source xml of the transformation i just see a couple of fields but not the entire xml . do you know if exist any kind of variable or way to could obtain the entire xml?

    THanks

  4. Sumanth Krishna says:

    Hi Fernando,

    I have a similar requirement , ABAP -> XML I have extract Master data related to PM Module based on the plants from the selection screen. Could you please assist?

  5. Sumanth Krishna says:

    Hi Fernando,

    I have a similar requirement , ABAP -> XML I have to extract Master data related to PM Module based on the plants(select options) from the selection screen. Could you please assist?

  6. Weng says:

    Hi fernando, can you advise how to.place a.condition? I have a requirement where color of a column will dynamic based on value. Example if value greater 10 color green. If less that 10 color red. Please advise. Thanks! Btw i’m using simple transformation in abap using tcode XSLT_TOOL. Thanks!

  7. Weng says:

    Hi fernando, can you advise how to.place a.condition? I have a requirement where color of a cell will dynamic based on value. Example if value greater 10 color green. If less that 10 color red. Please advise. Thanks! Btw i’m using simple transformation in abap using tcode XSLT_TOOL. Thanks!

  8. Raymundo Flores Flores says:

    HI do you know how to add multiple items to one order in the xml? I trying to create a PO with multiple items, but all the time is repeating the header info and treating this like separate orders, thanks

  9. Mauricio says:

    is possible generate a XML with prefix cac and cbc like ?
    <cac:Item>
    <cbc:Description>8039203 GR.</cbc:Description>
    <cac:SellersItemIdentification>
    <cbc:ID>1160024532/10</cbc:ID>
    </cac:SellersItemIdentification>
    <cac:StandardItemIdentification>
    <cbc:ID schemeID="999" schemeName="asd">1162/10</cbc:ID>
    <cbc:ExtendedID>30736</cbc:ExtendedID>
    </cac:StandardItemIdentification>
    <cac:AdditionalItemProperty>
    <cbc:Name>/ UND|</cbc:Name>
    <cbc:Value>/ | 64.720,00 / 1.000 UND</cbc:Value>
    </cac:AdditionalItemProperty>
    <cac:ManufacturersItemIdentification>
    <cbc:ID>I3073</cbc:ID>
    <cbc:ExtendedID>3073</cbc:ExtendedID>
    </cac:ManufacturersItemIdentification>
    </cac:Item>

  10. Nanda Champsi says:

    Hello Fernando,
    How can I convert XML with CDATA into ABAP?


    AUTORIZADO

    -<![CDATA[

    2
    1
    EMPRESA PÚBLICA MUNICIPAL DE TELECOMUNICACIONESP
    016005999999/ruc>
    0406281021201517
    01
    001
    003
    024735818
    BENIGNO MALO 7-78 Y MARISCAL SUCRE

  11. Khushboo says:

    I have a requirement in which i have to populate the element based on some condition. How to achieve it in XSLT tool.Also, the prefix required is ns2. So can i manually enter ns2 as prefix for all the element/node.

  12. sanjeev says:

    Hi,

    i am using Simple transformation for multiple XML files as upload to sap system but XML has some optional tags how to handle in XSLT_TOOL ? ( ST).
    EX: Want make it optional tag , if XML has attribute need to read if not skip to other tag to process..

    please advise. below is the code:

  13. Sainath Kaja says:

    Hi,

    I have one transformation issue.
    Through Call Transformation statement I am able to convert internal table to XML format.
    But I am unable to transfer internal table XML format to existing proxy generated XML file.
    I am able to transfer single variables into existing proxy generated XML file through method CL_EDOC_UTIL_CO_UBL_21=>GET_ELEMENT_IN_XML_WITH_URI , but I dont know how to transfer or append internal table XML to existing proxy generated XML file.

    Kindly please share your experience.

    [Main Instruction]

  14. pavani says:

    I want to debug XML file. When i place the debugger on CALL TRANSFORMATION ID source *** , it is going to next line by pressing F5. How to go into XML file?

  15. Praveen says:

    Hi ,
    If I add new field in any deep structure, how this will reflect in the tool? Do we have any refresh button.
    Why we need to change field type to attribute and element. whats’ the difference?

    Kindly help me with answers.

    Regards
    Praveen

  16. Sayan says:

    Hello,

    In header line of the xml generated from abap (that is 1st line in .xml file generated), how to add encoding =”utf-8″, currently using this logic, this is not coming, Please help.

    Thanks,

  17. Sivaprasad says:

    Hi Fernando,
    I ahve succesfully created the xml file. But now when i add a new filed in the ddic structure , I am unable to see that newly added field in the root,. I deleted the root and added the structure again. But still it is not visible. It is bringing only the old structure. How can we solve this ?

Leave a Reply

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