ARRAY is a structured data type that stores a one-, two-, or three-dimensional array of variables of identical data types. The size of each dimension is a positive integer of up to 32,767. Dimensions can be of different size and they can contain variables of any data type, provided that all the elements of the array are of the same data type.
Size |
The upper bounds for up to 3 dimensions. Can include from 1 to 3 4GL expressions separated by commas that return positive integers. |
4GL Data Type |
Any Querix 4GL or user-defined data type |
A variable included into an ARRAY is called an element. The example below declares a three-dimensional program array called my_array:
DEFINE my_array ARRAY[a,b,c] OF INTEGER
where
Here are several examples of an array declaration:
DEFINE array1 ARRAY[100,100,100] OF RECORD rec1 LIKE client.*
DEFINE array4 ARRAY[500] OF RECORD
variable1 LIKE client.fname,
variable2 INT
END RECORD
DEFINE array2 ARRAY[7,100] OF VARCHAR(20)
DEFINE array3 ARRAY[1000] OF my_rec
In this example my_rec is a user-defined type of record (created with the help of DEFINE...TYPE AS statement).
You cannot manipulate an array as a single unit; you can only operate its individual elements. A single element can be manipulated by specifying its coordinates next to the name of the array in which it is included. The number of coordinates an element requires depends on how many dimensions there are in the array. A coordinate must be specified for each dimension of a multi-dimensional array. If a coordinate for one or two dimensions is missing, though it is required, 4GL will produce a compile-time error.
You can operate an array as a unity, so it can be passed to and from a function. They are passed by reference.
A sub-string of an array is a list of character values within an individual element of an array of character type (CHAR, STRING or VARCHAR). You can use a pair of integer expressions between square bracket ([]) to specify a character sub-string within the string value of the array element. E.g. If my_array[d, e, f] is an element of a three-dimensional array of character data type, you can specify a sub-string within this element as follows: my_array[d, e, f] [m, n] where m and n specify the positions of the first and the last character (respectively) of the sub-string within the array element my_array[d, e, f]. The m and n should be positive integers, m should be smaller than n.
Querix4GL has a number of methods that can be used with variables of the ARRAY data type:
variable.Method()
These methods serve as auxiliary tools used to manage the static array effectively:
concatenates all the elements of an array into a string |
|
returns the length of a single-dimensional array |
|
sets all the elements to their initial value |