Oct 11

Simplify SAP PI Mapping Logic with FixValues Mapping

I was trying to think of something to write about this weekend, when I happened to stumble upon this gem:

After I stopped laughing, I started to cry, because I realized that this happens all the time in SAP PI–it just looks a little different…

However, most of the time complex mappings can be simplified by using a different approach.  The mapping block FixValues is a great tool to reduce needless. So let’s expand on this example.

Reducing Complexity with FixValues Mapping Block

Let’s say I am developing an interface between a database with information about goods/materials  and a file for system that needs the database data in an easy to read format. To help visualize here is some pseudo-XML of the database:

<Database>
  <row>
    <goodName />
    <goodType />
    <goodQuantity />
  </row>
</Database>

And here is some pseudo-XML of the file layout:

<Report>
  <row>
    <goodNumberUOM />
    <goodName />
   </row>
</Report>

In this example, the database categorizes goods by a category code (A-Z). The type of good determines the unit of measure.  In this imaginary scenario, maybe all but 5 categories have unit of measure assignments.  Everything else has the unit of measure of furlongs.  If we were converting the values using code (ABAP, perhaps?), we could implement the logic using a case statement:

  CASE L_CATEGORY.
    WHEN 'D'.
      L_UOM = 'pounds'.
    WHEN 'C'.
      L_OUM = 'ounce'.
    WHEN 'B'.
      L_OUM = 'kilogram'.
    WHEN 'Y'.
      L_OUM = 'Units'.
    WHEN 'Q'.
      L_OUM = 'SQFT'.
    WHEN 'J'.
      L_OUM = 'Other unit of measure'.
    WHEN 'G'.
      L_OUM = 'Quarks'.
    WHEN 'F'.
      L_OUM = 'Kilograms'.
    WHEN 'E'.
      L_OUM = 'Units'.
    WHEN OTHERS.
      L_UOM = 'Furlongs'.
  ENDCASE.

But how would we accomplish the same using an SAP PI message mapping? Well, one option would be to implement the logic with nesting IF blocks, but that has the nasty side effect of producing the messy message mapping shown above.  Another option is to implement the case statement in a UDF.  But a simpler option exists.  Use a FixValues mapping block.

Here is the same mapping logic using a FixValues mapping block:

And here are the FixValues settings:

Another favorite trick of mine is to use FixValues to evaluate TRUE and FALSE. This can be useful on filtering at the root level (e.g. a requirement to not send a record when the good is a type not relevant to the report you are generating).  In this example mapping, the row will not get generated if the type isn’t a D, A, T, X, S, R, E, or M:

And here are the FixValues settings:

The FixValues mapping block is a very useful message mapping block that can be used to streamline complicated SAP PI message mappings.

Avatar

About The Author

1 Comment

  1. […] Links: Simplify SAP PI Mapping Logic with FixValues Mapping [www.dataxstream.com] Value Mapping Techniques Comparison [Ruslim Chang] Conversions in Graphical Mapping (XI) […]

Leave a reply

Your email address will not be published. Required fields are marked *