IDocs in SAP
IDocs are the central import and export format of SAP ERP systems. They can therefore be used for data exchange with other software systems, e.g. when transferring customer data from a CRM system. IDocs are also particularly relevant in electronic data interchange (EDI) with external suppliers and customers. Further, much like saving an IDoc to your hard drive, deleting an IDoc, or reprocessing an IDoc, exporting an IDoc as an XML isn’t too difficult.
No matter which application scenario, you will often encounter the issue where you will need a specific IDoc as an XML file on your local hard drive. Repeatedly exporting files through a partner profile configured in transaction WE20 is ill advised due to uncontrolled side effects, e.g. repeating DESADV dispatches to clients.
The XML file is thus the best way forward, as it has many advantages and can for example be used to debug incorrect behaviour in software downstream from SAP. There are various functions available for exporting IDoc data in SAP. In a previous article we explained how to export IDoc data in Excel format. SAP also offers functions for exporting an IDoc as an XML file however.
In the following section, we will present you with an approach where it is not required to use your own ABAP code. With this approach, you will not have to create an ABAP code or transport it on a P-level. This method is also well suited for debugging on a P-system, under the condition that the user has the needed permissions for transaction SE37.
Do you have questions about Idocs and XML data? Feel free to contact us, we would love to help you!
Export an IDoc as an XML
To export an IDoc as an XML, you will first need to open transaction SE37.
© 2020. SAP SE or an SAP affiliate company. All rights reserved. Used with permission of SAP SE.
Enter the element IDOC_XML_TRANSFORM in the function block and execute it by clicking on F8. As you can see on the picture below, the IDoc is now shown as an XML data.
© 2020. SAP SE or an SAP affiliate company. All rights reserved. Used with permission of SAP SE.
Now enter the IDoc number that is to be exported in the DOCNUM field. Before the value can be entered, the zeros must be removed. Then execute the transaction with F8. The IDoc is now displayed as an XML file, as shown in the following image:
© 2020. SAP SE or an SAP affiliate company. All rights reserved. Used with permission of SAP SE.
Pressing ctrl+A, ctrl+C or ctrl+V will allow you to view the XML content with any editor.
As shown in the screenshot, the generated XML file has a small flaw: the opening angle brackets (< und </) of the elements are followed by spaces, and the closing angle brackets (>) have spaces before them. This means that this XML is not formatted properly.
To correct this, you can copy the XML data into an editor (Notepad++ e.g.) and search and replace the spaces around the angle brackets.
Summary
By using the method, you will be able to quickly and easily export IDoc data as XML files from an SAP system. The only disadvantage is that the resulting XML file is not valid and needs to be corrected with an editor, before it can be transmitted to further applications.
Do you have any questions?
Do you still have questions about Idocs and XML data? Feel free to contact us or check out our chat, we would love to help you!
SAP ERP and SAP S/4HANA are the trademarks or registered trademarks of SAP SE or its affiliates in Germany and in several other countries.