Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
christianlechne
Active Contributor
7,790

tl;dr


This blog post compares the concepts of the two business rule management systems BRFplus and SAP Cloud Platform Business Rules to enable your shift from  BRFplus to the SAP Cloud Platform service in an easy manner. In addition, hints are given to avoid some pitfalls that you might come across when first using the SAP Cloud Platform Business Rules.

Motivation


In the third quarter of 2017 the roadmap for the Business Rules in the SAP Cloud Platform (SAP CP) was published (SAP CP Business Rules - Official Roadmap). The slide on the vision about the service made it quite obvious that at minimum it should be kept on the watchlist. The vision is to make it the central place when it comes to business rules as can be clearly seen on the slide:



So, digging into the topic definitely makes sense.

Some blogs about how to setup and use the service have already been published here in the SAP community. Consequently, the question could arise: "Why write another one on that topic?" The reason behind that is to elaborate the concepts of SAP CP Busines Rules compared to BRFplus (as established Business Rule Management solution).  Comparing the concepts should help to make the transition for users of BRFplus smoother. From my experience, such a transition is always easier when comparing the concepts of the different worlds and highlight the equality and differences.

In addition, I will put a spotlight on some pitfalls you might come across (at least I ran into them when getting my first hands on the service) and I will put some (at least from my perspective) open issues and points that leave room for improvement in the SAP CP Business Rules.

It is not the intention to address functional gaps between BRFplus and SAP CP Business Rules as this would be unfair – BRFplus is out for several years (is it already a decade?) and SAP CP Business Rules are a new kid on the (business rule) block. So even when two concepts are comparable this does not mean that they also have functional parity.

The structure of the blog picks up the typical flow when creating a rule service so we will walk through the design and the call (at least for a testing purpose) step-by-step.

Precondition


If you want to follow the steps in the SAP CP and use the service for the first time it is the usual game that you must play to be able to make your hands dirty:

Step 1: Activate the Service “Business Rules” in the SAP Cloud Platform (this will basically activate the service and create destinations in your subaccount).

Step 2: Assign the relevant roles to your user to have the authorization to model and call the SAP CP Business Rules.

This procedure is described in the blog https://blogs.sap.com/2017/04/26/sap-cloud-platform-business-rules-try-it-yourself/

The Comparison


Disclaimer


The screenshots are intended to depict the single steps of rule creation in SAP CP Business Rules. The names of the objects shown in the screenshots are not what you should use in a project nor should you use that at home (even if nobody watches you, do not do this - however, I did). Names, wherever used in rules, should always be human readable. When reading this blog focus on the structure of the screens and not on the names.?

General Remarks


The functionality in the SAP CP Business Rules editor is comparable with the BRFplus workbench: you can edit objects, save them in an inactive state and activate them. In contrast to BRFplus there is no mass activation of objects, so as a first advice: whenever you are finished with editing an object, save and activate it. Otherwise, you will busy with resolving activation dependencies at a later point in time manually (I tried it, definitely no fun).

A Container for the Rules


The very first thing you do when working with BRFplus is the definition of an application that acts as a container for your BRFplus objects. The application allows you to configure global attributes of your BRFplus objects like language or currency. Most importantly you must define a storage type that influences the extensibility of the functions (system storage vs. customizing storage).

The SAP Business Rules implement a comparable concept. When you start the editor from the service area in the SAP CP you will be directed to the “Manage Project” area.



In the cloud service, the “Project” is the counterpart to the BRFplus application serving as a container for rule services. The data input on this level is restricted to namedescription and target runtime variant.

 

Name and description can be compared with name and text in a BRFplus object. This statement is true for all objects in the service.

The target runtime variant has no counterpart in BRFplus. This setting reflects the future option to deploy the rule models to different runtimes (as depicted in the roadmap slide above). Currently, the only option available is “Cloud”. This setting is available on every object where this makes sense to define it. This setting can be seen as the counterpart of the Partner Exit in the SAP Decision Service Management that enabled a partner to implement the deployment of BRFplus functions in non-ABAP environments.

This leads to the following table of comparison:

























“BRFplus-ish”  



“SAP CP Business Rule-ish”


Application Project
Name Name
Text Description
 DSM: Partner Exit in Deployment Target Runtime Variant



The (Inter) Face of the Rules


