arti.gopalan

11 Posts

As promised in the previous blog (Introducing SAP NetWeaver 7.2 Composition Environment Business Rules Management), we have added more articles and screencams for BRM 7.2 into SDN.

Now, you can learn how to use the rules flow feature of this new version of BRM, learn to test and validate the rules created. Create an end-to-end scenario. See how to easily generate a rules web service, by making use of a wizard now provided with BRM.

Also provided are articles to help in integrating BRM with BPM, and about how change management of rules can be done using SAP NetWeaver 7.2 Composition Environment 7.2

Here are the links –

Articles

Modeling rules using SAP NetWeaver 7.2 Composition Environment BRM

Change management of rules using SAP NetWeaver BRM 7.2

Integrating BRM with BPM in SAP NW CE 7.2 BRM  

 

Screencams -

How to Test Rules in the Rules Composer

How to Create a Rule Flow in the Rules Composer (Business Rules Management 7.2)

Working with the Rules Manager

TechEd 2009 Phoenix kicks-off today. Hope everybody attending it has an exciting time.

To learn more about BRM, the new features added to this component of SAP NetWeaver 7.2 Composition Environment, don’t miss the lecture session - Overview of Business Rules Management in SAP NetWeaver Composition Environment, by Michael Hill - http://www.sapteched.com/usa/edu_sessions/session.htm?id=209; and the hands-on session - Accelerating SAP NetWeaver BPM with BRM - http://www.sapteched.com/usa/edu_sessions/session.htm?id=240, by Jolene Jonas; Claudia Pacheco; Suresh Ranganathan; Abdul Razack

Also, available is a BPM pod. Do visit it and get to know the new features introduced in BPM/BRM components here.

To help in introducing you to BRM, we have also uploaded some articles which will be of use at the beginner’s level -

·         A Sneak Preview into BRM 7.2 [link]

·         The screencam showcasing the enhancements available in BRM (which has been divided into two parts) [Part 1, Part 2]

 

You can expect a lot more of articles, demos and screencams in the following days.. Watch this space for more!

Now you can import or export your excel sheet to a Decision Table!

 

In most case scenarios like in -

a. making a region based calculation of rate;

b. calculation of score based on certain factors like experience, qualification, etc.,

c. setting of discount based on user capacity and trustworthiness

 

where sets of value matching needs to be maintained in a form of a table, an excel sheet is an even more accessible option for business users when compared to a maintaining a decision table in NWDS BRM component.

 

With this new plug-in provided - link - you will be able to group the required rules i.e., create the required value matching peacefully by making use of a excel sheet without having to undergo the hassle of having to install the NetWeaver Development Studio for this purpose exclusively. This excel sheet once created or modified can then be imported into your rules DC as and when required.

 

For doing this, you need to note that -

  1. The header structure of the tables should be the same in both the excel sheet as well as the decision table.
  2. If the decision table contains Other Conditions values or complex expressions in action values, it can be exported, but cannot be imported due to limitations in parsing the mathematical expressions.
  3. The excel document which can be imported needs to be MS Office 2007 compatible. 

A best practice method described in this document is to create the decision table with the required header structure and export this into a .xlsx file. It is recommended to make the required modifications to this excel sheet and import it back.

 

To help you in installing and using this plug-in a clear step-by-step document has been provided in the SAP NetWeaver Business Rules Management Resources Center.

Provided at this link is a document to help you in creating a Web Dynpro application which involves decision making.

 

This article makes use of a simple example, where in the tax on a personal loan needs to be calculated, based on a set of inputted details. For the purpose of handling these decision-based calculations we make use of the NetWeaver BRM component 7.1 EhP1.

 

After following this end-to-end article, you will be able to –

  1. Model rules using the BRM component.
  2. Create a simple WDPro application and implement lines of code which will invoke the modeled rules.
 

Other links you may find useful are –

Writing Rules on XML Schema in Rules Composer

Writing Rules on Java Classes in Rules Composer

Invoking Rules Web Service from Web Dynpro CE 7.1

This is a continuation of my previous blog on how to start a BPM process in CE7.1. In that article I had mentioned 3 different ways of starting the process – http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/80ace13d-5182-2b10-a584-bfa2042061e6

  1. Using the process web service in a dynamic web application

