Skip to Content

Although this document is mainly based on NW BRM but in Process Orchestration scenarios, where NW BRM is involved, this can be helpful from modeling aspects. The description of the steps mentioned here are already there in SAP wiki for NW BRM. Here I have just tried to consolidate them into a single document format with detailed screenshots and example. Moreover, it has also been shown how a ruleset can be exposed as a web service and executed using WSNavigator. Please note that various customization can be made in these kind of scenarios and the rules that are considered are nothing but simple examples. Hope it will help you all.

Applies to:

SAP NetWeaver Business Rules Management

Software Requirements

SAP NetWeaver Developer Studio version should include the RulesComposer perspective

Key Points Discussed:

  • Overview on NetWeaver BRM
  • Creating and Testing Flow rule set in NWDS
  • Executing the rules exposed as a Web service from WSNavigator

Table of Contents

Introduction:

Business Use Case.

Steps Involved:

1.     Creating the Rules Composer DC..

2.     Creating the XML Schema.

3.     Creating the Definition.

4.     Creating the Enumeration Type.

5.     Creating the Flow Ruleset

6.     Creating the Decision Tables.

7.     Creating the Rule Scripts.

8.     Creating the Rule Flow..

9.     Creating and Running the Test Case.

10.       Exposing the Flow Ruleset as a Web Service.

11.       Deploying the Rules.

12.       Executing the Rules.

Bibliography:

Introduction:

SAP NetWeaver enables organizations to manage business rules for decision automation. Business users participate in and control rule definition and change, while business process experts’ model, validate, deploy, update, and archive business rules through their lifecycle. As such, IT organizations can work with business users to manage business rules that drive process flow and execution.

Business rules describe the operation, definition, and constraints that apply to an organization in achieving its goals.

SAP NetWeaver Business Rules Management (SAP NetWeaver BRM) helps us to model critical business rules and automate rule-based decisions in composite business processes and composite applications. The rules composer is the design time of BRM where we can create rules.

Rules Composer is integrated into SAP NetWeaver Developer Studio as a separate perspective and provides rich and user-friendly formats of rules representation enabling users to model complex business rules. It contains extensive business rules modeling capabilities for business analyst and rules implementation functionality for business rules developers.

Rules can be created in two ways:

Rules composer as a separate perspective in SAP NetWeaver CE allows us to model rules. These rules can be used in any other business application or a business process.

Process composer as a perspective allows user to model rules in a business process context.

Business Use Case

The rule based application modeled in this document, satisfies the following business use case:

An applicant/employee applies for his/her promotion by filling out a request form, including information such as Age, Experience, Employee Type, Skills and based on his details, the primary decision is taken whether he/she is eligible for promotion or not.

When the promotion request is received, based on the information provided by the applicant, based on the type of the employee, the decision is taken. For Regular employees, a standard Score is generated based on some criteria. For Contractors, a different criteria based on the experience is encountered and based on that the decision is taken.

The workflow is as shown below:

/wp-content/uploads/2013/11/image001_330555.png

Steps Involved:

The entire model is designed based on some basic steps which need to be followed while designing any rule-set in NW BRM.

Note: Here the design is created using Process Composer Perspective in NWDS

1.               Creating the Rules Composer DC

2.               Creating the XML Schema

3.               Creating the Definition

4.               Creating the Enumeration Type

5.               Creating the Flow Ruleset

6.               Creating the Decision Tables

7.               Creating the Rule Scripts

8.               Creating the Rule Flow

9.               Creating and Running the Test Case

10.           Exposing the Flow Ruleset as a Web Service

11.           Deploying the Rules

12.           Executing the Rules

1.   Creating the Rules Composer DC

Procedure

·         In the SAP NetWeaver Developer Studio, choose File -> New -> Project.

·         In the wizard that appears, expand the Rules Composer node and choose Rules Composer Development Component. Choose Next

·         In the screen that appears, choose the software component where you want to create the DC.

·         For example the software component could be MyComponents [demo.sap.com] under the Local Development node. Choose Next.

·         In the screen that appears, enter dc_test in the Name field and choose Finish.

/wp-content/uploads/2013/11/image006_330578.png

/wp-content/uploads/2013/11/image008_330579.png

2.   Creating the XML Schema

Procedure

·         In the Project Explorer view, expand the src node and in the context menu of the wsdl node, choose New -> Other.

·         In the wizard that appears, expand the XML node and choose XML Schema. Choose Next.

·         In the screen that appears, enter Promotion.xsd in the File Name field. Choose Finish.

