Domain: Variable access (variable name)
The ARRAY-INDEX( ) function can be applied to arrays. ARRAY-INDEX supplies the value of an array index. As a result, other functions can then explicitly request this element via the array index.
Format
ARRAY-INDEX( ) |
ARRAY-NAME = string_expression ,INDEX = *FIRST / *LAST / *LOWER-BOUND / *UPPER-BOUND |
Result type
INTEGER
Input parameters
ARRAY NAME = string_expression
Designates an array.
INDEX =
Specifies which array index is to be requested.
INDEX = *FIRST
Array index of the first element in the array containing a valid value.
INDEX = *LAST
Array index of the last element in the array containing a valid value.
INDEX = *LOWER-BOUND
Array index defined in the variable declaration with the DECLARE-VARIABLE command in the operand MULTIPLE-ELEMENTS = *ARRAY (LOWER-BOUND = ).
INDEX = *UPPER-BOUND
Array index defined in the variable declaration with the DECLARE-VARIABLE command in the operand MULTIPLE-ELEMENTS = *ARRAY (UPPER-BOUND = ).
Result
Index of the array element, returned as an integer.
Error messages
SDP0423 VARIABLE '(&00)' NOT AN ARRAY SDP1007 NO VARIABLE DECLARED SDP1052 AGGREGATE ELEMENT NOT PRESENT SDP1101 SYNTAX ERROR IN VARIABLE NAME
Example
The array AR is declared and contains the following:
/DECLARE-VARIABLE AR,TYPE = *STRING, MULTIPLE-ELEMENTS = *ARRAY
/AR#2 = 'abc'
/AR#3 = 'cde'
/AR#4 = ' '
/ARIND = ARRAY-INDEX('AR', *FIRST)
/SHOW-VARIABLE ARIND
ARIND = 2
/ARIND = ARRAY-INDEX('AR', *LAST)
/SHOW-VARIABLE ARIND
ARIND = 4
/ARIND = ARRAY-INDEX('AR', *LOWER-BOUND)
/SHOW-VARIABLE ARIND
ARIND = 0
/ARIND = ARRAY-INDEX('AR', *UPPER-BOUND)
/SHOW-VARIABLE ARIND
ARIND = 2147483647