Skip to Content
Technical Articles

SAP CPI – A Guide to MPL Search

Most of us already know that the ID based message search in SAP CPI is limited to Message ID or Correlation ID or Application ID. In this blog let us explore on using more Searchable Identifier(s).

While Message ID and Correlation ID are technical identifiers generated by CPI, we are left with just Application ID to set a process/functional identifier like Purchase Order Number, Sales Order Number, Customer Number, etc. This helps to search the MPL based on the business identifier for monitoring/troubleshooting.

However, in my SAP CPI journey, there were multiple instances where I had a need to have more than one ID to use for MPL search, for eg

  • Application ID set to Customer Number from IDOC, however, I also require a search based on IDOC number.
  • Application ID set to Order Number from message sent over message broker, however, I also require a search based on Message-ID from Message broker.

I achieved this use case by setting the additional ID as a Custom Header in MPL. Let us see in this blog on implementing it.

Scenario

Let us see the implementation in a scenario where a DEBMAS IDoc is sent for Business Partner Replication. We would set BP Number as Application ID and IDoc Number as Custom Header. Then we see how to search MPL based on both these IDs.

IFLOW

IFLOW

Set Application ID

Use the Content Modifier step to set the below standard MPL headers.

SAP_Sender Constant Sender System Name
SAP_Receiver Constant Receiver System Name
SAP_MessageType Constant Message Type
SAP_ApplicationID XPath XPath to read the business identifier i.e. /DEBMAS07/IDOC/E1KNA1M/KUNNR

Also, extract the IDOC number into a header field.

IDOCNUM XPath XPath to IDoc number field i.e /DEBMAS07/IDOC/EDI_DC40/DOCNUM

Content%20Modifier

Content Modifier

Set Custom Header

Use the groovy script to read the IDoc Number extracted in Content Modifier and set it as a Custom Header using addCustomHeaderProperty method of MessageLogFactory Interface.

import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {
    
	def messageLog = messageLogFactory.getMessageLog(message);
	if(messageLog != null){
		//Read IDoc number from Header
		def IDOCNUM = message.getHeaders().get("IDOCNUM");		
		//Set IDoc number as Custom Header
		if(IDOCNUM!=null)
			messageLog.addCustomHeaderProperty("IDOCNUM", IDOCNUM);		
	}
	return message;
}

Message Processing Log

This is how the MPL is for a BP 1000000001 processed with IDoc 0000000123456789.

Standard%20MPL%20Headers

Standard MPL Headers

Open Text View to see the Custom MPL header

Custom%20MPL%20Header

Custom MPL Header

Search based on Application ID

This is a straight forward search in SAP CPI Message processing Monitor. A search for ID “1000000001” yields two messages processed for this BP.

Search based on Custom Header ID

The standard UI does not allow us to search message based on the Custom Header Identifier OOTB. Hence we will use MPL OData API to retrieve the Message ID.

URL

https://{{cpi_tmn_host}}/itspaces/odata/api/v1/MessageProcessingLogCustomHeaderProperties?$filter=Name eq 'IDOCNUM' and Value eq '0000000123456789'&$expand=Log&$format=json

Note: Custom Header is inserted as a Name/Value pair, hence the $filter parameter should be passed with the Custom Header Name and the value that we are searching for.

The API Call fetches the Message ID matching the custom header search condition. Use it in the standard Message Processing monitor to search and troubleshoot.

Conclusion

Use the Custom Header to Insert one or more searchable identifiers. However, use it wisely as any wrong usage can lead to a large MPL size on the tenant. I also hope that in a future update SAP will enable us to search messages based on Custom Header in the Monitor UI.

5 Comments
You must be Logged on to comment or reply to a post.
  • Hello Santhosh,

    Nice find in the APIs! I hope it is only a matter of UI update and not about indexing/performance. Maybe someone from SAP can enlighten us πŸ™‚

    Regards,
    Fatih

    • Hi Fatih,

      Thanks for your comment πŸ™‚ I guess it’s indexed, but SAP can enlighten us.

      Is this something you could give us in the SuperEasy extension in the meantime πŸ™‚

      Thanks,
      Santhosh.

      • Hi Santhosh,

        If it will make one of your daily tasks easier, sure! πŸ™‚ I will try to find a good UI logic. Do you need to search for multiple Custom Header Properties with “and”, “or”? I haven’t tried, but the API should support it since it is an OData service.

        Regards,
        Fatih

        • Hi Fatih,

          Thanks for offering help πŸ™‚

          Usual ODATA filter conditions with “and”, “or” etc should be supported. It’s good to have a basic search with just one custom header, to begin with.

          Thanks,
          Santhosh.