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

Example 201 MEDIAN 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 A PICTURE S9V9.
PROCEDURE DIVISION.
MOVE FUNCTION MEDIAN (NUM(ALL)) TO A.
DISPLAY A.
MOVE FUNCTION MEDIAN (NUM(1) NUM(3) NUM(5)) TO A.
DISPLAY A.
MOVE FUNCTION MEDIAN (4 1 7 5 2 3 6) TO A.
DISPLAY A.
MOVE FUNCTION MEDIAN (4 1 6 5 2 3) TO A.
DISPLAY A.
Output:
5.0
4.0
4.0
3.5
MIDRANGE Function
MIDRANGE, a numeric function, returns the arithmetic mean (average) of its minimum and maximum
arguments.
argument
is a numeric argument.
argument can be an array; for example,
FUNCTION MIDRANGE (ARRAY1(ALL))
returns the arithmetic mean of the minimum and maximum elements of the array ARRAY1.
The returned value is the arithmetic mean (average) of the least argument and the greatest
argument (according to the rules for comparing simple conditions).
676 Intrinsic Functions