And, two simpler ways of starting the process (techniques which are mainly meant to help in doing a quick test of the deployed BPM process).

  1. Starting it directly from the wsnavigator portal
  2. Starting it directly from the Process Repository in the nwa portal.

I have created a silent demonstration to help in starting a BPM7.1 process using a very simple Visual Composer model. For this purpose, I have the video demo available at this link - http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a010d7a2-abee-2b10-3eb0-a5dc2af210b0

The presentation related to this demo can be found here - http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10f936a0-a5ee-2b10-3e8e-9dbe463aaad4

This silent demo is basically meant as a help to a beginner in creating a simple UI to start the process.

This blog gives you a short demo of how to invoke Rules Web Service from WebDynpro Application.

For this purpose, I have created a silent demonstration available at - http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a0ace84f-40f0-2b10-09b9-e31e90cb920b

In this demo, I performed the following set of steps –

1.       Created the WebService for the ruleset by making use of the WSGenerator Tool(available at - )

2.       Created Adaptive Web Service model by using the wsdl generated from the previous step.

3.       Created the Component and applied the service controller template to it.

4.       Created the required forms and tables in the view and included lines of code to call the execute invoke rule method created at the service controller level.

A step by step explanation of this is available in the presentation available here - http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e04e00db-3df0-2b10-9b92-ff8f00bc2df2

This blog is a part of the series regarding the features in BRM.  Other blog in the series is “Understanding the feature – Priority”. In this blog I wish to answer the general question which comes to one’s mind while creating conditions in a Decision Table – What are the different comparators which can be used to create a meaningful condition?

I have tabularized the whole collection of comparators supported  and a brief write-up about how it can be used –

Comparator

How to use

InCan be used in condition values in the following format:  In a,b,c

A condition gets satisfied if its LValue equals any one of the comma separated values which follow “In” comparator.

Example -

In 200,300,300 (for numeric values such as for int, float, double, etc.,)

 In Good, Bad, Moderate (for enum type where only the existing enum values can be assigned to the condition)

‘In’ comparator can be used with all except Boolean data type. A condition gets satisfied if the input value equals any one of the comma separated values which follow “In” comparator.

Not In 

Can be used in condition values in the following format : Not In a,b,c

“Not In” comparator can be used both in strings and numeric condition values.

“Not In” comparator can be used with all except Boolean data type.

Between 

Can be used in condition values in the following format: Between 5 and 10.

It is inclusive of boundary values. “Between” comparator can be used for numeric value but not for string condition value.

Like 

Can be used in condition values in the following formats:

Like a

Like *

Like ab*

Like ab*c*

Like ab*c*d*ee

“Like” comparator looks for a pattern-match between LValue of the condition and the value that follows it.

If Lvalue of a condition is “abcdef”, then following are the expected results:

Like * returns true

Like ab* returns true

 Like ab*e returns false

Like ab*d* returns true

This comparator can only be used with string condition value but not with numeric condition value.

Not Like 

Can be used in condition values in the following formats:

Not Like a

Not Like *

Not Like ab*

Not Like ab*c*

Not Like ab*c*d*ee

“Not Like” operator looks for a pattern-mismatch between LValue of the condition and the value that follows it.

If LValue of a condition is “abcdef”, then following are the expected results:

Not Like * returns false

Not Like ab* returns false

Not Like ab*e returns true

 Not Like ab*d* returns false

This operator can only be used with string condition value but not with numeric condition value.

>, >= , <, <= 

Can be used in condition values in the following format:

> 10

> = 10

 < 20

 < = 20

The Logical operator ‘and’ can be used in conjunction as follows: >10 and <20 (OR) >=10 and <=20 (Same as Between) These comparators can be used with all except Boolean data type. We can use “or” logical operator also. We can give complex ranges such as: ((>=10 and <=20) OR (>=40 and <=50))

= 

Can be used in condition values in the following format: = A

Where,  A can be a string or a numerical or a Boolean value.

 = 20

= Joe

= true

For Boolean this is the only comparator that is supported.

!= 

Can be used in condition values in the following format:

!=20 (numeric condition value)

 !=Joe (String condition value)

This comparator can be used for String and numeric types.

I have published a very small article to help one in starting a process (modeled by using the BPM tool in NWDS) once it has been deployed into the Application Server.

