Skip to Content
Technical Articles

Changing fault Message Of Outbound IDOC’s Sent from ECC To SAP CPI

Introduction: I was working on a scenario where an IDOC is sent from ECC to CPI via Cloud connector. The scenario worked fine except for the fact that when the IDOC failed in CPI we were getting a standard Error text (Not even complete) in WE02 after opening the status details like below.

 

 

We Wanted something more meaningful Like the error that was encountered. In our case we knew the exact case where this error must be propagated.

The final Outcome was like Below.

 

Solution: This cannot be achieved by using IDOC adapter as the processing is quite rigid and It doesnt allow to trick itself into taking a soap fault.

The error text we see above is nothing but he soap Fault which is triggered only when there is an handled error or exception in either the producer or consumer IFLOW.

This is the reason we need to pass this error in the IFLOW as a cosmetic error rather than a full blown exception to ECC.

We will use SOAP adapter like below in the sender side. Nothing changes not even the final url after deployment i.e /cfx/xyz…

 

After this We need to modify the Body while sending the response back in a content modifier.

Producer IFLOW

 

Consumer IFLOW:

In my case the receiver always returns a 204 when successfull request is made so i need to change that to 200 as any http code other than 200 results in a 02 status in ECC i.e Fail. Another major thing which this groovy script does is that it produces the standard response which is produced automatically by IDOC adapter if that is used. but in our case we are using SOAP adapter so we need to produce that manually.

 

 

Enclosing the error message in soap:fault tags is mandatory as otherwise it will go back as a normal response. also pay attention to the soap namespace that is mandatory otherwise it fails with a undeclared namespace error.

 

Also we need to modify the CamelHttpResponsecode as below.

Groovy Scripy

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    //Body 
       def body = message.getBody();
       String newbody = "";
       
       
        
       def map = message.getHeaders();
       int value = map.get("CamelHttpResponseCode");
       String Idoc_num = map.get("SAP_ApplicationID") as String;
       
       int padNum = 16; 
       
       if(value == 204)
        {       
            message.setHeader("CamelHttpResponseCode", 200);
            newbody = "<CLFMAS02Response>"+
			"<IdocAssign>"+
				"<TransferId>"+Idoc_num.padLeft(padNum,"0")+"</TransferId>"+
				"<DbId>"+Idoc_num.padLeft(padNum,"0")+"</DbId>"+
			"</IdocAssign>"+
		"</CLFMAS02Response>";
		
        }
        else
        {
            message.setHeader("CamelHttpResponseCode", 500);
            newbody = "<soap:Fault xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><faultcode>soap:Server</faultcode><faultstring>An internal error occurred. Product characteristics could not be saved in C4C. Search by Message ID"+ Idoc_num +" in SAP CPI</faultstring></soap:Fault>";

        }
        message.setBody(newbody);
        
       return message;
}

 

Conclusion: I don’t see any disadvantages of using SOAP adapter over an IDOC adapter for Receiving IDOCS from ECC (Same may not be said for IDOC Receiver and SOAP Receiver adapter). IDOC’s basically use SOAP over HTTP and if you look closely IDOC’s coming to CPI via IDOC adapter are wrapped in a soap envelope and soap body. IDOC adapter just like SOAP adapter unwraps the payload before CPI processes it.

 

Let me know in comments what do you think of preferring SOAP adapter over IDOC adapter for such requirements.

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