DEFINE ... ARRAY

An array defines a vector variable with a list of elements.

Syntax 1: Static array definition

DEFINE variable ARRAY [ size [,size  [,size] ] ]
    [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ]
    OF datatype

Syntax 2: Dynamic array definition

DEFINE variable DYNAMIC ARRAY
    [ ATTRIBUTES( attribute [ = "value" ] [,...] ) ]
    [ WITH DIMENSION rank ]
    OF datatype

Syntax 3: Java™ array definition

DEFINE variable ARRAY [ ] OF javatype
  1. variable defines the name of the array.
  2. size can be an integer literal or an integer constant. The upper limit is 65535.
  3. rank an be an integer literal of 1, 2, or 3. Default is 1.
  4. datatype can be a data type, a record definition, a user defined type, a built-in class, an imported package class, or a Java class.
  5. javatype must be a Java class or a simple data type that has a corresponding primitive type in Java, such as INTEGER (int), FLOAT (double).
  6. attribute is an attribute to extend the array definition with properties.
  7. value is the value for the array definition attribute, it is optional for boolean attributes.

Usage

The DEFINE ... ARRAY instruction creates a program variable as an array. The elements of the array can be of a simple type or structured records.

Consider using dynamic arrays instead of static arrays.

Java-style arrays will only be useful to interface with Java calls.

Static and dynamic arrays can be defined with the ATTRIBUTES() clause, to specify meta-data information for the variable. This feature is especially used when defining variables for XML-based Web Services. For more details about XML attributes, see Attributes to customize XML serialization.

Example

DEFINE arr DYNAMIC ARRAY OF RECORD
           p_num INTEGER,
           p_name VARCHAR(50),
           p_phone VARCHAR(20)
       END RECORD
LET arr[1].p_num = 84335
LET arr[1].p_name = "Scott McCallum"
LET arr[1].p_phone = NULL
DISPLAU arr[1].*