ILE COBOL Programmer's Guide

Processing Multiple Table Items (ALL Subscript)

You might often need to process the data in tables iteratively. For intrinsic functions that accept multiple arguments, you can use the ALL subscript to reference all the items in the table or single dimension of the table. The iteration is handled automatically, making your code shorter and simpler.

Example 1:

This example sums a cross section of Table-Two:

Compute Table-Sum = FUNCTION SUM (Table-Two(ALL, 3, ALL)))
 

Assuming that Table2 is a 2x3x2 array, the above statement would cause these elements to be summed:

Table-Two(1,3,1)
Table-Two(1,3,2)
Table-Two(2,3,1)
Table-Two(2,3,2)
 

Example 2:

This example computes values for all employees.

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

Example 3:

Scalars and array arguments can be mixed for functions that accept multiple arguments:

Compute Table-Median = Function Median(Arg1 Table-One(ALL))


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]