Here is the link to the article -http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/80ace13d-5182-2b10-a584-bfa2042061e6

In the article, I have mentioned about how to start the process from an Application. Also given is a brief set of steps to start the process from the wsnavigator and from the nwa portal directly.

This blog is about the feature - priority - provided in the BRM and about how it can be used effectively.

Before we continue on to understanding priorities, let us take a brief glance at rules engine - It is the rules engine (runtime engine) which is responsible for implementing / enforcing / executing the business rules. The engine makes use of the RETE Algorithm, one of the most efficient pattern matching algorithms available. (Please refer my prev. blogs to understand how rules (using schemas) can be invoked - Invoking Business Rules - Part 1 and Invoking Business Rules – Part 2)

In BRM one is allowed to control the order of evaluation of rules by making use of features/properties like priorities and mutual exclusions. Here, a priority is nothing but a way to help you in guiding the order of firing of rules.

Another way of defining the same is - Priority is an attribute of a rule that governs the order in which rules are added to the firing queue. The first rule in the Firing Queue is the one with the highest priority. [Firing Queue is the term which is used to indicate a buffer which maintains the rules whose conditions have been satisfied.]

The value, which can be assigned to a rule, can be any integer value. In NWDS rules perspective, you can set the priority in two ways. Either,

  • A set of predefined numbers as the priority have been provided. You can set any one of these predefined numbers as your priority
  • You can explicitly set the priority to any integer value as required.

Priorities are categorized into five standard levels:

LevelInteger Value

Minimum

0

Low

25,000

Medium

50,000

High

75,000

Maximum

1,00,000

  
 

Let us consider an example to understand this further -  a rules project having three rules

Rule A has 25000 as its priority

Rule B has 50000 as its priority

Rule C has 0 as its priority

The rule with the highest priority (here, Rule B) is invoked first and so on.. i.e, the order in which rules are invoked will be first Rule B; then Rule A; and finally Rule C.

 

Let us consider a very simple case scenario –  An employee’s bonus depends on  the band in which he is in and the department in which he is in.

  1. If employee is in Band A – bonus given will be 10% of his base salary.
  2. If the department is engineering then, the bonus is increased by 2%

In this scenario we can observe that for the final bonus to be calculated - first the initial bonus has to be set depending on the band of the employee. And then based on which department the employee is in, the bonus is increased by a certain percentage.

As the order of the rules executed needs to be ensured, we make use of the feature priority – assigning the first rule with a priority higher than the one set for the second rule.

This blog is a continuation to the Invoking Business Rules - Part 1 - "Invoking Business Rules - Part 1"- on how business rules can be evaluated.

The scenario considered is the same as before – i.e., you have already created a rules project.  And that the rules project created here makes use of a XSD as its business object.

In the previous blog I have already mentioned one way of invoking rules i.e., look-up the rule engine EJB in your application. The second way in which rules can be used is by exposing the ruleset as a webservice and then using this webservice when required in the application.

To help you in generating a webservice for a ruleset easily, a web service generator tool has been provided in the SAP NetWeaver Business Rules Management Resources Center of the SDN. The link to this tool is – http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10c6b0c3-0c50-2b10-97ac-e98ad72aaf8f. The tool is available in as a zip.

[One needs to note that this is an unsupported tool and is not a product feature as of yet. This is provided as an aid to developers to quickly create an XML service for Rules. This is equivalent to creating a Web service using a code based approach.]

The Rules Tutorial Center also has link to an article which will help you in generating the web service manually i.e., by using a code based approach. (http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c082390a-035f-2b10-dc9d-befec4aff998)

Once this tool is downloaded from the given location, you need to make sure that the tool is configured correctly.  The tool has to be configured in the run.bat file available in the zip. Here, you need to mention information regarding  -

  1. JAVA_HOME (we need to set the path to the jdk to this variable)

  2.  JDI_WORKSPACE(we need to set the path to the workspace to this variable)

Once these changes have been made, there are few prerequisites specified which needs to be satisfied. The workspace -

  • needs to have at least one Web Module or J2EE DC (any dummy DC will also do)

  • atleast one DC in the workspace needs to reference BRMS FAÇADE

  • atleast one DC in the workspace needs to reference ENGFACADE/tc/bl/logging/api

  • atleast one DC in the workspace needs to reference JEE Engine Façade 

 

