ILOG JRules User Guide > Creating Rule Projects > Concepts > Functions

With ILOG JRules you can create functions whose code is evaluated when the project executes. Functions allow you to share procedures among elements of the ruleset.

A function can be called either from a rule, from another function, or from task code.

Functions can be called in rule actions. The function keyword is used to declare a function in a rule file before a rule declaration. A function can be called in the action part of a rule and you can add as many functions to the rule file as you like. This enables you to write IRL code within functions, mapped to the IRL function keyword.

Functions can be used to set up the working memory when testing ruleset execution.

The function is composed of a header and a statement part. The header contains the function return type and its signature. A function signature consists of the function name and an argument list. This list can be either empty or composed of pairs: the argument type and name, separated by commas.

function returnType functionName (argumentList)
{
     code
}

The statement part can contain any action statements, just as in the action part of a rule, plus a return statement.

You use return to exit from the current function. The flow of control returns to the statement that follows the original function call. The return statement has two forms: one that returns a value and one that does not. To return a value, simply put the value (or an expression that calculates the value) after the return keyword:

return ++count;

The data type of the value returned by return must match the type of the function's declared return value. When a function is declared void, use the form of return that does not return a value:

return;

Note
A function is not required to declare in its throws statement any subclasses of IlrRuntimeException that might be thrown during the execution of the function.

Related Concepts

Technical Rule Actions
Branching Statements
Exception Handling Statements
The BOM to XOM Mapping Mechanism

Related Tasks

Working with Technical Rules
Refactoring Rule Artifacts
Creating a Function
Mapping an Attribute Assignment to a Function
Defining How Business Elements Map to the XOM
Troubleshooting Execution

Related Reference

Function Editor
New Function Wizard
ILOG Rule Language
Default Constructor Dynamic Methods