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

Example 202 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
MIN Function
MIN is a function that returns the value of its minimum argument. Its type depends on the type of
its arguments, as this table shows:
Function TypeArgument Type
AlphanumericAlphabetic
AlphanumericAlphanumeric
IntegerInteger
NumericNumeric (some can be integer)
argument
is an alphabetic, alphanumeric, integer, or numeric argument. If you specify more than one
argument, they must all be of the same class. Integer and numeric arguments can be mixed,
because integers are of the class numeric.
argument can be an array; for example,
FUNCTION MIN (ARRAY1(ALL))
returns the smallest element of the array ARRAY1.
The returned value is the argument with the least value (according to the rules for evaluating
simple conditions). If the function type is alphanumeric, the size of the returned value is the same
as that of the argument with the least value. If two arguments have the same least value, the value
of the leftmost argument is returned.
MIN Function 677