Professional Documents
Culture Documents
An Array, like a database record, is organized as rows and columns. But unlike a
database record, Arrays exists only in memory and NOT in the disk. One of the advantages that Arrays
provide is that, once the data is populated into the array, it can be presented in multiple ways without
further trips to the database there by making processing faster.
The above code creates an array in SQR named contracts which has two fields which are contract_num
and contract_val. Once the array is created, all numeric fields are defaulted to zero and everything else is
set to NULL. So contract_num will have a value of NULL and contract_val will have zero.
Arrays are created at compile time. It is necessary that you provide the size of the array during this time. If
you are not sure of how much data the array would need to hold, you have no option but to over allocate
the size of the array so that the SQR program doesnt fail.
Line one and two does the same task of assigning the value 100000 to the contract_num field on the
zeroth row of the array. Line 3 assigns the values 100001 to contact_num and 150000 to contract_val on
the first row of the array contracts.
The first two lines does the same task of copying the value of contract_num in the zeroth row to the
$con_num variable. The third line copies the value of contract_num into $con_num and that of
contract_val into con_val.
Arithmetic Operations
The below arithmetic operations can be performed on arrays when all the variables are declared prior of
these statements.
ARRAY-ADD
ARRAY-SUBTRACT
ARRAY-MULTIPLY
ARRAY-DIVIDE
Best Practices
These are some of the best practices are observed while using arrays in SQR.
1. Use #Define to set the size of the array. This way, understanding the size of the array would be easy
and meaningful
#DEFINE MAX_CONTRACTS 100
CREATE-ARRAY name = contracts size={MAX_CONTRACTS}
FIELD = contract_num:CHAR
FIELD = contract_val:NUMBER
2. Reinitializing the array after use. This can be done by using the Clear-Array command
CLEAR-ARRAY NAME = contracts