Function 
A function is the rule interface in BRFplus and acts as a link between the application code and the BRFplus code. A function carries a context and a result. It imports the context from the calling application and passes the context data to the assigned top expression or ruleset for further processing. After processing, the function returns the calculated result to the calling application.
A function can be designed for one of the following modes of operation:
Functional Mode
In functional mode, function execution starts with the assigned top expression. From this top expression, the processing may run through any number of nested subexpressions until a result is returned.
Event Mode
In event mode, the function is associated with a list of rulesets that are executed according to their execution priority and their position in the list.
In addition, there is another option that combines both modes of operation. For more information, see Modes of Operation.
The function signature consists of two parts:
Context
The context is a container for data objects that you can assign as import parameters for the function. You choose the context data objects of a function according to the requirements of the calling application by which the BRFplus function is invoked.
Result
The result data object returns a result value that has been calculated by the expressions of which the function consists.
Note
For functions in event mode, the result data object is automatically set to the predefined Actions table where the actions are recorded that have been triggered by the assigned rulesets.
For a function where you have set the mode of operation to either Event Mode or Functional and Event Mode on the Properties tab, the system expects that you assign one or more rulesets that shall be processed when the function is processed. You can create a new ruleset to be assigned to a function directly from the editing work area of a function. For an already existing ruleset, however, you first have to navigate to that ruleset and define the desired function as the ruleset's trigger. Once this assignment has been made, the ruleset is listed on the Assigned Rulesets tab of the function.
In case there is more than one ruleset assigned to a function, the rulesets are triggered according to the order in which they appear in the function's list of assigned rulesets. You can influence the execution order for the rulesets by defining a priority for each involved ruleset. The priority is a numeric value between 0 and 99 that you can define for a ruleset (default priority: 0). The list of assigned rulesets is sorted by that priority in ascending order so that the ruleset with the lowest priority value is executed first, followed by the ruleset with the second-lowest priority, and so on.
Note
When you execute a function that triggers more than one ruleset, the system starts by executing the first ruleset and waits for its termination before it starts the execution of the next ruleset, and so on. This is a prerequisite for the system to be able to pass parameters that may have been modified by a ruleset from one ruleset to another. There is no parallel processing of the assigned rulesets.
The relationship between a function and its assigned rulesets is not absolutely obvious at first glance. For a better understanding of the underlying concept, keep the following in mind:
Function and ruleset are modeled in a 1:n relationship. That is, one function can have any number of rulesets assigned, whereas a ruleset can only be triggered by exactly one function.
The relationship between function and ruleset is established from the ruleset's point of view, not vice versa. As a consequence, the system keeps track of which function is assigned to a particular ruleset, but not the other way round. This means that a function does not know the rulesets for which it is assigned as a trigger. This is true although the assigned rulesets of a function are listed in the BRFplus workbench for a function.
The one-way perspective from ruleset to function is also reflected in the following aspects of the system behavior:
If a function has been assigned to one or more rulesets as a trigger, these rulesets are shown in the where-used list of the function, but not in the Uses section of the repository tree in the BRFplus workbench.
When you activate a function and request that also the subordinate objects of the function shall be activated if necessary, this recursive activation does not touch any rulesets for which the function may have been assigned as a trigger.
The same applies for all other activities related to a function that can be carried out recursively, like copying or checking a function. Here, too, any rulesets to which the function may be assigned are not taken into account.
BRFplus provides a built-in code generation facility used to compile source code for as many rule constructs in a function as possible.
You can simulate the function processing to test the function's behavior in a sandbox environment. Here, you can gain an in-depth insight into the system status for every single step the system takes during function processing.
In BRFplus, you can request the system to create a trace log to keep track of all the events that may arise during function execution. The trace information is stored in the system and can be reviewed at any point in time.
BRFplus supports the generation of web services for a function. This enables you to integrate the rule execution power of a BRFplus function into a service-oriented software environment.