Dimension Statement

Defines the dimensions of one or more arrays. Not available in expressions.

Syntax

Dimension matrix (rows, columns) [ ,matrix (rows, columns) ] ...
Dimension vector (max) [ , vector (max) ] ...

matrix is a two-dimensional array to be dimensioned.

rows is the maximum number of rows in the array.

columns is the maximum number of columns in the array.

vector is a one-dimensional array to be dimensioned.

max is the maximum number of elements in the array.

Remarks

Arrays can be redimensioned at run time. You can change an array from one-dimensional to two-dimensional and vice versa.

The values of array elements are affected by redimensioning as follows:

  • Common elements with the same row/column address in both arrays are preserved.
  • New elements that had no row/column address in the original array are initialized as unassigned.
  • Redundant elements that can no longer be referenced in the new array are lost, and the memory space is returned to the operating system.

If there is not enough memory for the array, the Dimension statement fails and a following InMat function returns 1.

To assign values to the elements of the array, use the Mat statement and assignment statements.

Example

This example illustrates how a matrix can be dimensioned dynamically at run time based on incoming argument values:

Subroutine MyRoutine(InputArg, ErrorCode)
   ErrorCode = 0
* InputArg is 2 comma-separated fields, being the dimensions.
   Rows = Field(InputArg, ",", 1)
   Cols = Field(InputArg ",", 2)
   Dimension MyMatrix(Rows, Cols)
   If InMat = 1 Then
   * Failed to get space for matrix - exit with error status.
      Call DSLogWarn("Could not dimension matrix","MyRoutine")
      ErrorCode = -1
   Else
   * Carry on.
      ...
   End