Next thing that you usually do in BRFplus is the definition of the BRFplus function as an interface to your rule sets and consequently, also the data objects that you need as context and result. The relation between an application and a BRFplus function is 1:n, an application can contain several BRFplus functions. What came in handy was that you could define data objects for the context and the result directly from the function itself by creating new objects.

The concepts are basically the same in the SAP CP Business Rules: the counterpart for the BRFplus function is the Rule Service.



The term data object is used in both environments in the same way.

However, the (usual) flow of creating the objects differs a bit in the SAP CP compared to BRFplus: You must create the data objects first and only then you can assign them to the rule service. There is no option available to create data objects “on the fly” from the rule service dialog.
As a remark: This flow is reflected by the order of the tabs in the project. When starting a new project you can interpret the tabs in a project as to do list that you have to work through according to their order.

The creation of a data object in the SAP CP Business Rules has some different aspects than when working with BRFplus objects.



While the basic data (name, description) are the same you can only define two types in the SAP CP Business Rules: structures and tables. As in BRFplus tables reference structures (field “reference data object on the screenshot). The creation of a single element by itself is not possible as this is not a valid type. This is by design as the SAP CP Business Rules deals with entities when calling the REST API (we will see that later)The BRFplus component names of a structure are called Attributes. As data types you can assign so-called Business Data Types that correspond to the built-in element types of BRFplus



