ESQL variables

Start of changeAn ESQL variable is a data field used to help process a message.End of change

You must declare a variable and state its type before you can use it. A variable's data type is fixed; if you code ESQL that assigns a value of a different type, either an implicit cast to the data type of the target is implemented or an exception is raised (if the implicit cast is not supported).

Start of changeTo define a variable and give it a name, use the DECLARE statement.
Note: Start of changeThe names of ESQL variables are case sensitive, so it is important to make sure that you use the correct case in all places. The simplest way to guarantee this is always to define variables using upper case names.End of change
The Message Broker Toolkit flags, with warning markers, variables that have not been defined. It is best practice to remove all these warnings before deploying a message flow.End of change

Assign an initial value to the variable when you declare it. You can also set its value (initial or other) using the SET statement. You can use variables in expressions and you can test its value, like other field references.

If you can predict the initial value that you want to assign to a variable, it is more efficient to provide that value on the DECLARE statement than to set the value with a separate SET statement.

The following code shows the use of some variables:

DECLARE VAR1 INTEGER 100;
DECLARE Index INTEGER;
SET Index = 1;
Index = Index + 1;
IF Index = 1 THEN
DO;
  -- more ESQL --
END IF;
IF VAR1 = 100 THEN
DO;
  SET VAR1 = VAR1 + Index;
END IF;
Related concepts
Message flows overview
Related tasks
Developing message flows
Developing ESQL
Related reference
Built-in nodes
Compute node
Database node
Filter node
BEGIN ... END statement