·         In the Project Explorer view, you should see the Promotion.xsd when you expand the wsdl node.

/wp-content/uploads/2013/11/image010_330580.png

The Schema is designed in the following way as shown in below screenshots.

/wp-content/uploads/2013/11/image012_330581.png   /wp-content/uploads/2013/11/image014_330773.png

/wp-content/uploads/2013/11/image016_330583.png

Final Structure of the Schema:

/wp-content/uploads/2013/11/image018_330584.png

Adding the XSD Elements to the Rules Composer DC

·         In the Project Explorer view, expand the Rules Modeling node and double-click the Project Resources node.

·         In the Project Resources editor that appears, choose the Aliases tab.

·         In the Aliases editor that appears, choose the Add button and in the menu that appears, choose the XSD Element.

·         In the dialog box that appears, expand the http://www.example.org/Promotion node and choose Promotion

/wp-content/uploads/2013/11/image020_330585.png

/wp-content/uploads/2013/11/image022_330586.png

3.   Creating the Definition

You can also capture business terms in the form of Definitions. You create a Common Definition called Score which can be used across the rules composer DC.

Procedure

/wp-content/uploads/2013/11/image024_330590.png

·         In the Project Explorer view, expand the dc_test node, the Rules Modeling node and double-click the Project Resources node.

·         In the Project Resources editor, choose the Common Definitions tab

·         In the Common Definition editor, in the Variable Definitions section, choose the Add icon and in the drop down that appears, choose double.

·         Choose the default Definition name: double1 and in the text box that appears, enter Score and press Enter.

·         Leave the RHS value: 0 as it is.

·         Save the changes.

4.         Creating the Enumeration Type

The Promotion type has only two values: Regular and Contractor. Create an enumeration type called PromotionType and capture the corresponding values. This way we do not have to enter the Promotion type in the rules.

Procedure

·         In the Project Explorer view, expand the dc_test node, the Rules Modeling node and double-click the Project Resources node.

·         In the Project Resources editor, choose the Enumeration Types tab.

·         In the Enumeration Type editor that appears, choose the Add button.

·         In the dialog box that appears, enter PromotionType in the Name: field.

·         Locate Java Type and choose java.lang.string in the drop down menu.

·         In the space provided, enter the following values:

o        Regular = Regular

o        Contractor = Contractor

·         Choose OK.

·         Save the changes.

/wp-content/uploads/2013/11/image026_330591.png

5.   Creating the Flow Ruleset

Procedure

·         In the Project Explorer view, expand the dc_test node and in the context menu of the Rules Modeling node, choose New Flow Ruleset.

·         In the dialog box that appears, enter Check_Promotion_Eligibility in the field.

·         Choose OK.

Result

In the Project Explorer view, you should see the Check_Promotion_Eligibility node when you expand the Rules Modeling node.

/wp-content/uploads/2013/11/image028_330592.png

/wp-content/uploads/2013/11/image030_330594.png

6.   Creating the Decision Tables

Procedure

Creating the RegularPromotionEligibility Table

·         In the Project Explorer view, expand the dc_test node and the Rules Modeling node and in the context menu of the Check_Promotion_Eligibility node, choose New Decision Table.

·         In the decision table Creation Wizard that appears, enter RegularPromotionEligibility in the Decision Table Name field and choose Next.

·         On the Select the Conditions screen, double-click the following aliases in the Available Conditions section:

o        ApplicantPastPerformance

o        ApplicantExperience

o        ApplicantSkills

/wp-content/uploads/2013/11/image034_330596.png

·         Select the Table has Horizontal Condition checkbox. Choose Next.

·         On the Select the Actions screen, double-click Score in the Available Actions section.

·         The alias appears in the Selected Actions section.

·         Choose Finish.

·         Save the changes.

·         In the Project Explorer view, you should see the RegularPromotionEligibility node when you expand the Decision Tables folder.

/wp-content/uploads/2013/11/image036_330597.png     /wp-content/uploads/2013/11/image038_330598.png

·         If the decision table editor does not open, double-click the RegularPromotionEligibility node to open the decision table editor.

/wp-content/uploads/2013/11/image040_330602.png

7.   Creating the Rule Scripts

Procedure

·         In the Project Explorer view, expand the dc_test node and in the context menu of the Check_Promotion_Eligibility node, choose New Rule Script.

·         In the dialog box that appears, enter Check Regular Applicant Promotion Eligibility in the field and choose OK.

·         Create one more rule script as follows: Check Contractor Applicant Promotion Eligibility

