5.7 Value Mapping
By now, you’ve become comfortable with the notion that an enterprise service bus (ESB), such as SAP PI or the AEX, is used to enable the exchange of messages between two or more systems. The messages contain business data that the sender system wants the receiver system to become aware of.
The data to be exchanged isn’t always represented in the same manner in the sender and receiver systems. System X could be using values such as male and female to represent an employee’s gender, whereas system Y could be using numeric values instead, such as 1 for male and 2 for female. Typically, when a message containing employee data has to be exchanged between these two systems, a translation of those two ways of representing the same data needs to be performed. The value male from the source system will need to become 1 in the target system. This form of translation is called value mapping in SAP PI or SAP PO. SAP PO is equipped with three core ways to achieve value mapping:
- Use if/else logic (see Figure 5.22)
- Use the fixed values function
- Use the value mapping function
In addition to these three methods, you can also use SAP Business Rules Management (SAP BRM) to achieve data translation, which is discussed in Chapter 13. The next section will explore each of the previously listed value mapping methods.
5.7.1 If/Else Logic
In this method, you’ll implement some conditional logic to accomplish the value translation. This can be achieved purely from a message mapping or via a UDF.
As Figure 5.22 shows, this can prove to be a cumbersome and difficult-to-read approach. It’s especially not a suitable approach if you’re dealing with a large amount of values to be translated.
Figure 5.22 Cumbersome Way to Achieve Value Translation with If/Else Logic
5.7.2 Fixed Values
As its name states, fixed values are intended to enable the translation of fixed values that very rarely change. Fixed values also generally contain a finite or small set of data. Fixed value mapping is maintained in the ES Repository and is often used in message mapping (see Figure 5.23).
Figure 5.23 Fixed Values Table Example in the ES Repository
To add fixed values, you’ll need to be in a message mapping (in the ES Repository) and to select it from the set of SAP-provided functions, under Conversions • FixValues.
As Figure 5.23 shows, these particular fixed values contain a translation for industries. The source system contains industry data and their names, whereas the target system requires numeric values for each of the industries.
Some of the disadvantages of using the fixed value mapping include the following:
- Maintained in the message mapping, which implies that a transport is needed with every change made
- Lack of flexibility because only fixed values can be used
- Can’t be called outside of the message mapping in which it was created and can’t be reused
5.7.3 Value Mapping
Value mapping can be used to translate different representations of the same data in different contexts or systems using a dynamic method (see Figure 5.24). The data is saved in the SAP NetWeaver database internal table.
Figure 5.24 Example of a Value Mapping That Converts One Value (Color) to Another Value (Number)
Value mappings are loaded in the cache during runtime, which means that value mapping is a very fast method to achieve data translation and is better suited for the job when the data to be translated is subject to frequent changes. It’s better than the fixed value mapping because the data is maintained in the Integration Directory and can (in theory) be changed without the need for transport.
In value mapping, the data is categorized under agencies and identification schemes. The agency and scheme will need to be defined for the source and target system. Therefore, you can create different representations and groupings of data.
There are two main approaches to populating value mappings:
-
Manual approach
Select the required value mapping category (in the Integration Directory), and add a new value entry or update an existing one. -
Replication from an external source
With this approach, the translation table already exists in some other source (e.g., in SAP ERP), and you want to copy or replicate the data to a value mapping. The data replication is made possible via a standard interface.
In SAP PO, value mapping can be used by different mapping programs. With the message mapping, for example, you can make use of standard functionality to call value mapping from your mapping by choosing Conversions • Value Mapping. You then need to configure the agencies and schemes to match the ones that you configured in the Integration Directory.