SQL iQuery Script Built-in Function

Index

ELEM

Return Number of Array Elements

The ELEM() or ELEMS() built-in functions return the number of elements in the Session Variable Array.

Syntax

The ELEM() built-in function returns the number of independent values stored in the Session Variable. Multiple values may be stored in Session Variables using the SELECT INTO with multiple rows returned, or using the (a) operation extender on the EVAL operation. 

Parameters

  1. A session variable whose number of values or "elements" count is returned.
select baldue INTO &DUE
FROM qiws.qcustcdt
WHERE BALDUE > 0;

for &i = 1 to elem(&due);
if (&due[&i] > 1000); // To high a balance?
// send out Payment Due notice
endif;
endfor;

In this example the ELEM(&DUE) is performed once for each value stored in the &DUE Session Variable. That variable's values are loaded by the SELECT statement. If multiple rows are returned each value is stored in the &DUE variable separately, creating an array-like variable. The FOR loop is performed for the number of elements in that variable. The variable &I is automatically declared and is automatically incremented on each pass through the for loop.
To access individual values of the Session Variable, the square brackets are used as an "array subscript" syntax. For example &MYARR[3] references the 3rd value in the &MYARR Session Variable.