·         In the Project Explorer view, when you expand the Check_Promotion_Eligibility node and the Rule Scripts folder, you should see all the relevant rule    script nodes.

·         Save the changes.

/wp-content/uploads/2013/11/image042_330603.png

Editing the Check Regular Applicant Promotion Eligibility Rule Script

·         Double-click the Check Regular Applicant Promotion Eligibility node.

·         In the rule script editor that appears in the Actions section, choose the Add icon and in the drop down menu choose If-else if

·         The If-else if block appears.

·         Edit the default condition: Operation.isSuccessful Equals true as follows:

o        Choose the LHS value: Operation.isSuccessful and in the drop down menu expand the Promotion node and choose ApplicantAge.

o    Choose the comparator: Equals

o  Choose the RHS value: 0 and enter 25 in the inline text box.

o  Choose the Add icon and add another condition and edit as follows:

·         Choose the LHS value: Operation.isSuccessful and in the drop down menu expand the Definitions node and choose Score.

·         Choose the comparator: Equals and in the drop down menu choose Greater Than Equals.

·         Choose the RHS value: 0 and in the inline text box enter 8.

·         Under the Then section, choose the Add icon and in the drop down menu that appears, expand the Execute node, the Promotion node and choose Set PromotionEligibility = {String}.

·         Choose {String} and in the inline text box enter Is Eligible for Promotion.

·         Add another condition in the same way inside the else part with ApplicantAge greater than 29 and Score greater than equals 7.

·         Choose <Add Else> and in the drop down menu expand the If Else node,

·         In the If block is satisfied, Set PromotionEligibility = {String} and Choose {String} and in the inline text box enter Is Eligible for Promotion.

·         In the Else part, the Promotion node and choose Set PromotionEligibility = {String}

·         Choose {String} and in the inline text box enter Is Not Eligible for Promotion.

/wp-content/uploads/2013/11/image044_330604.png

Editing the Check Contractor Applicant Promotion Eligibility Rule Script

·         Double-click the Check Contractor Applicant Eligibility node.

·         In the rule script editor that appears in the Actions section, choose the Add icon and in the drop down menu choose If-else if

·         The If-else if block appears.

·         Edit the default condition: Operation.isSuccessful Equals true as follows:

o        Choose the LHS value: Operation.isSuccessful and in the drop down menu expand the Promotion node and choose ApplicantAge.

o        Leave the comparator: Equals as it is

o        Choose the RHS value: 0 and enter 25 in the inline text box.

Choose the Add icon and add another condition and edit as follows:

·         Choose the LHS value: Operation.isSuccessful and in the drop down menu expand the Promotion node and choose ApplicantExperience.

·         Choose the comparator: Equals and in the drop down menu choose Greater Than Equals.

·         Choose the RHS value: 0 and in the inline text box enter 4 YEARS

·         Under the Then section, choose the Add icon and in the drop down menu that appears, expand the Execute node, the Promotion node and choose Set PromotionEligibility = {String}.

·         Choose {String} and in the inline text box enter Is Eligible for Promotion.

·         Add another condition in the same way inside the else part with ApplicantAge greater than 29 and Score greater than equals 7 YEARS

·         Choose <Add Else> and in the drop down menu expand the Execute node, the Promotion node and choose Set PromotionEligibility = {String}

·         Choose {String} and in the inline text box enter Is Not Eligible for Promotion.

/wp-content/uploads/2013/11/image046_330605.png

8.   Creating the Rule Flow

Procedure

·         In the Project Explorer view, expand the dc_test node, the Rules Modeling node, the Check_Promotion_Eligibility node, the Rule Flows folder and double-click the Main Flow node.

/wp-content/uploads/2013/11/image048_330606.png

·         In the Rule Flow editor that appears, you should see the Start and End points by default.

·         Delete the connector connecting the Start and End points.

Creating and Editing the Rule Flow Elements

·         In the Palette, choose the following flow elements and drag and drop them in the Rule Flow editor:

o        Exclusive Choice Gateway

o        1 Decision Tables

o        2 Rule Scripts

Editing the Decision Table Elements
/wp-content/uploads/2013/11/image050_330607.png

·         Choose the decision table element and in the Properties view, in the drop down menu, choose RegularPromotionEligibility Table.

·         Save the changes.

Editing the Rule Script Elements
/wp-content/uploads/2013/11/image052_330608.png

·         Choose a rule script and in the Properties view, in the drop down menu choose Check Regular Applicant Promotion Eligibility.

·         Choose the second rule script and in the Properties view, in the drop down menu choose Check Contractor Applicant Promotion Eligibility.

