Performs arithmetic on array elements.
ARRAY-ADD{src_num_lit|_var|_col}...TO dst_array_name (element_lit|_var|_col)[field [(occurs_lit|_var|_col)]]... ARRAY-DIVIDE{src_num_lit|_var|_col}...INTO dst_array_name (element_int_lit|_var|_col)[field [(occurs_lit|_var|_col)]]... ARRAY-MULTIPLY{src_num_lit|_var|_col}...TIMES dst_array_name (element_int_lit|_var|_col)[field [(occurs_lit|_var|_col)]]... ARRAY-SUBTRACT{src_num_lit|_var|_col}...FROM dst_array_name (element_int_lit|_var|_col)[field [(occurs_lit|_var|_col)]]...
src_num_lit|_var|_col
Source value(s) are added, divided, multiplied, or subtracted from the respective destination array fields. All variables must be numeric.
dst_array_name (element_int_lit|_var|_col)[field [(occurs_lit|_var|_col)]]
Destination array field(s) contain the results after the operation. All variables must be numeric.
The following information applies to the array arithmetic commands:
The array must be created with CREATE-ARRAY.
Array arithmetic commands perform on one or more source numbers and place the result into the corresponding array field.
Array element and field occurrence numbers can be numeric literals (123) or numeric variables (#j) and can be from zero (0) to one less than the size of the array.
If fields are not listed, the results are placed into consecutively defined fields in the array. If fields are listed, results are placed into those fields, at the specified occurrence of the field. If an occurrence is not specified the zeroth (0) occurrence is used.
All fields must be of the type NUMBER, DECIMAL, FLOAT, or INTEGER. They cannot be of type DATE, CHAR, or TEXT.
If division by zero is attempted, a warning message is displayed, the result field is unchanged, and Production Reporting continues executing.
array-add &salary #comm to emps(#j)
Adds &salary and #comm to the first two fields defined in the emps array. The #j'th element of the array is used.
array-subtract #lost #count 1 from stats(#j2) loses tot sequence
Subtracts #lost, #count, and 1 from the fields loses, tot and sequence of the #j2'th element of the stats array.
array-multiply 2 2 2 times percentages(#i) p(0) p(1) p(2)
Multiplies occurrences 0 through 2 of the field p in the #i'th element of the percentages array by 2.
array-divide 100 into commissions(#j) salesman(#i2)
Divides the #i2'th occurrence of the salesman field of the #j'th element of the commissions array by 100.
The following example uses ARRAY-ADD in an Production Reporting program.
begin-setup ! declare arrays create-array name=emps size=1 ! one row needed for this example field=Salary:number=35000 ! initialize to 35,000 field=Comm:number=5000 ! initialize to 5,000 end-setup
begin-procedure Main local ! Show original contents of the arrays, then the modified arrays ! array-add ! retrieve values from the only row of array "emps" get #sal #com FROM emps(0) Salary Comm print 'Array-Add' (+1, 1)
print 'Add 1000 to each column' (+1, 1) print 'Salary' (+1, 3) bold underline print 'Comm' (,25) bold underline
let #salary = 1000 let #commission = 1000 let #j = 0 ! address the array row with variable "#j" ! Add 1000 (in variables) to each column of row 0 (the 1st and only row) array-add #salary #commission TO emps(#j) ! retrieved the new "added" values get #sal #com FROM emps(0) Salary Comm print #sal (+1,1) money print #com (,22) money end-procedure
CREATE-ARRAY for information on creating an array.
CLEAR-ARRAY for information on clearing or initializing an array.