Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SPL Statements > LET >

Calling a Function in a LET Statement

You can call a user-defined function in a LET statement and assign the returned values to an SPL variable that receives the values that the function returns.

An SPL function can return multiple values (that is, values from multiple columns in the same row) into a list of variable names. In other words, the function can have multiple values in its RETURN statement and the LET statement can have multiple variables to receive the returned values.

When you call the function, you must specify all the necessary arguments to the function unless the arguments of the function have default values. If you specify the name of one of the parameters in the called function with syntax such as name = 'smith', you must name all of the parameters.

An SPL function that selects and returns more than one row must be enclosed in a FOREACH loop.

The following two examples show valid LET statements:

LET a, b, c = func1(name = 'grok', age = 17);
LET a, b, c = 7, func2('orange', 'green');

The following LET statement is not valid because it tries to add the output of two functions and then assign the sum to two variables, a and b.

LET a, b = func1() + func2(); -- INVALID CODE

You can easily split this LET statement into two valid LET statements:

LET a = (func1() + func2()); 
LET b = a;                   -- VALID CODE

A function called in a LET statement can have an argument of COLLECTION, SET, MULTISET, or LIST. You can assign the value that the function returns to a variable, for example:

LET d = function1(collection1);
LET a = function2(set1);

In the first statement, the SPL function function1 accepts collection1 (that is, any collection data type) as an argument and returns its value to the variable d. In the second statement, the SPL function function2 accepts set1 as an argument and returns a value to the variable a.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]