·         Save the changes.

Creating Connections
/wp-content/uploads/2013/11/image054_330609.png

·         Choose the exclusive choice gateway and in the menu that appears, choose the Create Connection icon and drag and drop the connection into the RegularPromotionEligibility element.

·         Create connections from the exclusive choice gateway to the Check Contractor Applicant Promotion Eligibility element

·         Create connection from RegularPromotionEligibility to Check Regular Applicant Promotion Eligibility

·         Create connections from Check Contractor Applicant Promotion Eligibility and Check Regular Applicant Promotion Eligibility to End point.

Editing the Exclusive Choice Gateway

1.               Choose the exclusive choice gateway and in the Properties view and choose the Conditions tab.

2.               In the table that appears, double-click the first cell in the Name column and enter Regular

3.               In the Condition column, double-click the first cell and edit the default rule condition:

·         Choose the LHS value and in the drop down menu, expand the Promotion node and choose ApplicantType.

·         Leave the comparator: Equals as it is.

·         Choose Default after the comparator and in the drop down menu expand the ApplicantType node and choose Regular.

·         Press Alt + Enter to close the editor.

·         Save the changes.

4.               In the table, double-click the second cell in the Name column and enter Contractor

5.               In the Condition column, double-click the second cell and edit the default rule condition:

·         Choose the LHS value and in the drop down menu expand the Promotion node and choose ApplicantType.

·         Leave the comparator: Equals as it is.

·         Leave the value:Contractor after the comparator as it is.

·         Press Alt + Enter to close the editor.

·         Save the changes.

The result must be as follows:

/wp-content/uploads/2013/11/image056_330610.png

The rule flow must be as shown below:

/wp-content/uploads/2013/11/image058_330611.png

/wp-content/uploads/2013/11/image060_330612.png

9.   Creating and Running the Test Case

Procedure

Create a Test Case

·         In the Project Explorer view, expand the dc_test node, the Rules Modeling node and in the context menu of the Test Cases node, choose New XML Test Case.

·         In the dialog box that appears, enter PromotionType TestCase in the field and choose OK.

·         We should see the PromotionType TestCase node when we expand the Test Cases node. The test case editor appears.

Setting the Target Ruleset

·         In the Test Case editor, choose the Setup tab and in the tab page that appears, locate Target Ruleset: and in the drop down menu choose Check_Promotion_Eligibility.

·         Save the changes.

Creating the XML Document

Now we create an XML document based on Promotion.xsd used to write the rules. The XML document contains the data for the test case.

·         In the Test Case editor, choose Create XML in the top right corner.

