[SAP CPI] – MONITORING MESSAGE IN CPI AND S/4

Hi guys, in this article I want to share a tip about monitoring message in CPI and S/4. As you known, monitoring and search message is important in integration system maintenance to fix issue if it happen. For example, NON-SAP system send message XML to S/4 through CPI by using IDOC adapter receiver, how to get message ID of CPI at S/4 and how to get IDOC number of S/4 at SAP CPI ? One more example in IDOC outbound scenario, S/4 send message XML to NON-SAP through CPI by using IDOC adapter sender, how to get IDOC number of S/4, some data in data record of IDOC at SAP CPI ? All this answer for these question, I will share in this article.

I. Understand about header in CPI for log message ID.

In CPI, we have some header which using for search message in CPI.

SAP_ApplicationID – This is where you can put the content of your payload. So you can put in your invoice number. This value will display in field Application Message ID in MPL search

SAP_MessageType – This is where you can put extra data like message type, basic type, extension…This value will display in field Application Message Type in MPL search

SAP_Receiver – This is where you can put name of receiver system. This value will display in field Receiver in MPL search

SAP_Sender – This is where you can put name of sender system. This value will display in field Sender in MPL search

SAP_MessageProcessingLogCustomStatus – This is where you can put extra data for field Custom Status. This is should be configure at tab properties

SAP_MessageProcessingLogID – This is message processing log ID in MPL

Add more, you can use groovy script to add custom header in MPL search as below

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;
}
II. Logging in Inbound Scenarios with header in MPL

Scenario: POS/NON-SAP will send message to S/4 through CPI. In MPL CPI we have to log some data

  • SAP_ApplicationID – POS number
  • SAP_MessageType – Message Type
  • SAP_Sender – POS
  • SAP_Receiver – Logical System of S/4. This value should be parameter.
  • SAP_MessageProcessingLogID – Mapping into field ARCKEY in IDOC control record EDI_DC
  • Custom Header Property – IDOC number reply from S/4

In this scenario, we also use groovy script to send value header from outside into message mapping to resolve some data dynamic for fields of control record – EDIDC_40 over every environment.

  • TABNAM
  • MANDT
  • DIRECT
  • IDOCTYP
  • MESTYP
  • SNDPOR
  • SNDPRT
  • SNDPRN
  • RCVPOR
  • RCVPRT
  • RCVPRN
  • ARCKEY : urn:sap.com:msgid=<messageID>

    To do this, we create groovy script

    /* Refer the link below to learn more about the use cases of script.
    https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
    
    If you want to know more about the SCRIPT APIs, refer the link below
    https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */
    import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.HashMap;
    import com.sap.it.api.mapping.*;
    
    import com.sap.it.api.mapping.MappingContext;
    
    def String getheader(String header_name, MappingContext context) {
    
        def headervalue= context.getHeader(header_name);
    
        return headervalue;
    
    }

    This groovy script will receive header name from content modifier of IFLOW and return header value. By this way, we can configure dynamic for these value of EDIDC_40 control record of IDOC.

    This is integration flow for inbound IDOC from POS/NON-SAP to S/4

    This is configuration for content modifier

    With IDOC adapter receiver, we should be use with REQUEST REPLY to get response from S4 to CPI.

    This is payload response

    So, after this step we will use content modifier and groovy script to set custom header

    Add header name is IDOCNUM with value is //ns2:DbId/text() and data type is java.lang.String

    Take focus for prefix namespace NS2, we will set namespace prefix

    After all, we will have result

    For search in Monitor Message Processing

    III. Logging in Outbound Scenarios with header in MPL

    All of thing the same in scenario inbound, for outbound scenario, send message type DEBMAS from S4 to POS/NON-SAP. We set header in content modifier

    And add one field at tab Exchange Property for Custom Status : SAP_MessageProcessingLogCustomStatus

    This is result

    SUMMARY

    In this article, I talked about monitoring message in CPI with headers. I also talked about how to set dynamic value for IDOC control record from header value outside into message mapping by using groovy script. Thank you for your reading and any advise kindly leave your comment on this. Thanks.

    JOSEPH.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s

    This site uses Akismet to reduce spam. Learn how your comment data is processed.