sysVar.arrayIndex
The system variable sysVar.arrayIndex contains a number:
- The number of the first element in an array that matches the search condition of a simple logical expression with an in operator, as shown in a later example.
- Zero, if no array element matches the search condition.
- The number of the last element modified in the target array after a move ... for count statement.
You can use sysVar.arrayIndex as any of these:
- As an array subscript to access the matching row or array element
- As the source or target in an assignment or move statement
- As the count value in a move ... for count statement
- As a variable in a logical expression
- As the argument in an exit or return statement
The characteristics of sysVar.arrayIndex are as follows:
- Primitive type
- BIN
- Data length
- 4
- Is value always restored after a converse?
- Only in a non-segmented text program; for details see Segmentation
Example
Assume that the record myRecord is based on the following part:
Record mySerialRecPart serialRecord: fileName = "myFile" end 10 zipCodeArray CHA(9)[100]; 10 cityStateArray CHA(30)[100]; endFurthermore, assume that the arrays are initialized with zip codes and city-and-state combinations.
The following code sets the variable currentCityState to the city and state that corresponds to the specified zip code:
currentZipCode = "27540"; if (currentZipCode in myRecord.zipCodeArray) currentCityState = myRecord.cityStateArray[sysVar.arrayIndex]; endAfter the if statement, sysVar.arrayIndex contains the index of the first zipCodeArray element that contains the value of "27540". If "27540" is not found in zipCodeArray, the value of sysVar.arrayIndex is 0.
Related concepts
Segmentation in text applications
Related reference
Arrays
in operator
Logical expressions