My previous post discussed the “hidden” menu in the SAP PI message mapping tool that can only be unlocked by pressing <Ctrl> + <Shift> while right clicking in the data flow editor area. Hands down, the best feature of this menu is the import/export functionality. I have no idea why the SAP developers buried such a useful feature in such a hard-to-find menu. Whatever the reason, now that we know that we can import and export message mappings, we can exploit this fact to make our map-developing lives easier.
Most SAP PI developers have had a situation where a relatively minor change to the target message causes real havoc to the entire message mapping. For relatively small maps, it may not be a big deal. For maps with complex logic, this can be a big deal requiring hours of tedious rework. Recently, I was faced with a requirement change that required my message mapping to change correlations from 1:1 to 1:N. Since this interface used the RFC adapter (which supports multiple messages), I was able to implement a 1:N multi-mapping message split. In the new interface design, the file adapter will process one file and pass it to the integration engine. The integration engine will perform a multi-mapping message split to break-up the message. The new, individual messages will be sent via one adapter engine call to the RFC adapter. The RFC adapter will handle each message individually, calling each in a separate logical unit of work (LUW).
The steps below will detail how to switch a message mapping from a 1:1 correlation to a 1:N correlation without remapping anything!
Note: The steps outlined below assume a moderate understanding of SAP XI/PI and gives does not give comprehensive instructions for every step. Please post any questions to the comments section of this blog.
- Step 1 Before starting anything, make a safe copy of your message mapping. This will give you the ability to perform before and after comparisons and afford you some protection if something were to happen to your original mapping
- Step 2 Use the hidden menu command (<Ctrl> + <Shift> + right click for those of you not paying attention) to download the current version of your message mapping. SAP PI will save a file with the extension .mte.
The .mte file you just exported is really just an XML file. Opening the .mte file in Internet Explorer will yield something that looks like this
The entire message mapping is contained in the file, including any user-defined functions, brick layout, and test cases. This will be very useful!
- Step 2 Change the target occurrence in the message mapping. This is done on the Messages tab of the message mapping.
Changing the occurrence on the target message appears to have little effect on the message mapping, until you switch back to the Design tab and you see this ugly message box:
Oh noes! PI added <Messages> and <Message1> tags to the source and target messages! Since the target message structure changed, all of my hard-fought mappings are lost! Who can save me from hours of tedious remapping?
Fear not, plucky mapper, in a few steps, you can save the day by converting the entire map without remapping a thing!
- Step 3 Use your favorite text editor to open the .mte mapping file. We will use the find/replace functionality to mass change the source mappings. You will need the services of the copy of the map you made in step 1. To get the value to find, copy the path of the root node in the unscathed map. To get the value to replace, copy the path of the node just below the <Message1> node in the new map.
Here is the find/replace text for the example in the graphic:
- Step 4 Repeat step 3 for the target message.
Save the .mte file in the text editor
- Step 5 Providing you didn’t inadvertently screw something up, you should be able to import the .mte file to the Integration Builder
- Step 6 Now change the occurrence on the corresponding interface mapping to match the message mapping occurrence set in step 2. Save and activate all of your changes.
- Step 7 The final step is to change the Interface Determination in the Integration Directory to utilize your new multi-mapping message split.
As you can see, the ability to export/import message mappings can really save you a lot of time. If you have any other tips regarding message mapping export/import, please share the in the comments.