HP 3000 Manuals

SUM Function [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

SUM Function 

The SUM function returns a value that is the sum of the parameters.  The
function type is either integer or numeric depending on the type of the
parameters, as follows:

     Parameter Type                         Function Type                                                                            
     All parameters integer                 Integer
     Numeric (some parameters may be        Numeric
integer)

Syntax 

     FUNCTION SUM ({parameter-1}...)

Parameters 

parameter-1           Must be class numeric.

Return Value 

The returned value is the sum of the parameters.

If the parameter-1 series are all integers, the value returned is an
integer.

If the parameter-1 series are not all integers, a numeric value is
returned.

Example 

     01  TAB.
         05  ELEMENT   PIC S999V99
                         OCCURS 4 TIMES VALUE ZERO.
     01  TOTAL         PIC S999V99 VALUE ZERO.
          :
     MOVE 1.25 TO ELEMENT (1).
     MOVE 3.50 TO ELEMENT (2).
     MOVE 8.75 TO ELEMENT (3).
     MOVE 0.25 TO ELEMENT (4).

     COMPUTE TOTAL = FUNCTION SUM (1, 7, 9, 23, 85).
     DISPLAY TOTAL.
     COMPUTE TOTAL = FUNCTION SUM ( ELEMENT (ALL) ).
     DISPLAY TOTAL.

The above example displays the following:

     +125.00
     +013.75



MPE/iX 5.0 Documentation