in operator

The in operator searches for a value in an array. If the value is found, the expression evaluates to TRUE and the sysVar.arrayIndex system variable is set to the index of the element that contains the value. If the value is not found, the expression evaluates to FALSE, and sysVar.arrayIndex is set to zero.

Syntax

Syntax diagram for the in operator
searchValue
An expression.
array
A one-dimensional array, or an element of a multidimensional array.
dataTableColumn
The name of a column in a DataTable part. The in operator interacts with that column as if the column were a one-dimensional array.
start
An integer, or an expression that resolves to an integer. The value of start specifies the index of the first element to be searched for searchValue. If the value of start is greater than the number of elements in the array, the expression evaluates to false, and sysVar.arrayIndex is set to zero. If the in expression does not include from start, the search begins at the first element of the array or column. (EGL array indexes begin at 1 rather than 0.)

Examples

The following table shows the effect of the in operator when you refer to a character array named myArray, defined as follows:
myArray CHAR(1)[3] {"A", "B", "C"};
Table 1. Effects of the in operator
Logical expression Value of expression Value of sysVar. ArrayIndex Comment
"A" in myArray true 1  
"C" in myArray from 2 true 3 Search begins at second element ("B")
"A" in myArray from 2 false 0 Search begins at second element ("B")
In the next example, myArray01D is a one-dimensional array of strings, defined as follows:
myArray01D STRING[] = ["ABC", "DEF", "GHI"];
myArray02D is a two-dimensional array, with each element (such as myArray02D[1,1]) containing a single character, defined as follows:
myArray02D CHAR(1)[3][3] = [["A", "B", "C"],
                         ["D", "E", "F"],
                         ["G", "H", "I"]];

The next table shows the effect of the in operator on myArray02D:

Table 2. Further effects of the in operator
Logical expression Value of expression Value of sysVar. ArrayIndex Comment
"DEF" in myArray01D true 2  
"C" in myArray02D[1] true 1  
"I" in myArray02D[3] from 2 true 3 Search begins at the third row, second element
"G" in myArray02D[2] from 2 false 0 Search ends at the last element of the row being reviewed
"G" in myArray02D[2] from 4 false 0 The second index is greater than the number of columns available to search

Compatibility

Table 3. Compatibility considerations for the in operator
Platform Issue
JavaScript generation The in operator is not supported.

Feedback