size()
The sysLib.size() system function returns the number of rows in the specified data table or the number of elements in the specified array. The array can be a structure-field array or a dynamic array of variables or records.
If the array name (arrayName) is in a substructured element of another array, the returned value is the number of elements in the structure field itself, not the total number of occurrences in the containing structure (see the "Examples" section later in this topic).
Syntax
sysLib.size(arrayName ANY in)
returns (result INT)
- arrayName
- Name of the array or data table.
- result
- The number of rows in the specified data table or the number of elements in the specified array, as an INT.
Examples
This example uses the value returned by sysLib.size() to
control a loop:
// Calculate the sum of an array of numbers
sum = 0;
i = 1;
myArraySize = sysLib.size(myArray);
while (i <= myArraySize)
sum = myArray[i] + sum;
i = i + 1;
end
Next, consider the following Record definition:
Record ExampleRecord
10 siTop CHAR(40)[3];
20 siNext CHAR(20)[2];
end
Given that you create a record variable based on ExampleRecord, you can use sysLib.size(siNext) to determine the number of elements for the subordinate array:
// Sets count to 2
count = sysLib.size(myRecord.siTop.siNext);
Error conditions
If you call the function with an array that has an unspecified
number of elements, EGL throws a NullValueException, as in the following:
myArray INT[];
size(myArray);A validation error occurs if you reference a variable that is not an array or a data table.
Compatibility considerations
| Platform | Issue |
|---|---|
| JavaScript™ generation | The function sysLib.size() is not supported |