Previous Page | Next Page

SCL Arrays

Declaring Arrays in SCL Programs

You can use the DECLARE statement to declare static or dynamic arrays. Arrays that are declared with the DECLARE statement are all temporary arrays. That is, they default to the _TEMPORARY_ option. (See Using Temporary Arrays to Conserve Memory in SCL Programs for more information.) For example, the following statement declares an array named MONTH that contains five character variables that are each up to three characters in length:

declare char(3) month[5];

To declare a dynamic array, you must specify an asterisk (*) for the array dimensions:

declare char students[*];

This statement declares a one-dimensional array of type character. The DECLARE statement does not set the array bounds or create any elements. Dynamic arrays are only accessible within the scope in which they are declared.

You can use the ARRAY statement to declare indirect or non-temporary arrays. You can declare only static arrays with the ARRAY statement. You can declare temporary arrays by specifying the _TEMPORARY argument in the ARRAY statement. For example:

array month[5] $;

The ARRAY statement (but not the DECLARE statement) enables you to assign names to individual array elements. For example, the following statement assigns the names JAN, FEB, MAR, APR, and MAY to the five elements in the MONTH array.:

array month[5] $ jan feb mar apr may;

You can use these names to refer to the array elements in your SCL program.

In contrast to the ARRAY statement, you cannot use the DECLARE statement to assign names to individual array elements. The following DECLARE statement declares an array named MONTH plus five more character variables named JAN, FEB, MAR, APR, and MAY:

declare char month[5] jan feb mar apr may;

Previous Page | Next Page | Top of Page