How to Create and Read Flat IDocs from Files in SAP
I have recently come across the need to “manually” move an IDoc for testing purposes form one SAP system to another. The two systems were in two different environments and not planned to be connected network wise. So we needed a way to export and import an IDoc.
The idea was to export the IDoc on system A to a file and then import it in system B from that file. It seemed an easy task, but turned out to be quite tricky. I haven’t found much help from searching online or in SAP docs but enough to put something together that worked at the end. I’d like to share this here in a step-by-step guide.
Please note that this is only for manual testing purposes for single cases and not intended to serve as any kind of IDoc interface.
We firsts export an existing IDoc from source system, download the file to the local computer and then upload it to another system:
1 How to export a flat IDoc file in SAP ERP:
SAP GUI, Transaction Code: WE19
- Load an existing Idoc (see we02) via idoc number.
- Click on “inbound file” (note: this is actually confusing. You’re going to write a file to the file system, but the function is called inbound file. But it’s all right and you can go ahead.)
- Uncheck the checkbox “start inbound processing of file now”.
- Enter a path on the server (use transaction AL11 to find a suitable path) and a filename. The file name can be chosen freely. Execute the function.
- Download the exported file to your local machine using Transaction Code: CG3Y (or FM ARCHIVFILE_SERVER_TO_CLIENT as per a reader’s comment).
You can also use AL11 which displays a list of all available files. Select the file and then click the button marked below (“Download File as Text”):
- Target is a path on your local machine.
- Choose ASC for ASCII mode.
- Execute the download.
- You can now edit the file on your PC if needed, or further process/distribute it. Or you can now upload it e.g. to another SAP system and edit it there before processing (see next chapter).
2 Upload and Inbound Process a Flat IDoc File
- Upload the file using transaction code CG3Z (or FM ARCHIVFILE_CLIENT_TO_SERVER as per a reader’s comment) e.g. to a temp directory.
- Use t.code WE19 and select “File as Template”.
- Enter the path where you’ve uploaded the file and the filename.
- The test tool displays your IDoc, you can also change it here.
- You also need to create the control record (I don’t go into details of this here as this is required knowledge about the standard IDoc processing and can be found elsewhere). To create the control record, click on the first line in the editor and enter the data as needed (of course, change the name to your IDoc’s message type. Here it’s a business partner IDoc) :
- When you’re ready, click “Standard Inbound”. If a partner profile (WE20) exists, it will be processed after executing the function (or collected for later processing). See the status of the new IDoc in WE02.