Skip to Content
Technical Articles
Author's profile photo Ravi Gupta

Getting Inbound IDoc number in SAP CPI iflow

Requirement

IDoc transmission is quite common in SAP Integration world. For inbound scenarios (3PL => CPI => SAP ERP / Any other SAP system) integration scenarios, IDocs are used frequently. We would like to know the IDoc number generated in SAP ERP (or any other SAP system) in CPI flow itself during the execution.

 

How To

CPI <=> SAP ERP integration uses SOAP over http protocol to transmit the IDoc data. IDocs communication is asynchronous in general however, communication over SOAP/HTTP is synchronous and here is when IDoc transmission behaves differently.

When an IDoc is sent over SOAP/HTTP to SAP system, the SOAP framework waits for IDoc to be created in SAP system and the SOAP response returns back with the newly created IDoc number. So with a little effort in CPI, we can capture this IDoc number.

 

So following steps need to be executed to get the IDoc number back in CPI.

 

Fig – IDoc call via a request-reply step (step 1),

        Retrieving the Idoc number (step 2),

        printing the IDoc number (step 3)

Design Time

Step 1

Call the IDoc adapter via a request-reply step. Why a request-reply step ? because IDoc call from CPI to SAP (or vice versa), is a synchronous call over SOAP/HTTP.

 

Step 2

If the IDOC call is successful from step 1, we will get back the response from SAP system as

mentioned below. We are assuming that we are using MATMAS02 doc in this call.

 

<MATMAS02Response xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
	<IdocAssign>
		<TransferId>0000000000000246</TransferId>
		<DbId>0000000000000xxxxx</DbId>
	</IdocAssign>
</MATMAS02Response>

 

Field ‘Dbid’ contains the IDoc number. We just need to use a variable to retrieve the IDoc number Define a property named IDOC_NUMBER and write it via SAP_ApplicationID in step 3 in message monitoring. We can also use the IDOC_NUMBER to send back to the source system or other logging purposes.

 

We can use following XPATH for

/MATMAS02Response/IdocAssign/DbId

OR a generic XPath to retrieve the IDoc number is as mentioned below

node()/node()/node()[local-name()=’DbId’]

 

 

 

Step 3

We can use the Inbound Idoc number in iflow after this step.

 

 

 

Runtime

 

Step 1

 

Step 2

 

 

Step 3

 

 

Conclusion

 

It is always good to have inbound Idoc number when using the IDocs in SAP. Either passing it to source system or writing to message monitoring screen for easy troubleshooting / reporting purposes. It is quite handy and saves time when debugging in production environment where we have thousands of IDocs created in a very short span of time.

It is also important to note that, SOAP over HTTP guarantees the creation of IDoc in SAP but doesn’t guarantee whether the IDoc was successful or not. In the sync scenario, IDoc number is considered to be response of the SOAP call from CPI to SAP. Once the IDoc has been created in SAP, it will be successful or it will fail, depending upon the application data present in it. SOAP over HTTP framework lets us know the IDoc number.

 

 

 

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.