SAP PI 7.1 Mapping Enhancements Series: Copy XML Subtree
CopyXML is a new feature in the Message Mapping tool of PI 7.1. This feature can be used when we wish to copy an XML subtree from the source to target, exactly as is. Why is this so special? Well, by using this tool, we do not need to define the target elements and only one elemet-to-element mapping is required, no matther how many elements are in the subtree.
In this blog, I will discuss on how to use this feature and when the feature will not work or cannot be used.
Let’s take a look at the following mapping requirement:
We have a simple customer order document. The source has an address; the target has a billing address and a delivery address. We want to copy all the elements in “address” of the source to “BillingAddress” and “DeliveryAddress” of the target.
As you will notice, the target does not have all the elements defined.
Assign the Mappings:
- Double-click on “BillingAddress” of the target, and double-click on the “address” of the source, just as in the previous releases when we want to map from 1 element to another.
- Drag a direct mapping line between these 2 elements.
- Right-click on “address” and select “Return as XML” in the dropdown menu.
- Repeat the steps to map “address” to “DeliveryAddress”.
Verifying the mapping:
Below is the result of the mapping. All the elements in “address” have been mapped to “BillingAddress” and “DeliveryAddress”.
As you can see, the complete subtree of “address” is copied under “BillingAddress” and “DeliveryAddress”. And, we did NOT define any of the “address” elements in “BillingAddress” and “DeliveryAddress”.
But, what happens when…
As you will notice, under “BillingAddress”, there is an element “address”:
Now, let us map something to it. It does not matter what, any mapping will do. In this case, we will just map “Street” to it.
Let’s us take a look at the result of this mapping.
The “address” subtree was not copied to “BillingAddress”. So, when there is any mapping done to any of the sub-element of the target node, that mapping will take priority and void the CopyXML done to that target.