The next step is to use this tool to generate the web service. Mr. Velu has mentioned the steps to be performed to do this, very clearly in one of his blogs. The link to this in-detail blog, written by Mr.Velu is - Generate and Test your SAP Netweaver BRM Rules Web Service – Part 1

This blog is going to be about how business rules can be evaluated. The scenario considered is that, you have already created a rules project.  The rules project could either be using XSD or a  java resource as its business object on which the rules are defined. Let us consider in this blog the case that the rules project created here makes use of a XSD as the business object.

Rules can be invoked by either –

I.   Using the code to Look-up the rule engine EJB in your application.

(or)

2.  Creating a web service containing a method to invoke the rule engine. 

 

We are going to understand how business rules, created in the rules composer perspective of the NWDS, can be invoked inside an application. Steps to do this -

    The rules engine which invokes/evaluates/ executes business rules is available as an EJB. We need to look up this EJB and create an instance of the engine for use, in our application. To do this we make use of the following lines of code –

    String jndiName = "com.sap.brms.RuleEngine";

    InitialContext context = new InitialContext();

    Object obj = context.lookup(jndiName);

    RuleEngineHome engineObj = (RuleEngineHome)  PortableRemoteObject.narrow(obj, RuleEngineHome.class);

      

    1. Passing the required information to the rules engine.

    To invoke rules we need to pass information such as – the project name; the ruleset name and the business objects which are to be processed – to the rules engine. To do this we make use of the method – invoke Ruleset.

    The method syntax is  -

    RulesetContext  invokeRuleset(com.sap.brms.qrules.engine.RulesetContext arg0)

    List  invokeRuleset(java.lang.String arg0, java.lang.String arg1, java.util.List arg2)

     

    Here, arg0 is the Project Name ; arg1 is the Ruleset Name; and the arg2 is the business objects list. i.e,  we need to pass the business object, in this case as a XML as an object in a List to the rules engine.

    To do this we make use of the following lines of code –

    An xml string is created by making use of the inputted information from the web form, by the user. This xml string is then passed to the processPayload method.If more than one xml needs to be passed to the rules engine a payload saperator - # - needs to be used between each set of xml string.  The  processPayload method then creates an xml object for each set of xml string passed to it and adds the objects to a List. This list is then returned.
      1. This  returned list is then passed to the rule engine for invocation.
    The returned list is then passed to the processReturnPayload method which creates a xml string from each object returned. This xml string can then be parsed to get the required/processed element value.

               

       

      List xmlObjList = processPayload(inputXML);

      List opXMLObjects = ruleEngine.invokeRuleset(projectName, rsName,xmlObjList);

      output = processReturnPayload(opXMLObjects);

       


      private static List processPayload(String inputXML)

            throws Exception

        {

            List inputList = new ArrayList();

            StringReader strReader = new StringReader(inputXML);

            BufferedReader in = new BufferedReader(strReader);

            String line = null;

            StringBuffer sb = new StringBuffer();

            XMLObject xmlObj = null;

            while((line = in.readLine()) != null)

            {

                String trimmedLine = line.trim();

                if(trimmedLine.startsWith(payloadSeparator))

                {

                    xmlObj = XMLObjectFactory.createXMLObject(sb.toString());

                    inputList.add(xmlObj);

                    sb.setLength(0);

                    ret_payloadSeparator = trimmedLine;

                } else

                {

                    sb.append(line);

                }

            }

            if(sb.length() != 0)

            {

                xmlObj = XMLObjectFactory.createXMLObject(sb.toString());

                inputList.add(xmlObj);

            }

            return inputList;

      }

       

        private static String processReturnPayload(List opXMLObjects)

        {

            StringBuffer op = new StringBuffer();

            int size = opXMLObjects.size();

            for(int i = 0; i < size; i++)

            {

                XMLObject obj = (XMLObject)opXMLObjects.get(i);

                String opS = obj.getXmlString();

                op.append(opS);

                if(size != 1 && i != size - 1)

                {

                    op.append(ret_payloadSeparator);

                    op.append(System.getProperty("line.separator"));

                }

            }       

            return op.toString();

        }