| Reference > Rule Languages > Business Action Language > BAL Constructs > set <variable> to <definition> |
set <variable> to <definition> |
PREVIOUS NEXT |
Defines a variable as an object, a collection, or a value.
set `<variable>' to <definition> [in <list> / from <object>] [where <test>*] ;
Use this construct in the definitions part of a rule to declare a local variable. Variables allow you to write more concise rules by using a short, convenient identifier to represent a value or the result of an expression. A local variable can be used anywhere within this same rule, but is not available in other rules.
You should enclose the name of each variable in single quotes. This is compulsory for variable names that contain spaces. While it is not essential to enclose one word variable names in single quotes, it is strongly recommended that you do so, to make them easier to identify and to reduce the risk of confusion.
The following examples show how to define a variable as an object.
definitions set 'i' to an item; set 'house' to a house where the price of this house is more than 1000;
The following examples show how to define a variable as a literal, string, or collection.
definitions set 'category' to Gold ; set 's' to "a string"; set 'expensive items' to all items in the items of the shopping cart of the customer where the price of each item is more than 200;
The following example shows how to define a variable as the result of an expression.
definitions set 'expr' to the price of the car of the customer + 100; set 'h2' to the house of the customer where the price of this house is more than 1000;
The following example shows how to define a variable as another variable.
definitions set 'expr2' to 'expr';
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |