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: 
architectSAP
Active Contributor
16,910
Inspired by the excellent series of SAP HANA Rules Framework by the SAP HANA Academy YouTube videos listed by denys.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. For further details please refer to SAP Note 2259199 - Release-Informationen zu SAP HANA Rules Framework 1.0 SPS07 and to the SAP HANA Rules Framework's official documentation on SAP Service Marketplace.

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



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



Please be aware that SAP HANA Rules Framework 1.0 SPS 07 requires SAP HANA SPS 11. For this blog, I have been using the SAP HANA Database Revision 111. However please be aware, that at the time of this blog, there has been no SAP HANA Datacenter Service Point released for HANA SPS 11 yet, so at the time of this blog, you should try this in a sandbox environment only. Please check SAP Note 2021789 - SAP HANA Revision and Maintenance Strategy, whether this is still the case when you read this.

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



After confirming the import of the Delivery Unit:



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



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:



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:



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/FioriLaun...



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



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:



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:



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



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

  • CUSTOMER.SEGMENT

  • SOHEADER.TOTAL

  • ARTICLE.CATEGORY




To finish our vocabulary, we create an Output Type:



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:



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



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




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:



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':



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:



You would only get the one expected Test Result back:



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



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



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 NOT NULL ,
"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 NOT NULL ,
"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 NOT NULL ,
"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');
17 Comments
Labels in this area