Press "Enter" to skip to content

How to manage Message IDs with SAP Cloud Integration

0

When communicating with SAP systems, we might need to find the message in SAP Cloud Integration message monitor later. This makes sense for asynchronous messaging only, as synchronous API calls are rarely recorded at runtime.

The mechanism is to use the Header SAP_ApplicationID to be able to quickly find the message.

Out of all existing SAP Backend integration technologies, this article covers how to make sure that you can find the following messages based on their ID in SAP Integration Suite (Cloud Integration):

  • IDoc
  • XML Messages (SOAP-XI3.0 protocol)

How to track iDocs coming FROM SAP ABAP systems

The iDoc number is stored in the control record and can be easily retrieved.

Ideally you are using an iDoc dispatcher flow (using JMS to buffer the messages if you want to), so you can easily extract the value from the header SapIDocDbId or via XPath from the control record (//EDI_DC40/DOCNUM). Do not forget to remove the leading zeros (e.g. via a Groovy script below) to simplify the search as the Application ID is very picky and does not search via “contains”, but via “equals”…

def Message processData(Message message) {
def app_id = message.getHeaders().get("SAP_ApplicationID").replaceFirst("^0+", "");
message.setHeader("SAP_ApplicationID", app_id);
return message;
}

However, if you transfer a package containing multiple iDocs in one larger XML message (bulk) after collecting them (e.g. INVOIC), your message will contain multiple iDoc numbers. You can solve this either by splitting the package and process each message individually or sending back an acknowledgement message back where you attach the iDoc number. You can also make an exception and record all individual iDoc numbers as custom headers into the one message, but then you will have to remember that you need to search via custom header, and not via Application ID…


How to track iDocs being sent TO SAP ABAP systems

When sending IDocs to SAP ABAP, you can perform the call synchronously (Request-Reply) to retrieve back the iDoc number(s) created in the target system.

If you transfer one iDoc, you get back exactly one ID, if you send a bulk message, you will get again a list (as the XML message body) which could be all stored in a custom header (or sent via ProcessDirect and then stored in the Application ID).

You can also store the CPI message id (property SAP_MessageProcessingLogID) into each IDoc using the archive field in the control header. It is populated automatically by the SAP PI/PO IDoc adapter using the PI message id, but not from SAP Cloud Integration. This helps to identify in the SAP ABAP system backwards to find the message in SAP Cloud Integration as well.


How to track XML messages (XI) coming FROM SAP ABAP systems

The XI Message ID is stored in header SapMessageIdEx.

Again, ideally you are using a XI message dispatcher flow for ABAP proxies, so you can easily retrieve the id and also convert it to upper case at the same time, which is also simplifying the search later on:

def Message processData(Message message) {
// get XI Message Id & convert to upper case
def XI_MsgId = message.getHeaders().get("SapMessageIdEx").toUpperCase();
message.setHeader("SAP_ApplicationID", XI_MsgId);
return message;
}

How to track XML messages (XI) being sent TO SAP ABAP systems

When sending XI messages to SAP ABAP, you can not retrieve back the message id. To make sure you store the XI message id in the Application ID, you need to generate it first (using a Groovy script) and then you can (re)use the ID for the communication in your receiver XI channel:

def Message processData(Message message) {
   def ExtID = message.getHeaders().get("SapMessageIdEx");
   if (ExtID==null){
        String MsgID = UUID.randomUUID().toString();
        message.setHeader("SapMessageIdEx", MsgID);
        message.setHeader("SAP_ApplicationID", MsgID.toUpperCase());
        }
   return message;
}
Print Friendly, PDF & Email