One of most common message interface types I worked on is implementation of Message Filter pattern. Let’s assume we have simple File -> SAP PI -> File interface with message having multiple items and the interface purpose is to allow only few of them for further processing. Usually implementation of this interface is pretty straightforward – just use message mapping to filter unwanted items and output only right ones.  However that if in one particular message ALL the items would be filtered? Right, we will have the message with one root node only. It goes without saying we don’t want to write output files with no real data, this corner case could simply broke anything on the other side.

However, if you are using File adapter to write the data to output (on the file system or FTP) SAP PI allows us to cover this corner case. There is a setting for File Receiver adapted “Empty-Message handling” that allows to choose how to handle empty messages. We can to choose “ignore” and in this case all empty message will be ignored. The main problem is “empty message” means literally empty, i. e. 0 bytes length, so our message with one root node will be processed as usual. Unfortunately, it’s impossible to make “real empty” message using Message Mapping or XSLT transformation. However we still could do it using Java Mapping.

Here is listing for Java Mapping that checks if root node has any children and if not – outputs with empty message. Just use this mapping as last transformation step in Operational mapping pipeline and this will allow you to use “Empty message handling” feature. Please be aware, you will not be able to call other mappings or custom adapter modules after this mapping in pipeline sequence, most probably next mapping would fail then trying to parse empty message payload into XML.

 

SAP PI File Receiver Adapter: Better utilization of Handle Empty Message feature
Tagged on: