SAP PI / XI: Java XML Filter Utility
Applies To:
SAP XI 3.0, PI 7.0 and 7.1, 7.3 and SAP PO
Summary:
This paper discusses how to identify & filter out the flawed records from the source file based on certain conditions.
Author:
Anupam Chakraborty
Sudip Kumar Paul
Prasanna Vittal
Created: January 6th 2014.
Introduction
More often than not, while dealing with business interfaces, we have situations where we encounter issues with data, leading to the failure of the complete interface even though only a small percentage of the data has issues. Hijacking business for such reasons is uncalled for and can be avoided in certain cases. If could identify & filter out the flawed records from the source message based on certain conditions(business rule), and only pass the correct records to the target system, then we can get our job done. The flawed records(data) can be written to a separate file/error logs which business can review and correct at a later point of time.
This approach can be generalized and can be achieved by a utility a.k.a. Filtering utility which could be made plug-and-play and configuration only.
IT Requirement
- The input message coming into SAP PI might contain flawed records(data issues).
- While the mapping gets executed, it fails entirely since there is error in one/few of the records.
- The idea is to filter the message before the mapping gets called so that the maps get executed only with the correct records, whereas the bad records are sent back to some file server as-is.
This Utility (Java class) can be used by just plugging it into any message mapping. No development time is required. Only some additional configuration needs to be done, which will be explained in the next section.
Solution
The salient features of the solution are as follows:
- Generic solution which could be re-used across multiple interfaces
- Configuration only solution; no development time required for each interface once the solution is completed.
- This solution is parameterized so that it is flexible enough to cater to different kind of requirements.
The solution works as follows:
- Java Mapping is used for filtering the erroneous records from the good ones.
- The good records are then mapped to the required target message and pushed forward.
- The erroneous records are written to a file and sent to a specific location
- An alert is raised with the location where the error file is written.
The Filtering Utility(Java class) written for filtering the records is capable of doing the below functionality:
- Fields to be checked and conditions for the fields are read from Value Mapping. The value mapping is based on the Sender Component, Sender Service Interface and the Receiver Component. This way we can uniquely identify the value mapping set for each interface.
- Parsing the xml message and breaking down into good and bad records.
- The filtering of good and bad records is done based on certain condition checks on specific fields.
- For any message, if the header is wrong, then the entire message is considered as erroneous.
Implementation Guide
Let us consider an example of a File Server sending an XML file to SAP. Below is the structure of the source message:
The requirement is that, we need to filter out all the records that contain a blank for the field MaterialNumber
1.1 Design Steps
- Import the Java Map CheckXPath.jar as an imported archive
2. Create a one to one graphical mapping by using the above structure on both the sides.
3. Create operation mapping with source and target interfaces. Under Mapping Program, first add the Java class and then add the graphical mapping
4. In Value mapping, create the below parameters:
Sender Agency: | <Sender Business Component> |
Sender Scheme: | <Sender Service Interface> |
Receiver Agency: | < Receiver Business Component > |
Receiver Scheme: | JavaFltrClass |
Value Mappings
ErrorFilePath | This parameter is used to pass the name of the file in which flawed records will be stored. |
IsTraceOn | Optional Parameter if you want to set detailed Trace to On or Off |
NumberOfValidation | Number of field to be validated <n> |
XMLFormat | Specify the recordset structure here. For our case, it is row,* |
XMLValidation<1> | Provide the xpath and the validation row:/row/SAPMaterialNumber,notBlank |
XMLValidation<..> |
|
XMLValidation<n> |
|
1.2 Allowed Validation
- DateFormat-<Java Date Format>
Checks for the field with date format given in the format specifier
- notBlank Check if the field is not blank
- Exist Check if the field exist in the payload
- NumberOnly Check if the field is numeric
- FieldLength<n> Check if the length of the field is equal to n
1.3 Creating Alert Category
- Go to the transaction ALRTCATDEF in the ABAP stack of the PI system.
- Create an alert category XPATHALERT
3.Create the below container objects. These will be used in the body of the alert message, to provide the PI message details in the alert.
4 .Provide details under long and short text.
1.4 Alert Configuration in RWB
- Go to ‘Alert Configuration’ under Runtime Workbench.
- Click on ‘Add Rule’, and provide our sender interface name and save the rule.
3. Attachment Guide Content
Java Mapping Source