CREATE-ARRAY
Syntax
CREATE-ARRAY NAME=array_name SIZE=nn {FIELD=name:type[:occurs] [={init_value_txt_lit|_num_lit}]}...
Description
Creates an array of fields to store and process data.
You can define arrays to store intermediate results or data retrieved from the database. For example, a SELECT paragraph can retrieve data, store it in an array, and gather statistics at the same time. When the query finishes, a summary could be printed followed by the data previously stored in the array.
SQR creates arrays before a program starts to run. The CREATE-ARRAY command can be used in any section of a program.
Commands to process arrays include:
CREATE-ARRAY
CLEAR-ARRAY
GET
PUT
ARRAY-ADD
ARRAY-SUBTRACT
ARRAY-MULTIPLY
ARRAY-DIVIDE
LET
The maximum number of arrays in a program is 128; the maximum number of fields per array is 200.
The following code is a representation of an array emps with three fields in which the CREATE-ARRAY command defines the array:
create-array name=emps size=10
field=name:char='Unknown'
field=rate:number:2=10.50
field=phone:char='None'
The name is a simple field (one occurrence), rate has two occurrences, and phone is a simple field. Both array elements and field occurrences are referenced beginning with 0 (zero). The rate is referenced by rate(0) or rate(1). The emps array will contain 10 elements, 0 through 9. All name fields are initialized to Unknown, all phone fields are initialized to None, and all rate fields are initialized to 10.50.
Parameters
| Parameter | Description |
|---|---|
|
NAME |
Names the array. The name is referenced in other array commands. |
|
SIZE |
Defines the number of elements in the array. |
|
FIELD |
Defines each field or column in the array. Each field must be defined as type: DECIMAL[(p)]: Decimal numbers with an optional precision (p). FLOAT: Double precision floating point numbers. INTEGER: Whole numbers. NUMBER: Uses the DEFAULT-NUMERIC type. See the DECLARE-VARIABLE command. CHAR (or TEXT): Character string. DATE: Same as date variable. You can specify an initialization value for each field. Each field is set to this value when the array is created and when the CLEAR-ARRAY command is carried out. If no initialization value is specified, numeric fields (DECIMAL, FLOAT, INTEGER) are set to zero, character fields are set to null, and date fields are set to null. All occurrences of a multiple occurring field are set to the same value. For dates, the initialization string must be formatted as 'SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]'. |
|
OCCURS |
Fields can optionally have a number of occurrences (occurs); that is, they can be repeated any number of times. |
Example
The following example illustrates the CREATE-ARRAY command:
create-array name=custs size=100
field=name:char
field=no:number
field=state:char
field=zip:char
field=contacts:char:5
field=last-contacted:date
See The sample report CUSTOMR4.SQR
included with SQR
See DECLARE-VARIABLE, ARRAY-ADD, ARRAY-DIVIDE, ARRAY-MULTIPLY , ARRAY-SUBTRACT, GET , PUT , LET , CLEAR-ARRAY
See The LOAD-LOOKUP command
for an alternative way to store database tables in memory