Try OpenEdge Now
skip to main content
BPM Events User's Guide
The rule language : Rule structure : Common variables, constants, and their scope : Constant values vs. variables
 
Constant values vs. variables
A constant value is declared using the keyword val. Such a symbol is intended to be assigned an initial value that does not change later (immutable). This is checked at compile time. Always complete such initialization using the operator "=".
Examples:
val blserver = getBLserver();
val session = blserver.connect("ebms", "ebms");
Variables are declared with the keyword var. Initialize them in the same way as a constant value, but modifiable later.
Examples:
var mycounter = 1;
var taxrate;
var ratings = new infopad<cell{rating:int}>[10][2]("ratings");
Note: Although infopad variables are global to a module, they do not require declaring and initializing. Their declaration is implicit. This allows for grouping all infopad-related initial statements in the initial section of a module.
In the examples below, the variable is local to the iteration statement. The identifier i is incremented to iterate over the rows of an infopad, and must be declared as a variable.
for (var i = 1; i <= employees.rowCount(); i++ )
{ if (employees[i][1].name = evt1.name)
    employees[i][1].salary += evt1.raise; }
Except when declared, a variable must be assigned a new value using the operator ":=". So the statement "i++" in the previous example could have been written "i := i+ 1". When initialized in the declaration statement, the operator "=" is used, similar to constant values.
var empnbr = employees.rowCount();
...
empnbr := empnbr + newemps;
If no re-assignment is required for an identifier, then it is recommended to declare it as a constant value (val), instead of a variable (var). The compiler enforces this immutability.