ARRAY

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

In SQL...END SQL statement, the variable that represents an array needs a dollar sign ($) preceding it. However no dollar sign is required for a variable used as a coordinate in an array.

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).

Individual Array Elements

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.

It is also possible to pass a record that contains an array or a dynamic array as its member as a single unit. However, make sure you avoid cyclic references of such records.

Sub-strings of array elements of a character data type

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.

Using static arrays

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:

join()

concatenates all the elements of an array into a string

getLength()

returns the length of a single-dimensional array

clear()

sets all the elements to their initial value

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.