Home

News (12/11/08)new

Start Here
Getting Started
Downloads


Documentation

Tutorials (12/07/08)new
Tablets Structure
Deployment
Web Studio
OpenL Basics
Constrainernew

Change Log

References
LGPL License


Motivational Reading

OpenL Apologia



SourceForge.net Logo
Table of Contents

OpenL Tablets Structure and Semantics

Also see Decision Table Performance Optimization , Data Tables , Tutorial

Decision Table

Decision Tables are the cornerstone of any Business Intelligence suite that at least pretends to be business user oriented. Just to prove this statement most of the Business Rules vendors recently included their own implementations of Decision Tables into their offerings. This document argues that Business Rules in essence always are decision tables, but may be it is a bit overstated. In any case we present to you here the best solution for integrating decision tables into your application

Here is an implementation of decision table from HelloWorld.xls

On this picture you can easily see the main components of the Decision Tablet.

The first row is a header. It starts with a keyword Rules that is followed by familiar to every Java programmer method signature void helloWorld(int hour), that we call Decision Table Method Header.

The second row provides header for decision table columns. There is a simple naming convention for header columns: if header starts with a 'C' then it is a Condition, if it starts with an 'A' it is an Action. Since version 3.1.0.6 we introduced (optional) column Rule, where you can put Rule ID (each Decision Table row is a rule in some sense) . This column is optional and can be used for tracing and documentation purposes. Also it can anchor multi-row rule (in case of array parameters).

The third row contains code snippet that actually gets executed according to decision table logic. This code has a standard Java syntax, and therefore can be easily written by any Java programmer. As you can see, this code uses both parameter from the header hour and from the column min. Condition expressions must return type boolean (the return keyword is optional. The code snippet always returns the value of the last expression). Action expressions can be of any type.

The fourth row provides column parameter definitions. Each condition and action can have one or more parameters. The data in the columns will be converted into appropriate types using the following rules:

Java Type Conversion
java.lang.Integer, int Standard Java conversion
java.lang.Long, long Standard Java conversion
java.lang.Double, double Standard Java conversion + supports percent character at the end
java.lang.String Copy of the cell content; because empty cell means ignoring condition or action in Decision Table to enter an empty String you need to write an expression '=""
java.util.Date Conversion is done by using java.text.DateFormat.SHORT. Due to the fact that Excel converts dates into internal format it is necessary to enter dates as strings (to tell Excel that the cell content should be treated as text start it with apostrophe)
java.lang.Character, char Cell must contain single character
java.lang.Boolean, boolean Words "true", "yes", "t" or "y" in lower or upper case mean true. Everything else mean false
Any Java Class Call is made to the public constructor with a String parameter. This is how, for example, we provide custom data types like IntRange.
org.openl.rules.helpers.IntRange, org.openl.rules.helpers.DoubleRange Supports following formats: 1 - 10 (from 1 to 10 inclusive), < 100 (less than 100), 20+ (20 or more)
Arrays Decision Table supports one-dimensional arrays for all supported datatypes. Arrays syntax is the same as in Java. Arrays are entered as multiple cells. If you need to enter multiple values in a Decision Table row you should merge vertically the first row cell to cover all the rows in your array columns. The first column therefore cannot be an array, the best way to deal with it is to put Rule column first. See Tutorials for good Array examples

The fifth row contains Column Display Names or human readable columns descriptions.

Everything below the fifth row is Decision Table data. This data is used as parameter values when code snippets are executed

Expressions in Decision Table

In addition to literal data Decision Table supports expressions in table cells. Expressions should start with '='. Due to the fact that Excel expressions also start with '=', expression cells also should be entered as text fields (starting with apostrophe). For example, expression
x+5
must be entered literally as
'=x+5
Single '='in a cell is not considered an Expression. The alternative way of entering expressions is to put cell content in '{'... '}' brackets instead of using '='.

Expression Type must be compatible with the column type.

Decision Table Algorithm

Decision Table Rows (Rules) are executed from top to bottom. In "classic" decision tables all rule rows are executed. OpenL Tablets also provide the alternative way of execution by using so-called RET(return) columns. RET column works as a regular action with the only very important exception, once executed it returns the action result as a result of Decision Table Method. The return type of RET column expression must be compatible with the return type of Decision Table Method Header. Type void is compatible with anything.

Each Rule conditions are checked from left to right. This process stops after the first failure. If all Conditions are checked, all the Actions are being performed from left to right. Conditions and Actions with empty parameter cells are ignored.

To see more examples of Decision Tables in action check OpenL Tablets Tutorial

Also see Data Tables , Tutorial