·         In the dialog box that appears, the Choose XSD radio button is selected by default. Choose src/wsdl/Promotion.xsd{http://www.example.org/Promotion}.

·         Choose OK.

/wp-content/uploads/2013/11/image063_330613.png

·         In the screen that appears, in the File name: field enter Promotion.xml.

·         Choose Next. In the screen that appears, accept default selections or change the selections according to your choice.

·         Choose Finish.

Adding the XML Document to the Test Case
/wp-content/uploads/2013/11/image065_330617.png

·         In the Test Case editor, in the XML Documents for Test Input section, choose the Add XML button

·         In the dialog box that appears, select the src/brmtests/Promotion checkbox and choose OK.

·         We should see src/brmsets/Promotion.xml listed in the XML Documents for Test Input table.

·         Save the changes

Creating the Data Source

The Data Source is a CSV file that contains the input data and expected output data for testing the correctness of the rules. We can also pass data through XML file directly, but in that case, we have to pass 1 record in a single XML file i.e we can validate only a single test case.

·         In the Test Case editor, choose Create Data Source in the top right corner.

·         In the dialog box that appears, enter Promotion.csv and choose Finish.

·         The data source opens in the editor window. We should see a blank window.

·         Enter data in the format as shown below:

·         Save the changes.

/wp-content/uploads/2013/11/image068_330618.png

Adding the Data Source as Test Data
/wp-content/uploads/2013/11/image070_330619.png

·         In the Test Case editor, in the Test Data section, choose the Set Data Source button.

·         In the dialog box that appears, choose Promotion.csv in the drop down menu and choose OK.

Mapping XPath to Constant Values or Header Names in the Data Source

When you run the test case, the values from the Data Source must be taken as input data and expected output data. So you need to map the XML elements you have used in your rules with the header names in the Data Source. When you map the output data you compare the expected output with the actual output using a comparator. This indicates if the test case has failed or passed.

·         In the Test Case editor, choose the Detailed Configuration tab.

·         In the tab page that appears, in the Input Mapping section, choose src/brmsets/Promotion.xml and choose the Add XPath button.

·         In the dialog box that appears press Ctrl and double-click the following elements:

o        tns:Promotion/tns:ApplicantAge

o        tns:Promotion/tns:ApplicantExperience

o        tns:Promotion/tns:ApplicantSkills

o        tns:Promotion/tns:ApplicantPastPerformance

o        tns:Promotion/tns:ApplicantType

·         Choose OK.

·         In the Input Mapping section, in the table, the Mapping Element column displays the XML elements that have been added.

·         Choose the corresponding cell to each element in the Mapping Element column, and in the drop down menu you should see all the header names as specified in Promotion.csv. Make sure the header name that has been chosen is the same as the XML element.

/wp-content/uploads/2013/11/image072_330620.png

/wp-content/uploads/2013/11/image074_330621.png

·         Repeat the step until all the XPaths are mapped with the header names.

·         In the Output Mapping section, choose src/brmsets/Promotion.xml and choose the Add XPath button and in the dialog box that appears, double-click tns:Promotion/tns:PromotionEligibility and choose OK.

·         In the Comparator column choose Equals in the drop down menu.

·         In the Value column, choose Eligibility in the drop down menu.

/wp-content/uploads/2013/11/image076_330622.png

Running the Test Case

·         In the Test Case editor, choose Run Test Case in the top right corner.

·         In the Rule Testing Console window, you should see the location of the test case report. Access the report in the specified location.

/wp-content/uploads/2013/11/image079_330623.png

Report showing the Test Results and also trace details for failed cases:

/wp-content/uploads/2013/11/image081_330624.png

/wp-content/uploads/2013/11/image083_330625.png

10.   Exposing the Flow Ruleset as a Web Service

Procedure

·         In the Project Explorer view, expand the dc_test node and the Rules Modeling node.

·         In the context menu of the Check_Promotion_Eligibility node, choose Web Service -> Create WSDL Artifact.

/wp-content/uploads/2013/11/image085_330626.png

·         In the dialog box that appears, in the Check_Promotion_Eligibility : Service Attributes page, accept default values. Choose Next.

·         In the Check_Promotion_Eligibility : Service Signature page, the input and output types appear and the checkboxes are selected by default. Choose Next.

        ·         In the Check_Promotion_Eligibility : WSDL Preview page, we should see the contents of the WSDL artifact.

·         Choose Finish.

/wp-content/uploads/2013/11/image089_330628.png

11.   Deploying the Rules

Procedure:

·               In the Project Explorer view, in the context menu of the dc_test node, choose Development Component -> Build.

·               In the dialog box that appears, make sure the dc_test checkbox is selected and choose OK.

/wp-content/uploads/2013/11/image091_330629.png

·               To check if the build was successful, check the Infrastructure Console.

·               In the context menu of the dc_test node, choose Development Component -> Deploy.

·               In the Deploy DCs dialog box that appears, select the dc_test checkbox and choose OK.

12.   Executing the Rules

Procedure:

·         Go to http://appserver name:port type/WSNavigator

·         Enter the user id and password in the respective fields and choose Log On.

/wp-content/uploads/2013/11/image093_330630.png

·         In the Search Services Interface section, choose the Provider System radio button.

·         Enter Ch* in the Search For field.

·         Choose the Search button.

·         We should see Check_Promotion_EligibilityPortType in the Interface Name column in the table.

·         Choose Next. We should see invokeRules in the Operation Name table.

/wp-content/uploads/2013/11/image095_330631.png

  • Choose Next. We should see the following page, where you can enter data:

  • Enter data in the fields as shown below. Please note that the PromotionEligibility field can be kept blank as it is the key field which will get the proper value based on the rules defined in the Ruleset.

/wp-content/uploads/2013/11/image097_330632.png

/wp-content/uploads/2013/11/image099_330633.png

  • Choose Next. You should see the result as follows:

/wp-content/uploads/2013/11/image101_330634.png

Bibliography:

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Naresh Bollepogu

    Hi Sourav,

    Thank you.

    Very nice blog covering most of the features in BRMS.

    I am curious to do Multiple returns in the response by using XML schema.

    Could you please help?

    Naresh

    (0) 
    1. Sourav Mukherjee Post author

      Hi Naresh,

      Is your requirement based on merging multiple messages and sending it as a single XML to target. You can easily do it in NWBPM. If this is not your requirement, could you please specify how you want to return multiple response to the target.

      Regards,

      Sourav

      (0) 

Leave a Reply