The MEDIAN function returns the contents of the argument whose value is the middle value in the list formed by arranging the arguments in sorted order.
The type of this function is numeric.
Format
FUNCTION
MEDIAN
({argument-1}...)
Argument
argument-1 must be class "numeric".
Returned values
The returned value is the content of the argument having the middle value in the list formed by arranging all the argument values in sorted order.
If the number of occurrences referenced by argument is odd, the returned value is such that at least half of the occurrences referenced by argument are greater than or equal to the returned value and at least half are less than or equal. If the number of occurrences referenced by argument is even, the returned value is the arithmetic mean of the values referenced by the two middle occurrences.
The comparisons used to arrange the argument values in sorted order are made according to the rules for simple conditions (see section "Conditions").
The error default value is 0.
See also: MIN, MAX, RANGE, MEAN, MIDRANGE, SUM
Example 9-26
... DATA DIVISION. WORKING-STORAGE SECTION. 01 RES PIC 9(3). PROCEDURE DIVISION. P1 SECTION. MAIN. COMPUTE RES = FUNCTION MEDIAN (2 32 8 128 16 64 256). DISPLAY RES UPON T. STOP RUN.
Result: 032