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

Example 200 MEAN 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 MEAN (NUM(ALL)) TO A.
DISPLAY A.
MOVE FUNCTION MEAN (NUM(1) NUM(3) NUM(5)) TO A.
DISPLAY A.
MOVE FUNCTION MEAN (3.4 5 6.2 9) TO A.
DISPLAY A.
Output:
5.6
4.0
5.9
MEDIAN Function
MEDIAN, a numeric function, returns the value that would be the middle value in a list formed by
sorting its arguments numerically.
argument
is a numeric argument.
argument can be an array; for example,
FUNCTION MEDIAN (ARRAY1(ALL))
returns the median element of the array ARRAY1.
The returned value is the value that would be in the middle of the list if the arguments were sorted
numerically (according to the rules for comparing simple conditions). If there are an odd number
of arguments, at least half of them are less than or equal to the returned value, and at least half
of them are greater than or equal to the returned value. If there are an even number of arguments,
the returned value is the arithmetic mean of the two middle arguments. (For the definition of
arithmetic mean, see MEAN Function).
MEDIAN Function 675