Intermediate Document (IDOCs)
IDOCs (Intermediate Documents) are a method of integration for SAP with other SAP systems or Non-SAP systems. The idea behind IDOCs is to have a intermediate document (aka records) that can be sent from one system to another system (inbound and outbound) in a format defined within IDOC Type.
How it works
IDOCs have inbound and outbound processing. Each process can be linked with a specific function module that will process the data within the IDOC.
Based on the data of the IDOC type, and the implementation of the function module, the data will be processed accordingly. For example, if an IDOC of type Standard Order is created, SAP will process the data within the IDOC and create a sales order based on the data. This is one of the standard SAP IDOCs defined by SAP.
Users of SAP can also create custom IDOCs and custom function modules to process the data within the IDOC. This is useful when integrating with Non-SAP systems or when the standard IDOCs do not meet the requirements of the business process.
Creating IDOCs
IDOCs consist of serval main components that are required to define an IDOC. These components are:
- IDOC Type: This defines the structure of the IDOC and the segments that it contains (Define in Tcode: WE30).
- Message Type: This defines the type of message that the IDOC will be used for (Define in Tcode: WE81).
- Segment Type: This defines the structure of the segments within the IDOC Type (Define in Tcode: WE31).
- Function Module: This defines the function module that will be used to process the IDOC (Define in Tcode WE20).
- Partner Profile: This defines the partner that will be used to send or receive the IDOC (Define in Tcode WE20).
- Port: This defines the port that will be used to send or receive the IDOC (Define in Tcode WE21).
There is a BAPI Tcode to create all these in one tcode related to BAPI.
The tcode is BDBG, however, i haven't tried it yet not sure it work universally.
Monitoring IDOCs
IDOCs can be monitored using the following Tcodes:
- WE02: This tcode is used to display IDOCs and their status.
- WE05: This tcode is used to display IDOCs and their status (similar to WE02).
- BD87: This tcode is used to reprocess IDOCs that have failed.
- WE19: This tcode is used to test IDOCs by creating test IDOCs and processing them.
Checking IDOC Documentation
To check the documentation of a specific IDOC type, you can use the following Tcode:
- WE60: This tcode is used to display the documentation of IDOC types. You can enter the IDOC type and view the documentation related to that IDOC type.
This Tcode is exeremely useful to understand the structure and segments of a specific IDOC type. Providing this detail to an LLM will make creating/generating XML for IDOC Creation much easier.
Using Standard IDOCs
Even when using standard IDOCs, it is nessesary to create partner profile and ports to be able to send and receive IDOCs. There are different ways to communicate IDOCs between systems, some of the common methods are:
- File Transfer: IDOCs can be sent and received using file transfer methods such as FTP or SFTP.
- tRFC: IDOCs can be sent and received using tRFC (Transactional Remote Function Call).
- HTTP XML : IDOCs can be sent and received using HTTP XML methods.
The one i used and worked well is HTTP XML using python requests library to send the IDOC XML to SAP endpoint. tRFC for python is not recommended since pyRFC package is no longer maintained by SAP. Moreover, it is extremely challenging to setup/write IDOCs using pyRFC.
Trying & Testing IDOCs
I have setup a external python API to send inbound IDOCs to SAP using HTTP XML method. You can find the code here. Here you will be able to try to send inbound IDOCs for Standard Sales Order. Data accuracy and validity is extremely important when sending IDOCs to SAP. Make sure to provide valid data to avoid errors during processing.