Determining the Common Type of Multiple Operands

For some built-in functions, such as %MAX, %MIN, and %LIST, the data type of the value returned by the built-in function depends on the data type of its operands.

  • If all the operands are hexadecimal literals, the result is alphanumeric with CCSID(*HEX). Otherwise, hexadecimal literals are treated as numeric or character depending on the other operands of the built-in function.
  • If all the operands have date type date, the result has data type date with format *ISO.
  • If all the operands have date type time, the result has data type time with format *ISO.
  • If all the operands have data type timestamp, the result has data type timestamp and the number of fractional digits of the returned value is the maximum number of fractional digits of any of the operands.
  • If all the operands have date type pointer, the result has data type pointer.
  • If all the operands have date type procedure pointer, the result has data type procedure pointer pointer.
  • If all the operands have data type Numeric, the following considerations are used to determine the format, length and number of decimal positions.
    • If any operand is float, the returned value is float with a length of 8.
    • Otherwise, if any operand is packed decimal, zoned decimal, or binary decimal, the returned value is packed decimal. The number of integer places is the maximum number of integer places of the operands. The number of decimal positions is the maximum number of decimal positions of the operands. If the number of integer places plus the number of decimal places exceeds 63, the number of decimal positions is reduced so that the total length is 63.
    • Otherwise, if any operand is integer and another operand is unsigned integer, then the returned value is packed decimal with a length of 20 digits and 0 decimal positions.
    • Otherwise, if any operand is integer, the returned value is integer with a length of 20.
    • Otherwise, the returned value is unsigned integer with a length of 20.
  • If all the operands have data type alphanumeric, UCS-2 or graphic, the following considerations are used to determine the data type, length and CCSID:
    • If any operand is alphanumeric with CCSID *UTF-8, the returned value is alphanumeric with CCSID *UTF-8.
    • Otherwise, if any operand is UCS-2, the returned value is UCS-2. If all the UCS-2 operands have the same CCSID, the returned value has that CCSID. Otherwise, the returned value has the default UCS-2 CCSID for the module.
    • Otherwise, if there is a mixture of alphanumeric and graphic operands, the returned value is UCS-2 with the default UCS-2 CCSID for the module.
    • Otherwise, if all the operands are graphic, and all the graphic operands have the same CCSID, the returned value is graphic with the same CCSID as the operands.
    • Otherwise, if all the operands are graphic but with different CCSIDs, the returned value is UCS-2 with the default UCS-2 CCSID for the module.
    • Otherwise, if all the operands are alphanumeric, and all the alphanumeric operands have the same CCSID, the returned value is alphanumeric with the same CCSID as the operands. The job CCSID and the mixed CCSID related to the job CCSID are considered to be the same for this determination. If at least one CCSID is the mixed CCSID related to the job CCSID, then the returned value has that CCSID.
    • Otherwise, if all the operands are alphanumeric but with different CCSIDs, the returned value is alphanumeric with CCSID *UTF-8. The length of the returned value is the maximum length of the operands, or if any CCSID conversions are required, the maximum possible length of the operands converted to the CCSID of the returned value. If this length exceeds the maximum length allowed, the length is reduced to the maximum length. If any alphanumeric or graphic operand has CCSID *HEX, all the operands must have the same data type, alphanumeric or graphic. The returned value has CCSID *HEX only if all the operands have CCSID *HEX.
      Warning: Comparisons in Unicode or ASCII differ from comparisons in EBCDIC. See Unexpected results when comparing data with different data types or CCSIDs.