Create Variables statement (within function)

Defines a variable within the function and initializes its variable.

Syntax

CREATE VARIABLE data_type name [= value] ;
Components

data_type

The CCL data type of the variable.

name

The name of the variable.

value

A literal of the specified type.

Usage

This statement creates a variable which can be used by subsequent CFL statements inside the block. As with other CFL statements, the scope of this form of the Create Variable statement is the block. A different, though syntactically identical, usage of the Create Variable statement is within a query module. For more information, see Create Variable Statement. The variable is created by defining its data type and name. Optionally, the variable can also be initialized with a constant or expression of the same type as variable. (Literals of type STRING must be enclosed in quotation marks.) If a variable is not initialized in the Create Variable statement, the variable's value is initialized to NULL. The variable value can be set later using the Assignment Statement.

Restrictions

See Also

Examples

The following example creates several variables. The variable called res is visible to the whole function, but the two occurrences of variable ii are visible only in the respective blocks of the If statement.

CREATE FUNCTION MyFunction(InputPar FLOAT) RETURNS FLOAT;
   CREATE VARIABLE FLOAT res = SIN(InputPar) + COS(InputPar); 
   IF InputPar > 0 THEN
      CREATE VARIABLE INTEGER ii = TO_INTEGER(ROUND(InputPar, 0));
      WHILE(ii > 0) DO
         res = res + ii * sin(ii / 2);
         ii = ii - 1;
      END; 
   ELSE
      CREATE VARIABLE INTEGER ii = TO_INTEGER(ROUND(-InputPar, 0));
      WHILE(ii > 0) DO
         res = res + ii * cos(ii / 2);
         ii = ii - 1 ;
      END; 
   END; 
   RETURN res; 
END FUNCTION;