In some situations, it is useful to be able to manually export and save IDocs as files. A typical use case is before a QA-System refresh. You don’t want to fully lose all your hard work Test-IDocs. Then, you can export and save them as file for reference, and you can reimport them later with the WE19 test-tool after the system refresh.
We present three different ways of exporting IDocs with different outcomes:
- Export as an Excel list of segment fields and values. This format is not the official IDoc protocol format and thus you cannot “import” it as an IDoc in a target system
- Export as XML file IDoc – requires use of developer tools (SE37)
- Export as IDoc file or XML-IDoc with the IDoc test-Tool WE19
The last two ways produce files that can be re-imported in a SAP system.
1. Export as an Excel list of segment fields and values
Start from the IDoc List transaction WE02, open an IDoc to display, and then use the somewhat less known menu function “Print IDoc”.
This will display the IDoc as a flat list of segments with field-names, descriptions and values. The list can then simply be saved as a local file or exported as a Spreadsheet with the standard ALV functionality.
2. Export as XML-IDoc file by using an ABAP function
Start the ABAP function workbench SE37 and test-execute the function module IDOC_XML_TRANSFORM. Enter the IDoc number to be exported in parameter DOCNUM and execute. You will get something looking like IDoc-XML. Unfortunately it has additional spaces added in the XML tags, which makes it actually not real XML.
To get the correct XML, you can copy-paste the displayed output to a text editor and just remove the spaces in the XML tags as needed.
Alternatively, the ABAP debugger can be used to display the correct XML-IDoc, before it is being transformed with the additional spaces: The breakpoint must be put after the method call idoc->get_xmldata_as_string and then you can just display the variable “str” with the XML browser debugger view:
3. Export as XML-IDoc file or “standard” IDoc-file with WE19 and CG3Y
This is a somewhat tangled way of proceeding – but it produces standard IDoc-file or XML-IDoc files that are in the IDoc protocol format and can be re-imported in any target SAP system
Prerequisites:
- There is a File (or XML-File) port available. This can be checked in transaction WE21. Additionally, the Port Outbound-File directory must be accessible. You can test this with the button “access test”.
- One is allowed to add dummy IDoc Partner-agreement to a dummy receiver system for example the SAP dev system.
- Authorization for WE19
- Authorization for CG3Y. By the way, CG3Y is only needed to fetch the IDoc-XML files from the SAP server. You can use any other (maybe non standard) other tool for that purpose.
Steps:
- Add a dummy partner agreement in WE20 for example to the SAP-Dev system for the given message and IDoc type and the file port.
- Call WE19 with the IDoc number to be exported.
- Adjust the control record.
- Receiver data to match the partner-agreement created in previous step
- Also remove and clear all control record “reference” and date fields
- If it’s an inbound IDoc, also adjust the sender partner data to be the current SAP logical system.
- Push button “standard outbound processing“.
- Normally, the IDoc file is created and saved on he server directory as specified by the IDoc File port.
- Call CG3Y to fetch the server file and download it to you desktop.