ARRAY-ADD, ARRAY-DIVIDE, ARRAY-MULTIPLY, ARRAY‑SUBTRACT

Function

Performs arithmetic on array elements.

Syntax

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)]]...

Arguments

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.

Description

The following information applies to the array arithmetic commands:

Examples

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-program
  do Main
end-program
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
  print #sal   (+1, 1) money
  print #com   (,22) money
  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

See Also