Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


Adds the values of the elements of a dynamic array.




dynarray An expression that resolves to a dynamic array of numeric values.


The SUM function adds the values the elements in a dynamic array and returns the sum as a dynamic array. If an element is missing or has a null string or a non-numeric value, SUM parses its value as 0 (zero).

  • If all of the elements in dynarray are on the same dynamic array level, SUM returns a dynamic array consisting of a single value, the sum of the elements. This is shown in the following example, in which each SUM returns 34:

    PRINT SUM(a);    ! returns 34
    PRINT SUM(b);    ! returns 34
    PRINT SUM(c);    ! returns 34
    Copy code to clipboard
  • If elements in dynarray are on different dynamic array levels, SUM returns a dynamic array in which elements at the lowest array level are summed. Values at higher levels are returned as array elements. This is shown in the following example:

    PRINT SUM(a);    ! returns 30^8^7
    PRINT SUM(b);    ! returns 9^10^26
    Copy code to clipboard

The SUM function adds dynamic array values that are on the same dynamic array level. To add all values in a dynamic array, regardless of level, use the SUMMATION function. To add the elements of two dynamic arrays, use the ADDS function.

See Also