Skip to Content
Author's profile photo Former Member

Access BRM decision table from PI message mapping

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.

Assigned Tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Harish Mistri
      Harish Mistri

      Thanks for sharing the wonderful feature, this would help to move not only value mapping but some of the custom table (ABAP or external) to BRM.

      Author's profile photo Anshul Walia
      Anshul Walia

      Thanks for sharing it ..

       

      Author's profile photo Bijayashree Banoj Brahma
      Bijayashree Banoj Brahma

      its a nice blog. But kindly share how to create and edit rules and decision table. Also mention how to update decision table entries.

       

      Author's profile photo Former Member
      Former Member

      Good blog, Kevin

      Author's profile photo Federico Abait
      Federico Abait

      Hi Former Member

      Thank you for your blog, it's very helpful but I can't see the images. Would you be able to check the images again please?

       

      Many thanks

      Fede

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Fede, images are now visible again. 🙂

      Author's profile photo Federico Abait
      Federico Abait

      Thanks very much

      Author's profile photo Sergi Segura
      Sergi Segura

      Thanks Former Member for your blog, it is really helpful. Unfortunatelly I cannot see the images anymore. It is possible to reupload them?

       

      Thank you!

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Images are now available again. 🙂

      Author's profile photo pratibha singh
      pratibha singh

       

      No Images

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Added

      Author's profile photo Amlesh Singh
      Amlesh Singh

      Hi Kevin,

       

      can you please suggest how to call BRM table from XSLT mapping?

       

      Regards,

      Amlesh

      Author's profile photo Easy Jasunai
      Easy Jasunai

      I'm getting an error cannot "RuleEngineLocalHome cannot be resolved to a type". Seems I'm missing some Library/jar of this class file to the project. Would you please help here what is missing?

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Check step 3, you are missing the dependency to tc/brms/facade

      Author's profile photo Torsten Uhrenholdt
      Torsten Uhrenholdt

      Thanks for this fine blog. We have tried to do this, but are having trouble with the rule not answering. We have found the following error in the java log.

      com.sap.brms.qrules.network.InsufficientDataForEvaluationException: Could not resolve elementMT_CountryNameSchema:ns1:MT_CountryName

      We think i must have something to do with the xpath that is used for every element i the decision table.

      Could show what the xpath is for the elements sourceSystem, targetSystem, inputvalue.

       

      Author's profile photo Torsten Uhrenholdt
      Torsten Uhrenholdt

      We solved the issue.

      We read your blog once more and found that we had made the rule before the class. And had not made a rule based on the fields from the class. Thanks.