In BRFplus your definition of a data object finishes here. Due to the nature of the Business Rule Service and its future goal to deploy the content to different runtimes (e.g. Java or JavaScript) in different runtime variants (e. g. SAP Cloud Platform Java Runtime or SAP HANA XSAyou must define mappings for your attributes as their properties might differ depending on the concrete runtime e. g. with respect to precision, size etc. This is achieved via navigation from the attributes (not really intuitive imho): 



The attribute mappings must be done per target runtime and target runtime variant.  



Currently, the only option is “Java” and “Cloud” so you can go with the defaults and again navigate one level deeper to the mapping itself



Hint: If you change the type of the attribute, make sure to adjust the mapping as this is only defaulted once and not derived automatically when changing the type of the attribute.

In addition, a new concept called “Associations” is available that has no counterpart in BRFplus. As the name suggests this concept enables you to define associations between data objects.



You can define different cardinalities as well as an association mapping between the data objects attributes of the source and the target of the association. 



This concept can then be used within the rules to navigate between associations to fetch the information you aim to evaluate.

After the definition of the data objects the next step is to define the function that then acts as an API for invoking your rules. In the SAP CP Business Rules this is the Rules Service:



The definition of a rule service is basically the same as when creating a BRFplus function. Be aware that there are no different operation modes available which basically means you use event mode in the SAP CP Business Rules (which is a restriction that also makes sense in BRFplus).

You define the name, the description and the context. The only thing that “irritated” me at the very first glance is that you have one section for the context (“Where do I put my result data object?”) The semantic meaning of the context (input vs. result) is defined inline as you can see in the screenshot.

As mentioned before you also must specify a target runtime and target runtime variant.

Let’s conclude this section with another table of comparisons:





























“BRFplus-ish” 



“SAP CP Business Rule-ish” 


Function Rule Service
Signature (Context + Result Data Object) Execution Context (with Usages)
Data Object Data Object
Component Name (of a structure) Attribute
Element Type Business Data Type



The Central Part - Rules


Now we can move forward to the core – let us define some rules. In BRFplus the rules have been represented by textual rules (if … then ... else). In those textual rules, you, in general, made use of expressions like formulas or decision tables.

The SAP CP Business Rules also make use of the term “Rule”. Comparing this rule with BRFplus one would end up with the conclusion that a SAP CP Rule is a combination of a BRFplus rule and a BRFplus expression where the concrete expression is defined by the rule types. At the time of writing this blog, the only available rule type in SAP CP is the decision table.



The configuration of the Decision Table Rule contains the options one would expect. As in the case of BRFplus you have a hit policy that defines at which point the evaluation of the table ends. This corresponds to the table settings of a BRFplus decision table “Return all matches found”.



According to the documentation this setting is specific to the decision table rule (However, you get the same setting again when navigating to the table settings, so I think something must be cleared up here in the UI.)

As expected you can also add the result object for the rule that can be any data object that you defined before:



Next, we define the columns of the decision table. In BRFplus you could either enter a data object from the context or an expression for the condition column and a data object (or an action, but I do not like the concept of actions in BRFplus, so let’s forget about that) as result column. The decision table in the Business rule service behaves the same, but the data entry is a bit unusual for a BRFplus user. You define the settings via the corresponding symbol: 



And then this is what you see as configuration dialog: 

 

The first thing that came to my mind: “What is a valid expression for a column?” I would have hoped for a drop-down, but it is just a text box … at the first glanceThere is support for your data entry and it is type-ahead. When you navigate to the field and hit the backspace you get all options of valid expression in the format of the “Rule Expression Language”. Here you can also see how the associations come into play: 



After defining the columns of your decision table, you can enter the data into the cells via direct inputBe aware that you must put quotes around strings, otherwise you get an error message … just saying. Finally, you might end up with something like this that looks somewhat familiar: 



That’s it for rules, so let’s put the vocabulary together:





























BRFplus-ish” 



“SAP CP Business Rule-ish” 


Rule + Expression Rule + Rule Type
Decision Table Rule of Type Decision Table
Configuration Option: “Return all matches found” Hit Policy
Condition Column Column of Decision Table
Result Column Result/Result Data Object



The Glue in between – The Rulesets


Up to now we have the rule service as API to our shiny business rule world and the rules containing the business logic, but no connection in between. The same concept as in BRFplus applies for the SAP CP Business Rules i. e. the glue that brings the rules service and the rules together is the Rule Set. You have the following degrees of freedom in SAP CP: you can assign a rule to several rule sets and assign multiple rule sets to a rule services assumed that they are in the same project. This is the same as in  BRFplus

The data input on that level is self-explanatory and supported by drop-down in the fields.



I assume that the rules are evaluated in accordance to their sequence as in BRFplus.

A hint for you when using this for the first time: when adding multiple rules I would propose to add the necessary empty rows first and then assign the rules in the desired sequence as you have no option to add a rule before or after a specific line (the same patter for adding rows as for the decision table would be great here).

That did not hurt too much right? So here is the short comparison table for this section:













“BRFplus-ish” 



“SAP CP Business Rule-ish”


Rule Set Rule Set



Bring the Rules to Life


Now we are nearly done. We are at a point where we want to call the rules. As BRFplus objects lived in the same system as the call of the function implemented in ABAP the story was simple. Take the code snippet from BRFplus and implement the call of the function in your ABAP system. Execute the piece of code and you will get the results without further ado.

The story is different for SAP CP Business Rules. They are more comparable to the SAP Decision Service Management i. e. you must deploy your rule service into your target runtime/runtime variant to make it callable as shown in the following screenshot:



Unfortunately, there is no status or info stating if the service was deployed or not. There is also no log at least none that can be accessed from the Rule Service tab.  So there is a quite ab it of room for improvement here.

Finally, this leads to the following comparison:













“DSM-ish” 



“SAP CP Business Rule-ish”


Deployment of a Service Deployment of a Rule Service



The Moment of Truth – The API Call


We have defined our rule service, we have (hopefully) successfully deployed – now the moment of truth has come, and we want to call the rule service. The question is: How ?

BRFplus and SAP Decision Service Management offered functionalities like simulating your function or creating code snippets that represented the boilerplate code for the function call.

The test/call of your rules service in SAP CP is a bit less comfortable than what you have been used to in BRFplus. First, you need two ingredients to be able to address your API:

  • URL of the Business Rule Service Runtime available in the destinations of your SAP Cloud Platform cockpit


  • The name of your project and your rule service 


With this information, you can call your rules service by using a tool like postman (https://www.getpostman.com/).

For the sake of completeness, I will shortly show how to perform such a call with Postman as this is unusual ground for a typical BRFplus developer. The screenshots are taken from an example that is based on the scenario described in the blog post https://blogs.sap.com/2017/08/01/implementing-a-user-self-registration-scenario-using-workflow-and-b....

Step 1: Get the XSRF token via a GET request on the REST endpoint of the SAP CP Business Rules. The URL is constructed as follows:
https://bpmrulesruntimebpm-<userid>trial.hanatrial.ondemand.com/rules-service/v1/rules/xsrf-token

You must provide two fields in the header of the request (you can achieve the base64 encoding via online tools)
















Key  Value 
Authorization Basic <Base64 encoded value of username:password>
X-CSRF-Token Fetch




The response gives you the X-CSRF token in the header of the response: 



Step 2: Make the call of your rule service. This is achieved via a POST call. The URL is constructed as:
https://bpmrulesruntimebpm-<userID>trial.hanatrial.ondemand.com/rules-service/rest/v1/rule-services/...

You must provide two field in the header of the request
















Key  Value
X-CSRF-Token Value of the token you fetched before
Content-Type application/json


 



The body of the request contains the input data as a JSON document. The structure of the document represents the entity type (__type___) and the values of the fields of the entity as name-value pairs:
[{ 

"__type__": "<name of the entity you want to pass>",

"<name of the field of the entity>":"<value of the field of the entity>"

}]



This request will return the result of the rule evaluation as a JSON document. The body of the response has the same structure as the request i. e. entities and the corresponding fields of the entity as name-value pairs. 



Congrats: You have now made one trip through the new world of the SAP CP Business Rules and are able to compare the BRFplus concepts with the ones of the SAP CP Business Rules.

A small addition: If you integrate the business rule call into the workflow service the described two-step procedure can be handled in one call. For details see the blog post https://blogs.sap.com/2017/08/01/implementing-a-user-self-registration-scenario-using-workflow-and-b...

Programmatic Approach


Another aspect that made BRFplus extremely powerful was its design time API and the consequent option to create and modify you BRFplus objects programmatically via plain ABAP code. The same is possible for the SAP CP Business rules. All actions available in the UI are also available as APIs. You find a description of the APIs here: https://help.sap.com/doc/3eeb1d27382c45d5b88510bed5639397/Cloud/en-US/rule-repo.html#sw-default-prod...

Some last Remarks


First, I hope you have now an idea of the quite similar concepts that lie underneath BRFplus and the SAP CP Business Rules. This way the move towards using the SAP CP Business Rules as a BRFplus user shouldn't be too difficult. Due to this similarity designing rules in SAP CP Business Rules should be no big deal. Managing expectations and as mentioned in the beginning, you should not (yet) compare BRFplus and SAP CP Business Rules from a functional perspective. SAP CP Business Rules have no chance when it comes to this aspect as they are too new. The current state of the SAP CP Business Rules allows you to define some “simple” rules based on decision tables (that already should cover a lot of scenarios) that can be easily digested in the SAP CP Workflow and in the Java runtime. If you have such scenarios use the service – as with BRFplus and ABAP: please do not try to model rules in plain Java resulting an IF-hell.

As the SAP CP Business Rules are a quite young member of the SAP CP service offering a lot of open questions and room for improvement remain:

  • First and foremost, the documentation (https://help.sap.com/viewer/9d7cfeaba766433eaea8a29fdb8a688c/Cloud/en-US/86771c47c8ca4c7d855595bc226...) is quite slim, so you get some answers for basic questions but if you dig deeper you will fail to find answers.

  • The usability of the design time is also something one could furbish up. I already made some comments on that in the blog to give another point you will certainly come across: error messages – the ones I have seen to not really help you to resolve the problem, so this area is also something that is hopefully on the to-do list for SAP CP Business Rules.


Besides these initial quirks that one would expect and also have been in BRFplus (usability in the day of 7.02 was not optimal if somebody still remembers), there are a lot of conceptual questions that need to be answered. Here are some examples:

  • What about versioning of the rules and switching between versions?

  • What about monitoring and logging of the rules?

  • How to integrate the rules into a “build chain”?



  • How to document the rule service (e. g. Swagger)?


Let’s see if the upcoming TechEd Barcelona might shed some light on these questions.

Some very last Remarks


Perhaps you have asked yourself the following questions:

  1. Hmm, does it still make sense to start with BRFplus?



  1. If I model rules with BRFplus do I have to take something into account in order to allow a smooth transition/migration towards SAP CP Business Rules?


Here are my answers:

  1. Yes, it definitely makes sense to use BRFplus when you work in the ABAP stack. Just do it. There is no excuse not to make use of this tool when you deal with business rules in the Business Suite or S/4HANA.

  2. Yes, there are points you have to consider to make a later transition smooth. Stick to the information delivered with note 2509401 (S-User required) and you will be on the safe side.

6 Comments
Labels in this area