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.
LET a, b, c = func1(name = 'grok', age = 17);
LET a, b, c = 7, func2('orange', 'green');
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
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.