COBOL Manual for TNS and TNS/R Programs

Intrinsic Functions
HP COBOL Manual for TNS and TNS/R Programs522555-006
14-34
MIDRANGE Function
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).
Example 14-24. MIDRANGE 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 MIDRANGE (NUM(ALL)) TO A.
DISPLAY A.
MOVE FUNCTION MIDRANGE (NUM(1) NUM(3) NUM(5)) TO A.
DISPLAY A.
MOVE FUNCTION MIDRANGE (8 1 3 6) TO A.
DISPLAY A.
Output:
6.0
4.0
4.5
( )
MIDRANGEFUNCTION argument
VST442.vsd