Introduction
With more customers now migrating or thinking about migrating their SAP PI/PO Integrations to CPI; a few common questions I get from seasoned PI/PO developers and Integration Managers is
- How do I monitor?
- How do I filter messages in Message Monitor?
- How do I search?
- What should I do to make sure I migrate my Interfaces right from a Monitoring and Operations perspective?
This post is an attempt to list out the Standard Out of the Box Features available in CPI that every developer “should” mandatorily use and leverage to make both their and Operations teams lives easy.
Standard Message Headers
SAP CPI provides a list of Standard Message Headers. While its usage is upto Individual developers it is essential and imperative that you use these Message Headers in your Iflows. Lets take a look at these Standard Message Headers
SAP_Sender
- This is a header to identify your Sender System.
- If you are from a PI / PO Background think Sender Business System / Service.
- Example usage can be ERPCLNT100, HCMCLNT500 and so on for your on-premise SAP Systems.
- The usage is left to you from SAP but it is strongly recommended that
- You have a List of allowed values in your landscape for both SAP and not SAP systems.
- You have these values as externalized in your iflow when you define them
SAP_Receiver
- This is a header to identify your Receiving System.
- If you are from a PI / PO Background think Sender Business System / Service.
- Example usage can be ERPCLNT100, HCMCLNT500 and so on for your on-premise SAP Systems.
- The usage is left to you from SAP but it is strongly recommended that
- You have a List of allowed values in your landscape for both SAP and not SAP systems.
- You have these values as externalized in your iflow when you define them
SAP_MessageType
- This is a header to identify your Message Type.
- If you are from a PI/PO Background think Sender Interface /IDoc.
- Example Usage can be ORDERS.ORDERS05, SalesOrder, PurchaseOrder etc.
- The usage is left to you from SAP but it is strongly recommended that
- You have a List of allowed values in your landscape for both SAP and not SAP systems.
SAP_ApplicationID
- This is a header to identify your unique Message in runtime.
- If you are from a PI/PO background think IDocNumber, FileName, PurchaseOrderNumber etc.
SAP_MessageProcessingLogCustomStatus
- This is a header to put a Custom Status in your iflow.
- SAP provides standard status for the iflows – Completed, Escalated, Failed etc. What if you want to provide a custom status in your iflow beyond this.
- In my experience this is not something that I have found much use for.,
How to use Standard Headers in your Iflow
- Define a Content Modifier step – ideally the 1st step of your Iflow.
- Provide values for each of these Headers in the Header
Name | Type | Value | Data Type | Example |
SAP_Sender | Constant | {{SAP_Sender}} | String | ERPCLNT500 HCMCLNT100 SalesforceCRM Coupa C4C_ServiceCloud |
SAP_Receiver | Constant | {{SAP_Receiver}} | String | ERPCLNT500 HCMCLNT100 SalesforceCRM Coupa C4C_ServiceCloud |
SAP_MessageType | Constant or XPATH ( for IDocs) | {{SAP_MessageType}} | String | Orders ServiceTicket |
SAP_ApplicationID | XPATH ( for taking value from Payload) | //DOCNUM | Integer | Example for IDoc Number |
For SAP_MessageType when you use a IDoc as a Sender; I would recommend to use the following XPATH so that you can have the IDoc as the SAP Message Type in CPI with MessageType.IDocType.Extension
concat(//MESTYP, '.',//IDOCTYP,if (//CIMTYP) then concat('.', //CIMTYP) else ())
How to use Standard Headers in CPI Message Monitoring
Use Option “Use More Fields” to view these Headers in a Drop Down.
Custom Message Headers
So we have seen Standard SAP Message Headers. We have seen how they can b e used to search and filter for messages. We have seen SAP_ApplicationID and how it can be used to search for messages. BUT,
- What if I want to search a message by more than one field.
- IDoc Number works for me but what if I want to search by PONumber, DeliveryNumber, EDI InterchangeID, and so on.
- Basically I want CPI to index and allow multiple identifiers to search a message.
- Are you from a SAP PO Background – think User Defined Message Search.
How to use Custom Headers in your Iflow
While custom headers provide additional mode to Log Headers in CPI and search for them in Standard Message Monitor, the only way to log custom headers is to use a Groovy Script.
- Assume you get 2 Fields in your payload that you would like to set as your Custom headers – IDocNumber and PONumber
- They are in the Input XML Payload with field names IDocNumber and PONumber.
- Extract these values and store them as Properties
- You can then use this Groovy script to log Custom Headers in CPI.
import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message) {
def messageLog = messageLogFactory.getMessageLog(message);
if(messageLog != null){
def map = message.getProperties()
def IdocNumber = map.get("IdocNumber");
def PONumber = map.get("PONumber");
if(PONumber!=null){
messageLog.addCustomHeaderProperty("PONumber", PONumber);
}
if(IdocNumber!=null){
messageLog.addCustomHeaderProperty("IdocNumber", IdocNumber);
}
}
return message;
}
How to use Custom Message Headers in CPI Message Monitoring
Once you have logged your Custom Headers, you can then see them in your message monitor as below.
You can also search for your messages with Custom Headers as below
- In Message Monitor, Select Use More Fields
- Provide the CustomHeaderName and Value in the following Format “Name=Value”. Eg: IdocNumber=2 in our example
Final Thoughts
Standard Message Headers
- Standard SAP Messages Headers are mandatory. Please use them.
- Ensure you have a allowed list of SAP_Sender, SAP_Receiver and SAP_MessageType in your landscape. This will keep your landscape clean and allow for easy monitoring.
- Use SAP_ApplicationID to allow for Payload Search.
- If you use IDocs in your landscape use the XPATH I gave, you wont regret that.
Custom Message Headers
- Custom Message Headers are extremely powerful and will help with your message search in CPI. Ensure you use this!
- Custom Message Headers can only be set via Groovy Script. The Groovy in this post is an example. Ensure that you use a Re-usable Groovy script. Refer SAP CPI Custom Headers -Reusable Groovy Script
- If you use EDI Conversion in CPI for EDI to XML and want to search your EDI Messages with EDI Parameters, then refer SAP CPI – Reusable Groovy Script to Log All EDI Headers