table of contents - espresso tutorials · (transactions brfplus or brf+). this is where the rules...

10

Upload: others

Post on 11-Mar-2020

12 views

Category:

Documents


2 download

TRANSCRIPT

TABLE OF CONTENTS

5

Table of Contents Preface 7

Personal dedication 9

1 Introduction 11 1.1 What are business rules? 11 1.2 What is big data? 20 1.3 Big data in business applications 22

2 Fast walkthrough of BRFplus basics 25 2.1 Overview 25 2.2 BRFplus building blocks 26 2.3 Creating a consumable rule service 34

3 Design rules for a single-run scenario 37 3.1 What is a single-run scenario? 37 3.2 Naïve design of a BRFplus rule 38

4 Design rules for mass execution 51 4.1 What is a mass-execution scenario? 51 4.2 Introducing the Logic2MD principle 57

5 Mass-run architecture 65 5.1 Overview 65 5.2 Business process and shell programs 65 5.3 Anatomy of a mass run 67

6 Benchmarks and advanced topics 101 6.1 Setting the scene 101 6.2 Benchmarks 103 6.3 Employing artifical intelligence techniques with BRFplus 112

TABLE OF CONTENTS

6

7 Monitoring BRFplus decisions using the Application Interface Framework 135 7.1 What is Application Interface Framework? 135 7.2 Monitoring BRFplus executions using AIF monitoring

tools 138 7.3 Customizing AIF to monitor executions of business rules 140 7.4 Considerations for mass runs 154

8 Creating HRF rules using analytical mode in BRFplus 169 8.1 What are HRF and analytical mode? 169 8.2 How do we create and run business rules in analytical

mode? 175

A The Author 190

B Index 191

C Disclaimer 193

25

2 Fast walkthrough of BRFplus basics This chapter is aimed at those who are not yet familiar with BRFplus but want to use it as a high-performance rules engine in an SAP sys-tem. Readers who are already familiar with BRFplus may skip this chapter.

2.1 Overview

BRFplus is an ABAP-based rules engine which is a native part of SAP NetWeaver Application Server. As such, it enjoys the following ad-vantages over other rules engines:

Full integration with the Data Dictionary (DDIC), which allows you to reuse elements that have already been defined, such as fields, structures, table types, along with their definitions, texts, translations, domain lists, etc.

The ability to define objects as local/client-dependent/client-independent; changes are transported via the standard Change and Transport System (CTS)

Design-time artifacts are translated into ABAP code (and in some cases into SQLScript that runs on HANA, as explained in Chapter 8), providing unrivalled performance

Seamless integration with ABAP applications

Actions of users in the workbench can be restricted using the standard SAP authorizations mechanism

BRFplus does not require the installation of any special software or hardware to be operational

BRFplus is an incarnation of the now obsolete Business Rule Framework (BRF) tool, hence the “plus” in its name. However, there is no compari-son between the two, as BRFplus is far more advanced than BRF.

Besides providing high performance, one of the declared objectives of BRFplus is to empower business users. As business policy is usually best understood by business experts, there is immense value in enabling

FAST WALKTHROUGH OF BRFPLUS BASICS

26

business users to understand and even edit existing business rules in the workbench in the most comfortable way. Therefore, the authoring environment of BRFplus is based on a graphical approach to allow non-IT experts and non-coders to intuitively compose business logic. Fur-thermore, BRFplus provides business users with tools to help them un-derstand the calculation steps that have led to a certain outcome and/or to record those steps in real time as a trace of an actual invocation. Oth-er key features provided by BRFplus are:

Personalization of the workbench

Ability to manage versions of each object, thus enabling you to view and run a business logic as it was in a former state

Ability to call custom code

Various administration tools

2.2 BRFplus building blocks

Video lecture

For a more comprehensive and vivid explanation of BRFplus basics, watch my video lecture BRFplus Buil-ding Blocks in the Espresso Tutorials library.

2.2.1 BRFplus workbench

The BRFplus workbench is the authoring environment for BRFplus (transactions BRFplus or BRF+). This is where the rules composer mod-els the business logic by creating and connecting various objects that act as building blocks. The workbench is one of the three main components of BRFplus that are common to many rules engines:

1. The rules authoring environment (i. e., the workbench)

2. The rules runtime engine

3. The rules repository

FAST WALKTHROUGH OF BRFPLUS BASICS

27

The repository component deals primarily with how the design-time arti-facts are persisted in the database, including version management. It is mainly concerned with the inner workings of the rules engine and will not be described here as it is outside the scope of this book. The runtime engine will be discussed in Section 2.2.4.

The BRFplus workbench can be split into three principal areas, as shown in Figure 2.1:

The navigational panel: this shows the objects tree, search results, and favorites objects. The directory icon symbolizes an object called an application. The application is a basic building block that acts as a container for other building blocks. It is used as a means for sorting and organizing business rules (and their constituent parts) according to common denominators.

The GENERAL section: this area contains the key properties of an object such as its technical name, short and long texts, name of the user it was created by, etc. This section is common to all BRFplus objects.

The main work area: this is where most of the work gets done and, in contrast to its representation in Figure 2.1, it is the larger area of the interface. Here, the user lays out and models the business logic. This area takes a different form for every building block to provide different abilities (i. e., a decision table looks different to a decision tree).

Figure 2.1: BRFplus workbench layout

FAST WALKTHROUGH OF BRFPLUS BASICS

28

2.2.2 Object types

