Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

MAX - Value of maximum argument

The MAX function returns the content of the argument that contains the maximum value.
The type of this function depends upon the argument types as follows:

Argument type

Function type

alphabetic
alphanumeric
all arguments integer
index
national
numeric
numeric/integer

alphanumeric
alphanumeric
integer
index
national
numeric
numeric

Format


FUNCTION MAX ({argument-1}...)


Arguments

  1. If more than one argument is specified, all arguments must be of the same class.

  2. The individual arguments must not be specified in the ANY LENGTH clause.

Returned values

  1. The returned value is the content of the argument having the greatest value. The comparisons used to determine the greatest value are made according to the rules for simple conditions.

  2. If more than one argument has the same greatest value, the content of the argument returned is the leftmost argument having that value.

  3. If the type of the function is alphanumeric or national, the size of the returned value is the same as the size of the selected argument.

  4. The error default value is 0.


See also:
        MIN, ORD-MAX, ORD-MIN, RANGE, MEAN, MEDIAN, MIDRANGE, SUM 

Example 9-24

...
DATA DIVISION.
WORKING-STORAGE SECTION.
01  RES PIC 9(3).
01  RES1 PIC X(4).
PROCEDURE DIVISION.
P1 SECTION.
MAIN.
    COMPUTE RES = FUNCTION MAX (12 32 5 8 17 9).
    MOVE FUNCTION MAX ("HUGO" "EGON" "THEO" "OTTO") TO RES1.
    DISPLAY "Argument with greatest value: " RES UPON T.
    DISPLAY "Argument with greatest value: " RES1 UPON T.
    STOP RUN. 

Result:               Argument with greatest value RES: 032
                          Argument with greatest value RES1: THEO