COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

Example 199 MAX Function
Code:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUMERIC-ARRAY.
05 PICTURE 9(1) VALUE 4.
05 PICTURE 9(1) VALUE 9.
05 PICTURE 9(1) VALUE 3.
05 PICTURE 9(1) VALUE 7.
05 PICTURE 9(1) VALUE 5
01 NUM-ARRAY REDEFINES NUMERIC-ARRAY.
05 NUM OCCURS 5 TIMES PICTURE 9(1).
01 ALPHABETIC-ARRAY.
05 PICTURE X(5) VALUE "dog".
05 PICTURE X(5) VALUE "cat".
05 PICTURE X(5) VALUE "horse".
05 PICTURE X(5) VALUE "sheep".
05 PICTURE X(5) VALUE "goat".
01 ALPHA-ARRAY REDEFINES ALPHABETIC-ARRAY.
05 ALPHA OCCURS 5 TIMES PICTURE X(5).
PROCEDURE DIVISION.
...
DISPLAY FUNCTION MAX (NUM(ALL))
DISPLAY FUNCTION MAX (ALPHA(ALL))
DISPLAY FUNCTION MAX (NUM(1) NUM(4))
DISPLAY FUNCTION MAX (ALPHA(3) "bird" "fish")
DISPLAY FUNCTION MAX (3.4 5 6.2 9)
Output:
9
sheep
7
horse
9.0
MEAN Function
MEAN, a numeric function, returns the arithmetic mean (average) of its arguments.
argument
is a numeric argument.
argument can be an array; for example,
FUNCTION MEAN (ARRAY1(ALL))
returns the arithmetic mean of the elements of the array ARRAY1.
The returned value is the arithmetic mean (average) of the argument series; that is
where n is the number of arguments.
674 Intrinsic Functions