Best Practices – Message Mapping

Facebooktwittergoogle_pluslinkedintumblr

As a part of my SAP TechEd presentation on best practices, I would like to share some common problems that I see with SAP message mappings.

If you are not an experienced SAP PI/PO developer, you may be missing some of the patterns. It could make your mappings miss contexts, thereby rendering them error-prone. The bad thing about some of the context errors is that you only find these errors if you are lucky, or in case you don’t understand the data in your ERP system. One of my former clients had a context error in a mapping, and they first noticed the error after 6 months, because someone in the business could not make sense of some data. The moral of the story: you need to be careful when dealing with contexts; also keep in mind that it is not enough to just do a simple test. This is why I am stressing that the second part of the post is of the utmost importance.

 

Selection

Sometimes you can make things a lot simpler with the help of the FixValue mapping instead of using an if/then/else node.

SAP Mapping

SAP Mapping

 

FixValues is a fantastic tool for these kinds of conversions, and it makes it much easier to read what is going on.

The second pattern is much the same. Here you have to input elements, and to select values for them. You would use a concat to concatenate the two values; then you could use a FixedValue table with the different possible options. This way you can easily assess the differences and the possible outcomes of the development.

SAP Mapping

SAP Mapping

Contexts

The most complicated mappings are those that have to be done in locations where you have lines and context – and you want to map on them. The common way of mapping lines is to remove the lines that you don’t want by collapsing the context, only letting through the values of your choosing. The downside of this is that you also need to filter all elements. It can be somewhat challenging if there are locations where you are missing some nodes, as the text could be moved to the wrong context, thereby to the wrong line, as opposed to your expectations.

The approach that I find to be better is having the createIf element. This will make things easier at line level. You just need to have a simple mapping at line item level, because the filtering is done at the line level.

SAP Mapping

SAP Mapping

For the patterns that are on a nested line item, you will get a much more complex structure. In this case, we have a pattern where we want to query the material type. Sometimes the materials you have do not have any of the E1EDP02 segments, and you have to take care of them. This could mean that things will change, and you’ll need to have mapWithDefault on most of the elements; you will probably also have to use formatByExample. This can lead to some context problems with your mappings that will make it difficult to ensure that the data is in the right context.

The other approach is to use selectXML from FigafTools. This is XML-based and simply allows you to select any file based on a qualifier; the output consists of all the elements that have this text value. It is good for 3rd level structures, e.g. E1EDP02, or for instance the Text fields in IDocs.

SAP Mapping

SAP Mapping

If you want this node you can get more details regarding the selectXML UDF in FigafTools at http://scn.sap.com/community/pi-and-soa-middleware/blog/2014/05/02/find-the-right-data-with-simple-context-selection

I hope that you enjoy exploring these elements. Are there any other elements that seem to create a lot of errors? Do you think some of them could be improved? Let me know in the comments!

 

Facebooktwittergoogle_pluslinkedintumblr

1 Comment

  • swati

    August 12, 2015

    Really helpful.