Finding the largest or smallest data item
To determine which of two or
more alphanumeric, alphabetic,
or national data items has the largest value, use the MAX
or ORD-MAX
intrinsic
function. To determine which item has the smallest value, use MIN
or ORD-MIN
.
These functions evaluate according to the collating sequence.
To compare numeric items, including those
that have USAGE NATIONAL
, you can use MAX
, ORD-MAX
, MIN
,
or ORD-MIN
. With these intrinsic functions,
the algebraic values of the arguments are compared.
The MAX
and MIN
functions
return the content of one of the arguments that you supply. For example,
suppose that your program has the following data definitions:
05 Arg1 Pic x(10) Value "THOMASSON ".
05 Arg2 Pic x(10) Value "THOMAS ".
05 Arg3 Pic x(10) Value "VALLEJO ".
The following statement assigns VALLEJObbb
to the first 10 character
positions of Customer-record
, where b
represents a blank
space:
Move Function Max(Arg1 Arg2 Arg3) To Customer-record(1:10)
If you used MIN
instead, then THOMASbbbb
would
be assigned.
The functions ORD-MAX
and ORD-MIN
return
an integer that represents the ordinal position (counting from the
left) of the argument that has the largest or smallest value in the
list of arguments that you supply. If you used the ORD-MAX
function
in the previous example, the compiler would issue an error message
because the reference to a numeric function is not in a valid place. Using the same arguments as in the previous example, ORD-MAX
can
be used as follows:
Compute x = Function Ord-max(Arg1 Arg2 Arg3)
The statement above assigns the integer 3 to x
if
the same arguments are used as in the previous example. If you used ORD-MIN
instead,
the integer 2 would be returned. The examples above might be more
realistic if Arg1
, Arg2
, and Arg3
were
successive elements of an array (table).
If you specify a national item for any argument, you must specify all arguments as class national.
Performing arithmetic
Processing table items using intrinsic functions
Returning variable results with alphanumeric or national functions