Skip to Content
Technical Articles
Author's profile photo Lakshmi Ganga

Sending IDOC as XML (Outbound API)

This blog post will give you the overview to use IDOC as XML.

Introduction:

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:

https://wiki.scn.sap.com/wiki/display/ABAPConn/IDoc+Overview

https://wiki.scn.sap.com/wiki/display/Community/Inbound%20and%20Outbound%20Idoc%20Configuration%20Steps

https://wiki.scn.sap.com/wiki/display/Community/Inbound%20and%20Outbound%20Idoc%20Configuration%20Steps

Now we are going to see how IDOC can be sent as XML over HTTP to external systems.

Procedure:

The below are the steps to be followed:

  1. Create the RFC destination to send the outbound IDOC.
  2. Maintain the Outbound Port.
  3. Create Partner Profile.
  4. Generate  the IDOC.

1. Create the RFC destination:

  1. Transaction Code to create RFC destination is SM59
  2. Select the connection type as G (HTTP Connection to External Server)
  3. In order to send the outbound IDOC to we need to maintain the RFC destination in S4.
  4. 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

  1. Transaction Code to create PORT is WE21.
  2. XML HTTP port is required in order to convert the IDOC into XML
  3. Create the XML HTTP Port in S4 and maintain the RFC destination as below.

 

3. Create Partner Profile

  1. Transaction Code to create Partner Profile  is WE20
  2. 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.

https://wiki.scn.sap.com/wiki/display/ABAP/Outbound+Idocs+by+ALE

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.

Conclusion:

By following these steps, we can send the IDOC as XML over HTTP protocol.

 

 

 

 

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Vladislav Klimov
      Vladislav Klimov

      Hi Lakshmi

      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,

      Vlad

      Author's profile photo Lakshmi Ganga
      Lakshmi Ganga
      Blog Post Author

      Thanks for your comments. Yes, its all based on the requirement. We have a specific requirement using custom IDOC and trigger from custom program.

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      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...

      Author's profile photo Lakshmi Ganga
      Lakshmi Ganga
      Blog Post Author

      The requirement is to leverage the IDOC as API so that the standard monitoring and reprocessing is possible.

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      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.

      Author's profile photo Lakshmi Ganga
      Lakshmi Ganga
      Blog Post Author

      Do we have reprocessing tools in SAP for REST API without AIF. could you please share further details if possible.

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      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.

      Author's profile photo Shai Sinai
      Shai Sinai

      AIF stands for Application Interface Framework

      SAP Application Interface Framework | SAP Blogs

      Author's profile photo Ricky Orea
      Ricky Orea

      hi there,

      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.

       

      Author's profile photo Srikumaran tp
      Srikumaran tp

      @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. 

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      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:

      https://www.codecademy.com/article/what-is-rest

      https://community.sap.com/topics/gateway

      https://developers.sap.com/tutorials/abap-environment-restful-programming-model.html

      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

       

       

      Author's profile photo Srikumaran tp
      Srikumaran tp

      Hi,

      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.

       

      Regards,

      Sri