You can declare an array of records or data items without specifying the number of elements, and in this case the number varies at run time as your code invokes system functions that append, insert, or delete elements or that remove the array. This dynamic array is useful for a variety of tasks but is not available in forms.
The syntax for declaring a dynamic array includes brackets with no size value, as in the following examples:
// an array of 5 items or less myDataItem01 CHAR(30)[] { maxSize=5 }; // an array of 6 items or less myDataItem02 myDataItemPart[] { maxSize=6 }; // an array of the maximum number of items // (the maximum depends on the generated language) myRecord myRecordPart[];
The rules for referencing the elements of a dynamic array are equivalent to the rules for referencing a static array. If your code refers to a dynamic array of records or data items and does not specify brackets or a subscript, the reference is to the array as a whole.
An out-of-memory situation is treated as a catastrophic error and ends the program.
A set of functions and read-only variables are available for each dynamic array. In the following descriptions, substitute the array name for arrayName and note that the name may be qualified by a package name, a library name, or both:
The elements of appendArray must be of the same type as the elements of arrayName.
The rules for assigning a literal are as specified in Assignments.
content is the new content (a constant or variable of the appropriate type for the array), and index is an integer literal or a numeric variable that indicates the location of the new element.
If index is one greater than the number of elements in the array, the function creates a new element at the end of the array and increments the array size by one.
index is an integer literal or a numeric variable that indicates the location of the element to be removed.
A dynamic array can be passed as an argument to an EGL function. The related parameter must be defined as a dynamic array of the same type as the argument; and for a data item, the type must include the same length and decimal places, if any.
A dynamic array cannot be passed as an argument to another program.
An example of a function that uses a dynamic array as a parameter is as follows:
Function getAll (employees Employee[]) ; end
At run time, the maximum size for a parameter is the maximum size declared for the corresponding argument. The function or called program can change the size of the array, and the change is in effect in the invoking code.
EGL lets you use a dynamic array to access rows of a relational database. For details on reading multiple rows, see get. For details on adding multiple rows, see add.
Related concepts
Compatibility with VisualAge Generator
References to variables and constants
Related reference
add
Assignments
EGL system limits
get
in
sysLib.size
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.