# %MAX and %MIN (Maximum or Minimum Value)

``%MAX(item1 : item2 {: item3 { item4 ... } })``
``%MIN(item1 : item2 {: item3 { item4 ... } })``

%MAX returns the maximum value of its operands and %MIN returns the minimum value of its operands. Otherwise, the rules and behavior of these built-in functions are identical.

The operands must all have data types that are compatible for comparison with each other. For example, if one item in the list is alphanumeric, the other items can be alphanumeric, UCS-2, or graphic. If one item is packed numeric, the other items can be packed numeric, zoned numeric, integer, unsigned integer, binary decimal, or float.

Items with type procedure-pointer or type object are not allowed as operands.

There must be at least two operands. There is no practical upper limit for the number of operands.

When the built-in function is used in a Declaration statement, there must be exactly two operands; the operands must both be numeric and they cannot be float or hexadecimal.

If any decimal operand has more decimal positions than the result of the operation, half-adjust is used.

If the built-in function is used in a Declaration statement, the result is the operand with the higher (%MAX) or lower (%MIN) value.

The data type of the value returned by the built-in function in calculations depends on the data type of the operands. See Determining the Common Type of Multiple Operands.

To find the maximum or minimum value in an array, use %MAXARR or %MINARR.

## Examples of %MAX and %MIN

1. %MAX used in a Declaration statement. The dimension of arr3 is 5, the maximum of the dimension of arr1 and arr1.
``````
DCL-S arr1 CHAR(10) DIM(3);
DCL-S arr2 CHAR(10) DIM(5);
DCL-S arr3 CHAR(10) DIM(%MAX(%ELEM(arr1) : %ELEM(arr2)));
``````
2. %MIN used in a Calculation statement.
``````
DCL-S triangleArea PACKED(7 : 2);
DCL-S squareArea PACKED(7 : 2);
DCL-S circleArea PACKED(5 : 2);
DCL-S size PACKED(7 : 2);

size = %MIN (triangleArea : squareArea : circleArea);
``````