Progress
Language Reference


ACCUMULATE Statement

Interfaces
OS
SpeedScript
All
All
Yes

Calculates one or more aggregate values of an expression during the iterations of a block. Use the ACCUM function to access the result of this accumulation.

SYNTAX

ACCUMULATE  { expression ( aggregate-phrase ) } ... 

expression

An expression for which you want to calculate the aggregate value. The expression you use in the ACCUMULATE statement and the expression you use in the ACCUM function (when using the result of the ACCUMULATE statement) must be in exactly the same form. (For example, “A * B” and “B * A” are not in exactly the same form.)

aggregate-phrase

Identifies one or more values to calculate based on a change in expression or a break group. This is the syntax for aggregate-phrase. For more information, see the Aggregate Phrase reference entry.

SYNTAX
{   AVERAGE
  | COUNT
  | MAXIMUM
  | MINIMUM
  | TOTAL
  | SUB-AVERAGE
  | SUB-COUNT
  | SUB-MAXIMUM
  | SUB-MINIMUM
  | SUB-TOTAL
} ... [ BY break-group ] ... 

EXAMPLES

This procedure calculates and displays statistics for all customers, but does not show the detail for each customer.

r-acmlt.p
FOR EACH customer:
  ACCUMULATE credit-limit (AVERAGE COUNT MAXIMUM).
END.

DISPLAY "MAX-CREDIT STATISTICS FOR ALL CUSTOMERS:" SKIP(2)
        "AVERAGE =" (ACCUM AVERAGE credit-limit) SKIP(1)
        "MAXIMUM =" (ACCUM MAXIMUM credit-limit) SKIP(1)
        "NUMBER OF CUSTOMERS =" (ACCUM COUNT credit-limit) SKIP(1)
        WITH NO-LABELS. 

The following procedure lists each item with its inventory value and lists that value as a percentage of the total inventory value of all items. It sorts items by highest value.

r-acmlt2.p
FOR EACH item:
  ACCUMULATE on-hand * price (TOTAL).
END.

FOR EACH item BY on-hand * price DESCENDING:
  DISPLAY item-num on-hand price on-hand * price LABEL "Value"
          100 * (on-hand * price) / (ACCUM TOTAL on-hand * price)
          LABEL "Value %".
END. 

The following procedure displays all customers, sorted by salesrep and country within the list for each salesrep. The procedure calculates the balance for each customer, total balance for each country, and total balance for each salesrep.

r-acc.p
FOR EACH customer BREAK BY sales-rep BY country:
   ACCUMULATE balance (TOTAL BY sales-rep BY country).
   DISPLAY sales-rep WHEN FIRST-OF(sales-rep) country name balance.
   IF LAST-OF(country) THEN
      DISPLAY ACCUM TOTAL BY country balance
         COLUMN-LABEL "Country!Total".
   IF LAST-OF(sales-rep) THEN DO:
      DISPLAY sales-rep ACCUM TOTAL BY sales-rep
              balance COLUMN-LABEL "Sales-Rep!Total".
      DOWN 1.
   END.
END. 

NOTE

You can use the ACCUMULATE statement only in blocks with the implicit looping property. Progress automatically supplies looping services to REPEAT and FOR EACH blocks. See the Progress Programming Handbook for more information on block properties.

SEE ALSO

ACCUM Function, Aggregate Phrase


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095