Show TOC

Background documentationContext and Result

 

Context and result define the input and output parameter interface. In BRFplus, input parameters are referred to as context while output parameters are referred to as result. Context and result are data carriers.

Features

General

Both context and result are a set of data objects, such as an element, structure, or a table. A context or a result of type element can be a text, number, Boolean, quantity, amount, and timepoint.

Functions as well as expressions, actions, and rules have a context. A set of attributes defined by the context is used as input values to be processed by a function or an expression. The context can consist of one or many elements, structures, or tables, each of which is addressed by its name.

The context data of a function can be used by all subexpressions that belong to the function's top expression or ruleset. The input parameters of the expressions are filled either with the function's context or with the result of other expressions.

In contrast to this, a function or expression can always have only one result data object. Given that, if a business rule is to return more than one value at once, this can only be accomplished by assigning a structure or a table as a result data object.

When you create a function with execution mode Event Mode, the system assigns the predefined Actions table as the function's result data object. However, you can overwrite this default assignment with any data object that may suit better.

Context Overview

For each object that has a context, you can easily inform yourself of the available context data objects. To accomplish this, navigate to the object in question in the BRFplus workbench and choose Context Overview. The system then displays a list with all data objects that are available via the object's context. For each context data object, the system displays its origin (function context or result). Likewise, in the same dialog you can inform yourself of potential other context data objects that are currently not available for use by the expression.

Note Note

If a function is run in event mode instead of functional mode, the context can be changed and can be a part of the result. In this case, the result parameter is not relevant.

If an expression, action, or rule is assigned to more than one function, the list of available context data objects represents the intersection of the context data objects of all involved functions. This is necessary to ensure that the expression, action, or rule can be processed properly, regardless by which function it is called.

End of the note.

Example Example

A decision table expression DT is used by three different functions F1, F2, and F3, either directly as the function's top expression or indirectly as a nested expression. The following table shows the context data objects for each of these functions:

Function

Parameters

F1

NUM1, TXT1, BOOL1

F2

NUM1, TXT1

F3

NUM1, BOOL1

In this scenario, there is only one context data object that all three functions have in common, namely NUM1. Consequently, an expression like decision table DT that is used in all three functions can only access this one common context data object. Using any of the other context data objects would lead to a situation where the expression's context would be partially undefined for at least one of the three function, which is not permitted.

If, in the scenario described, you would decide to assign DT to a fourth function F4, and if F4 has only one number data object NUM2 in the context that is not available in any of the three other functions, then the intersection of context data objects that can be used in DT would be empty.

End of the example.
Implicit Result Type Conversion

The result data object of a BRFplus object must be compatible to the context data object to which the result is passed as input data. For example, if a decision table cell contains a value range expression, then the range parameters must be populated by direct values, data objects, or expressions of the same type as the value range parameters. However, there is one exception to this rule: For a function with a result data object of type text, you can assign any expression as its top expression, regardless of the result data object type of that expression. If the result data object type of the expression differs from the text data object defined for the function, BRFplus performs an implicit type conversion of the expression's result value into text. The conversion logic is the same as the one that is used for the ToString function that is available for formula expressions. For the details of this logic, see the formula function documentation that is available in the BRFplus workbench.