BRFplus is object oriented. You create business logic by creating differ-ent objects (building blocks), each with a specific behavior, and then combining them so that they work together as one. I will now describe the different types of objects.

Functions

Function objects act as mediators between BRFplus—as the rules en-gine—and the caller. Although the object is called function, it is not the familiar ABAP function module. The function may receive input parame-ters and may return output parameters as well. It triggers the logic carri-ers to act on the input and generates an output. From the perspective of the caller, the function is the rule service.

Data objects

Data objects are carriers of information. They can be used to convey data in and out of the function object and may also be used as helper variables to store information between processing steps. Every data object has a type that can be bound to a DDIC definition. Data objects can be crudely categorized as tables, structures, and elements. Data elements can be categorized according to the basic types, such as text, date, number, etc.

Expressions

Expressions are carriers of business logic and are the main ingredients in each business rule. The expression provides a logical construct into which the user pours business content. There are several kinds of ex-pressions, the more common ones being the decision table and the for-mula expression type. Other common expression types are the decision tree, DB lookup, case, and loop. The most basic expression is the con-stant expression, which simply returns a (predefined) fixed value.

FAST WALKTHROUGH OF BRFPLUS BASICS

29

Rulesets

Rulesets allow you to compose business logic as a sequence of if-then-else rules. This seemingly simple feature is what allows you to imple-ment highly complex business logic. The different expression objects are then nested inside the rules—for example: “If expression A returns 5, then call expression B, else call expression C”.

Another key feature of the ruleset is the introduction of the ability to de-clare variables (based on data objects). This is extremely helpful, as it allows the business logic to be evaluated in a sequence of logical steps by saving the result of each step in a variable—much like in a computer program. Once declared in the ruleset, the variables can be used any-where within the ruleset, including in nested expressions of any depth!

Rules

The rules that are used in the ruleset are in fact objects of their own type. They integrate seamlessly with the ruleset, so for most practical uses they can be seen as just a functionality of the ruleset. However, they can also be used as stand-alone objects, much like expression objects.

Actions

Actions are special object types that trigger a noticeable change in the system. The most common actions are sending an email and logging a message. Action objects may also be used to call a custom ABAP code. As a rule of thumb, you should avoid performing actions in the context of business rules as this compromises the logical purity of the rules. Think about rules in everyday life: you act according to rules that apply to you—the rules themselves do not act on the world on your behalf. Fur-thermore, actions are susceptible to performance issues.

INDEX

191

B Index A ABAP Development Tools 178 Actions 29, 50, 68, 149 Analytical mode 170, 182 Application Interface Framework

99, 135 Artificial intelligence 101, 112

Machine learning 112 Supervised learning 112, 118

B Big data 16, 20, 22, 93, 136

3 Vs 20 Big O notation 43 Business process 65, 67, 80

C Call database procedure 171 Callback routine 84 Callback routine 83 CDS view 74, 79, 88, 106, 175,

178, 183, 187 Classifier 113

Naïve Bayes classifier 113 Code pushdown 79, 174 Compactification 16, 19, 47, 106 Cross entropy 120

D Data Definition Language 174 Database context 171 Database context 182 DB lookup expression 48 DB lookup expression 32 DB lookup expression 49 DB lookup expression 50

DB lookup expression 64 Decision Service Management

64, 140 Decision table 57 Decision table 30, 54, 55 Decision table 104 Decision table

Dummy decision table 116 Decision table

Dummy decision table 117 Decision table 184 Decision table 185 Decision table 187 Decision tree 130, 133

Binary decision tree 118 Decision tree classifier 118, 129 Random forest 134

E Edge cases 136 Event mode 33, 170 Extended Services 174

F Function object 28, 32, 34, 129,

182 Functional mode 33, 129, 170

G Generation mode 34 Greedy algorithm 124

H HANA Rules Framework 74, 169 High-order logic 16, 57

High-order business rule 16, 59

INDEX

192

Low-order variants 23, 51, 57, 61, 105

I In-memory database 172 Internal interface 136 Interpretation mode 34 Invoker 15, 16

L Lock objects 97, 99 Logic2MD 57, 58, 59, 60, 63, 72,

74, 75, 104, 108 Logical quantifier 17 LOOP GROUP BY 88

M Mass-execution scenario 51, 154 Mass-execution scenario 161 Micro decision 16

N Naïve design 38, 39, 46, 47, 49 Nested loops 41, 46

O Ockham’s razor 41

P Package run 73, 75, 78, 81, 83,

84, 86, 107, 155 Parallelization 56, 66, 80, 84, 87,

97 Pure business logic 68 Purity index 119

R Resource failure exception 85 RFC function 82, 83 Rule as a service 15

Analytical rule service 187 Rule service 15, 32, 34, 39, 158

Rule expression language 184, 186

Rules engine components Authoring environment 26, 33 Rules repository 26, 33 Runtime engine 26, 33

Runtime complexity 39, 44, 45, 46, 47, 48

S SAP HANA Rules Framework 63 Shell program 66, 67, 81, 89

Level 2 shell program 93, 96, 97 Signature minimization 49 Single-case scenario 68, 141, 157 Single-run scenario 37 Space complexity 39, 45 SQLScript 171, 188 STARTING NEW TASK 82, 94 Stored procedure 174 Symbolism 11

T Text rule 184, 186 Top expression 33, 129 Transactional rule 37, 170 trias politica analogy 50 Trias politica analogy 40