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.
myArray CHAR(1)[3] {"A", "B", "C"};
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") |
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:
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 |