Enhanced Receiver Determination in SAP XI
In this wiki I am going to discuss Enhanced Receiver Determination taking example of a project that we had executed.
One activity which is common among all the interfaces is data validation of header fields present in source message. If header validation succeeds then source data should be mapped to target data and sent to SAP system. If header validation fails then a negative acknowledgement message with appropriate error message must be sent back to source system. We need to use conditional receiver determination. The scenario is as given in below screen
Technical Challenge Faced:
Conditional Receiver Determination:
One limitation in case of conditional routing is that we cannot do conditional routing based on target data. We can do it only based on source data. So the logic of taking an extra flag field in target xml structure , setting it during mapping after header validation and doing routing based on this field is ruled out.
1. Standard Receiver Determination: Use XPATH Expression to formulate a condition for deciding receivers. We cannot base our condition on any field in target message type. We will have to formulate condition for each receiver possible in the flow. We need to create a XPATH expression of source fields which will do the validation activity. But if fields are greater in number and validation logic is complex we cannot implement it into XPATH expression. We have to move validation process to message mapping. If we do validation process in receiver determination we cannot reuse the validation function for other interfaces in case source data structure is same across interfaces
2. Enhanced Receiver Determination : Logically, the Receiver Determination step comes before the Interface Determination step, where the mapping runtime occurs. But since the information in target message is function of the information in the source message (target = f(source); mapping is nothing else more than a linear transformation over source message). We can use the same function in the receiver determination condition in order to get the same check on source message. Since validation function is complicated, we can use it inside a mapping (UDF, java mapping etc) in an enhanced receiver determination. We chose this approach.
SAP Metadata for Receiver Determination.
For implementing Enhanced Receiver SAP has provided message interface ReceiverDetermination is in the Integration Repository in the software component SAP BASIS (namespace http://sap.com/xi/XI/System).
The message interface uses the message type Receivers and the data type Receivers. The data type Receivers describes a list of receivers.
The following instance of the data type Receivers contains two receivers. We can specify party and service for each receiver.
Step for implementing the second approach
To implement enhanced receiver determination we just have to add an additional mapping in IR. This is how we should do it.
1. Create an additional Message Mapping for determination receivers through user defined function.
2. Take Source Message Type in the message mapping.
3. Select 'Receivers' Message Type (present in SAP Basis namespace http:// sap.com/xi/XI/System) as target Message Type.
4. Develop a java code (UDF) for validating header fields in source message.
5. Sample UDF could be
Set 'SAP Service' in Service of ReceiverDetermination.
Set 'Websphere' in Service of ReceiverDetermination.
Even with this kind of UDF , we need to know all the possible receivers at configuration time.
Enhancement in the Mapping :
To make the solution more generic we can take all possible receivers name in a table in SAP System or any repository system. So during mapping we need to do RFC lookup (in case of SAP system) or database lookup to read the receivers from table. We don't need to know name of all the receivers and we can add additional receivers in the flow without disturbing existing XI code. We can also manipulate the flows by changing the table with appropriate receivers. These two alternative examples have been described in pictorial format below.
6. Develop Interface Mapping between source Message Interface and 'ReceiverDetermination' (present in SAP Basis http:// sap.com/xi/XI/System) as target Message Interface.
7. Activate the mappings.
8. Go to Integration Directory. Select Enhanced option in RecieverDetermination.
9. Select the Interface Message developed above. Don't add any receiver name.
10. Create Interface determination , sender agreement and receiver agreement.
Benefit of the Approach.
1. In standard receiver determination, we cannot formulate complex XPATH expression. For that we use an enhanced receiver determination to have a mapping program determine the receivers of the message dynamically at runtime.
2. Moving routing logic to mapping gives more flexibility. We can read receiver names from external database or SAP System by database lookup or RFC lookup respectively in a scenario where receivers name are not know at configuration time.
3. There is greater chances of reusability. In case source structure is same across many interfaces then java function for validation can be uploaded in Integration Repository as jar file in base software component and can be used in all the interfaces.