Quantcast
Channel: SCN : Blog List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 902

SAP HANA Rules Framework End-to-End Tutorial

$
0
0

Inspired by the excellent series of SAP HANA Rules Framework by the SAP HANA Academy YouTube videos listed by Denys van Kempen, and because I did not have the banking model available referenced in those videos, I decided to start my own SAP HANA Rules Framework 1.0 SPS 07 proof of concept implementation.

 

This blog describes my steps from installing the SAP HANA Rules Framework 1.0 SPS 07 Patch Level 1 and configuring it until creating a HANA Rule and executing a HANA Rule Service with varying HANA Rule Conditions in the end.

 

The SAP HANA Rules Framework 1.0 SPS 07 can be downloaded from SAP Service Marketplace:

SMP.png

At the time of this blog, SPS 07 Patch Level 1 was the latest available version:

HCORULEFW07P_1.png

After extracting the ZIP archive, I install the package with the HANA Application Lifecycle Management Delivery Units Import functionality:

Import Delivery Unit.png

After confirming the import of the Delivery Unit:

Confirm Import of Delivery Unit.png

The imports starts and runs for a little while. Once completed you get a green light and we are ready to proceed:

HCO_RULE_FW.png

Next, back in HANA Studio, you have to create a user called HRF_TECH_USER and grant this user the following, to enable rule service consumption:

 

  • sap.hrf::AllPrivilegesForTechnicalUser application privilege
  • sap.hrf.role.model::HRF_TECH_ROLE role

 

Also, you would have to grant your user a series of HANA Rules Framework Roles:

Granted Roles.png

With that preparation we can configure the HANA Rules Framework via REST API. Please configure basic authentication with your user, that you granted the roles above. As a result, you are rewarded with a success message:

HRF Technical Configuration success.png

And subsequently with access to the Fiori Launch Pad of the SAP HANA Rules Framework at:

 

http://<full_domain_name>:80<instance_number>/sap/hana/uis/clients/ushell-app/shells/fiori/FioriLaunchpad.html?siteId=sap.hrf.ui|app|app2

Launch Pad.png

With the configuration in the bag, we next deploy the SAP HANA Rules Framework Modelling Tools at:

 

http://<hostname>:80<instance_number>/sap/hrf/updatesite

HANA Rules Framework Tools.png

After confirming the license agreement the software gets installed and you will have to restart SAP HANA Studio.

 

Next we build a small Point of Sales data model as the basis for our HANA Rules. You find the SQL scripts for these tables and their contents in the appendix at the end of this blog:

Tables.png

Please do not forget to grant both users _SYS_REPO and HRF_TECH_USER SELECT Privileges with Grant Option to the schema of your user. These are needed for the creation and execution of the Rules Service respectively:

Priviledges.png

Now we create a new XS Project and within that a new Vocabulary based on the tables above:

hpvocabulary.png

For this we join:

 

  • CUSTOMER.ID to SOHEADER.DEBITOR
  • SOHEADER.NUMBER to SOITEM.PO
  • SOITEM.ARTICLE to ARTICLE.PART

 

In addition we activate (marked with an Orange light):

 

  • CUSTOMER.NAME
  • CUSTEOMER.SEGMENT
  • SOHEADER.TOTAL
  • ARTICLE.CATEGORY

Outline.png

To finish our vocabulary, we create an Output Type:

Edit Output.png

Now we got the basis to create our first HANA Rule. In the Fiori Launch Pad of the SAP HANA Rules Framework chose Rules – Mange all rules and create a new HANA Rule:

Segmentation.png

Then add the following conditions. Type forward help will help you immensely with this, especially for the joined condition Category over three intermediate tables:

Edit Conditions.png

Finally Add Output Customer and provide conditions as follows:

  • Conditions: SEGMENT of the CUSTOMER = ‘Y’
  • CATEGORY of the PART of the PO of the DEBITOR of the CUSTOMER = ‘G’
  • Outputs: Customer NAME of the CUSTOMER

Rule.png

Now Activate the Rule and select Rule Services from the Fiori Launch Pad of the SAP HANA Rules Framework and create a new Rules Service as follows:

Rule Service.png

Once you save this Rule Service and Test run it, you get two hits as expected, i.e. the customers in Segment = 'Y' and at least one purchase of a product in Category = 'G':

Test Results.png

Now you can play with the Rule Conditions and check-out the respective Test Results. If you for example changed the Category Condition to ‘P’ and Activate it:

Activate.png

You would only get the one expected Test Result back:

Faigle.png

And when further changing the Segment Condition to ‘X’ and Activate it:

Rule Builder.png

You get back the one customer with Segment = ‘X’ and a product in Category = ‘P’:

Frehn.png

Appendix

 

These are the SQL scripts to create the Point of Sales data model used in this blog. Schema USER will have to be replaced with your user schema:

 

CREATE COLUMN TABLE "USER"."CUSTOMER" ("ID" INTEGER CS_INT,

  "NAME" VARCHAR(8),

  "SEGMENT" VARCHAR(1),

  PRIMARY KEY ("ID")) UNLOAD PRIORITY 5 AUTO MERGE

 

insert into "USER"."CUSTOMER" values(1,'Faigle','Y')

 

insert into "USER"."CUSTOMER" values(2,'Frehn','X')

 

insert into "USER"."CUSTOMER" values(3,'Schuler','Y')

 

CREATE COLUMN TABLE "USER"."SOHEADER" ("NUMBER" INTEGER CS_INT,

  "DEBITOR" INTEGER CS_INT,

  "TOTAL" DECIMAL(5,

  2) CS_FIXED,

  PRIMARY KEY ("NUMBER")) UNLOAD PRIORITY 5 AUTO MERGE

 

insert into "USER"."SOHEADER" values(1,1,70)

 

insert into "USER"."SOHEADER" values(2,2,50)

 

insert into "USER"."SOHEADER" values(3,3,30)

 

CREATE COLUMN TABLE "USER"."SOITEM" ("PO" INTEGER CS_INT,

  "ARTICLE" INTEGER CS_INT,

  "COUNT" INTEGER CS_INT,

  "AMOUNT" DECIMAL(5,

  2) CS_FIXED) UNLOAD PRIORITY 5 AUTO MERGE

 

insert into "USER"."SOITEM" values(1,1,1,50)

 

insert into "USER"."SOITEM" values(1,2,2,20)

 

insert into "USER"."SOITEM" values(2,1,1,50)

 

insert into "USER"."SOITEM" values(3,2,3,30)

 

CREATE COLUMN TABLE "USER"."ARTICLE" ("PART" INTEGER CS_INT,

  "DESCRIPTION" VARCHAR(10),

  "PRICE" DECIMAL(5,

  2) CS_FIXED,

  "CATEGORY" VARCHAR(1),

  PRIMARY KEY ("PART")) UNLOAD PRIORITY 5 AUTO MERGE

 

insert into "USER"."ARTICLE" values(1,'Keyboard',50,'P')

 

insert into "USER"."ARTICLE" values(2,'USB Stick',10,'G')


Viewing all articles
Browse latest Browse all 902

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>