During system integration in SAP PI, one of the most common things we generally encounter is value translation (or value mapping). And SAP has provided various approaches to handle it, for example using:
- Fixed values in SAP PI message mapping
- Value mapping defined either in the SAP PI Integration Directory or via a value mapping replication interface
- BRFplus decision table or custom table in a SAP backend (e.g.: ECC)
- BRM decision table via web service or Java Session Bean call
In this blog, I am going to focus on the option of using a BRM decision table, and how to access it directly from a UDF (User Defined Function) library without any web service calls. In my opinion, this approach has the following advantages:
- Allowing more than 1 input conditions
- Import and export from/to excel files
- Better performance than accessing BRM decision tables with web service calls
- Less coding compared with SAP ECC backend BRFplus and custom tables
- Possibility of also utilizing other functionalities provided by the BRM rule engine
Here, I am going to use packaging material conversion for demonstration purposes. Below is a snapshot of how the SAP BRM decision table looks like. The yellow columns are conditions, and the green column is the desired outcome.
To achieve our purpose, we need to create a list of objects:
- Development component: value/mapping/ejb (it contains a Java class for building the BRM application and a Java Session Bean for accessing the BRM application)
- Development component: value/mapping/ear (it is an EAR project for deploying EJB into SAP PI runtime)
- Development component: value/mapping/brm (it contains BRM development)
- UDF library in the ESR: ValueMappingUDF
- Message Mapping in the ESR: MM_ValueMapping
Below is a step by step instruction.
1. Create “value/mapping/ejb”, add Java class “ValueMapping” and declare public part
Open your NWDS and switch to the “Development Infrastructure” perspective.
Inside the EJB development component, create a Java class called “ValueMapping” with all get and set methods (as shown below).
Note that later on we will use it for building BRM rules and decision tables.
Then go back to the NWDS Development Infrastructure perspective to declare a public part.
After declaring the public part, right click on it and then choose “Manage Entities”. Add the Java class we just created to it.
2. Creating “value/mapping/brm”, add dependency and create the BRM application
The process of creating a BRM development component is pretty much the same as creating the EJB development component, but remember to choose development type of “Rules Composer” instead. No need to repeat the steps here again.
After creating the BRM development component, stay in the NWDS development infrastructure perspective, because we need to add a dependency from the BRM component to the EJB development component.
Now, we can switch to the NWDS perspective “Rules Compose” to create a ruleset, a rule and a decision table. One can refer to SAP help document (“Writing Rules on Java Classes”) if helps are needed. Below is how the BRM rule and decision table looks like.
3. Add dependency for “value/mapping/ejb”, and create a Java Session bean for accessing the BRM application
In order to access BRM rules and decision tables, we need to first add a dependency to standard SAP development component “tc/brms/facade”. So go to NWDS development infrastructure perspective.
Next, switch to NWDS perspective “Java EE” to create a Java session bean. The session bean is later on to be called from a UDF library for accessing the BRM decision table.
4. Creating “value/mapping/ear”, add dependency and deploy applications into SAP PI runtime
The process of creating an EAR development component is pretty much the same as mentioned in step 1, the development type is “Java EE >> Enterprise Application” however.
It is important to remember to also add the dependency to “tc/brms/facade” (and this time also check Deploy Time, Runtime and Build time dependencies, as shown below).
Then, deploy the EAR and BRM development components into the PI runtime.
5. Create an UDF library “ValueMappingUDF” in ESR
The main idea of accessing BRM decision tables is through the session bean we have developed (using either the local or remote interface depending on the SAP PI system setup). To access the session bean from the UDF, we need to use the technique called Java Reflection. Below is the complete code of the UDF library.
OK, we have now completed all the developments. It’s time for testing …
6. Testing in SAP PI message mapping
A message mapping is created for the testing purpose. It looks like below:
The first simple test only includes two records.
Then to verify the performance, add 5 000 records into the BRM decision table, and repeated the Material element in the source message 50 times. Are you wondering how does it impact the performance?
Voila, it only took 221 milliseconds to complete the test! So performance wise, I think it’s quite good.
Want to learn more about SAP BRM? Buy our book form the official SAP store.