ABS

The ABS function returns the absolute value of a number.

Read syntax diagramSkip visual syntax diagram
>>-ABS--(--expression--)---------------------------------------><

expression
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. A string argument is cast to double-precision floating point before evaluating the function. For more information about converting strings to double-precision floating point, see DOUBLE_PRECISION or DOUBLE.

If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Note

Start of changeResults involving DECFLOAT special values: For decimal floating-point values, the special values are treated as follows:
  • ABS(NaN) and ABS(-NaN) return NaN.
  • ABS(Infinity) and ABS(-Infinity) return Infinity.
  • ABS(sNaN) and ABS(-sNaN) return sNaN.
End of change

Syntax alternatives: ABSVAL is a synonym for ABS. It is supported only for compatibility with previous DB2® releases.

Example

  • Assume the host variable PROFIT is a large integer with a value of -50000.
       SELECT ABS(:PROFIT)
         FROM SYSIBM.SYSDUMMY1
    Returns the value 50000.