Scenario: A requirement may be to process an empty file (empty payload) having no data, to run a mapping program.

In my case it is a file to JDBC scenario, where I had to insert records when file had data. If the file was empty then I had to delete all the records in the table.

We are using PO 7.5. But this solution could be used on lower versions and dual stack as well.

Why do we need this tweak?

By Default the mapping is terminated when there is no payload/ input size is 0 bytes.

Input file is empty/ 0 bytes:

Error when executing the map:

Error during Run-time:

 

 

Solution:

  • Java map to alleviate the issue of empty payload. Java map provides the XML input to the graphical mapping.
  • Standard context object – SourceFileSize in Interface determination condition, to separate empty file and non-empty file.
  • ESR Mapping Objects – 2 Operation Mappings, 1 Message Mapping.

Java map for our case was a simple if condition in the transform method. When the input is empty then a default XML structure is written to output. During normal transmission (file with Data) input is passed on as output. (We can write the entire transformation logic in the Java Map – but we delegated business logic to Graphical Mapping for ease of maintenance.)

Include this line with choice of XML structure in the transform method of the mapping class – This will default assigned XML Structure when an empty payload is passed.

 

StringBuffer xmlStr = new StringBuffer( “<?xml version=\”1.0\” encoding=\”UTF-8\”?><ns0:Message_Type xmlns:ns0=\”XYZ\”> <Record> <Field1 /><Field2 /> </Record></ns0:Message_Type>”);

 

String inputContent = new String(b);

 

if (inputContent.trim().length() == 0) // This condition checks if the input is empty

{

out.write(String.valueOf(xmlStr).getBytes());

}

else // When actual input is present the input is transferred as output.

{

out.write(b);

}

 

Operation-Mapping for case – Empty file (size 0 bytes). (Java map before Graphical Map)

Operation- Mapping for case – File with Data

Integration Directory Configuration:

 

Result: Processing Empty File to run a delete operation on the database table.

References:

https://blogs.sap.com/2015/02/08/how-to-create-java-mapping-in-sap-pi-po/

https://help.sap.com/saphelp_nw73ehp1/helpdata/en/4b/f416d3eaca4c86e10000000a42189e/frameset.htm

 

SAP Note:  1883809

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply