Example: processing tables using intrinsic functions
These examples show how you can apply an intrinsic function
to some or all of the elements in a table by using the ALL
subscript.
Assuming
that Table-Two
is a 2 x 3 x 2 array, the following
statement adds the values in elements Table-Two(1,3,1)
, Table-Two(1,3,2)
, Table-Two(2,3,1)
,
and Table-Two(2,3,2)
:
Compute Table-Sum = FUNCTION SUM (Table-Two(ALL, 3, ALL))
The
following example computes various salary values for all the employees
whose salaries are encoded in Employee-Table
:
01 Employee-Table.
05 Emp-Count Pic s9(4) usage binary.
05 Emp-Record Occurs 1 to 500 times
depending on Emp-Count.
10 Emp-Name Pic x(20).
10 Emp-Idme Pic 9(9).
10 Emp-Salary Pic 9(7)v99.
. . .
Procedure Division.
Compute Max-Salary = Function Max(Emp-Salary(ALL))
Compute I = Function Ord-Max(Emp-Salary(ALL))
Compute Avg-Salary = Function Mean(Emp-Salary(ALL))
Compute Salary-Range = Function Range(Emp-Salary(ALL))
Compute Total-Payroll = Function Sum(Emp-Salary(ALL))