Sending IDOC as XML (Outbound API)
This blog post will give you the overview to use IDOC as XML.
IDOC is a standard data structure used in SAP applications to transfer data to and from SAP system applications and external systems.
More details about IDOCs can be found here:
The below are the steps to be followed:
- Create the RFC destination to send the outbound IDOC.
- Maintain the Outbound Port.
- Create Partner Profile.
- Generate the IDOC.
1. Create the RFC destination:
- Transaction Code to create RFC destination is SM59
- Select the connection type as G (HTTP Connection to External Server)
- In order to send the outbound IDOC to we need to maintain the RFC destination in S4.
- RFC destination will going to contain the external system endpoint including Host, Path Prefix. Also maintain the basic authentication.
The below is the RFC destination created.
2. Maintain the Outbound Port
- Transaction Code to create PORT is WE21.
- XML HTTP port is required in order to convert the IDOC into XML
- Create the XML HTTP Port in S4 and maintain the RFC destination as below.
3. Create Partner Profile
- Transaction Code to create Partner Profile is WE20
- Partner profile need to be maintained in S4 with the outbound port which we have created in WE21.
4. Generate the IDOC.
Now Create a sample program to populate the control record and IDOC segments and call the function modules ‘MASTER_IDOC_DISTRIBUTE’ and ‘DB_COMMIT’.
Please refer to the below blog to get the sample code.
Now execute the program to send the data to external systems using IDOC as XML.
Once the IDOC is triggered, the system will convert the IDOC data into XML file and post to end-point URL maintained in RFC destination of IDOC port.
By following these steps, we can send the IDOC as XML over HTTP protocol.
Thanks for the article!
For the step #4 (generate IDOC) you may not even need to create custom ABAP report. There are some standard tcodes like WE19 (test tool for IDOCs), BD10 (send material), BD12 (send customer), BD14 (send vendor) and smore more BD* transactions that allow generating standard IDOCs types out of the box.
Thanks & regards,
Thanks for your comments. Yes, its all based on the requirement. We have a specific requirement using custom IDOC and trigger from custom program.
Is there a specific reason you decided to use IDoc? If everything is custom then you might as well just use the same ABAP program to produce XML...
The requirement is to leverage the IDOC as API so that the standard monitoring and reprocessing is possible.
We can create REST APIs in ABAP using SAP Gateway even in ECC (I did it in an EHP6 system with ABAP 7.31, so don't even have to be latest and greatest). These also have monitoring and reprocessing tools. And REST is designed to work over HTTP and can provide either XML or JSON format.
There is a lot of information on this online, SAP Gateway tag on SCN would be a good start.
Do we have reprocessing tools in SAP for REST API without AIF. could you please share further details if possible.
Not sure what AIF is... There is an error log transaction in SAP Gateway where we can view the error messages and reprocess the request too.
This particular scenario is outbound though, so that would not apply (and we do not "reprocess" outbound IDocs either, they can only be sent again if in error status). The difference between IDoc and API-based scenario is that the outbound IDocs are "pushed" from SAP while APIs are called from outside (i.e. data is "pulled" from SAP). So for the outbound interface, there is nothing to reprocess on SAP side, the API call can simply be repeated by the other side.
In any case, I'd encourage to look into REST API / SAP Gateway as a replacement for custom IDocs. If anything, you'd learn more valuable skills developing the APIs.
AIF stands for Application Interface Framework
SAP Application Interface Framework | SAP Blogs
I've been looking at this kind of solution for our requirement but could not find any related article, would you be willing to share the steps or email them to me please? We are on NW 7.4 and trying to get to activate the SAP Gateway but need a reason what to use it for.
Thanks in advance.
@Lakshmi, The blog is informative . Thanks.
@Jelena, If you don't mind can you please share the some peice of technical information on REST API's. would like to know. I have a similar requirement to send Outbound IDOC to Ariba using CPI. so i am using the similar approach. Main reason i went with IDOC is to check the log in the system.
FYI use full name after @ (you should see the person's name appear as you type) to send a notification to the person mentioned. I saw this post only because Shai posted a comment above. This works just like Twitter or LI.
There are metric tons of information on this. Just for starters:
To make it clear, I don't advocate using APIs instead of IDocs when standard IDocs exist and work well. It's the custom IDocs that I believe might no longer be beneficial in many scenarios. Here are some short articles I wrote on the subject:
EDI vs API
Round two: API vs BAPI
Thanks for the informative content. I have the same in my project . need to trigger an outbound IDOC. I am able create the outbound IDOC but status gets into "02" Problem with the SOAP class.
I have the similar settings in partner and port configuration but not sure why it is throwing this error.
I could not resolve this. Please help.