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
{ AVERAGE | COUNT | MAXIMUM | MINIMUM | TOTAL | SUB-AVERAGE | SUB-COUNT | SUB-MAXIMUM | SUB-MINIMUM | SUB-TOTAL }... [ BY break-group]... |
For more information, see the Aggregate phrase reference entry.
This procedure calculates and displays statistics for all customers, but does not show the detail for each customer.
r-acmlt.p
FOR EACH Customer NO-LOCK: ACCUMULATE Customer.CreditLimit (AVERAGE COUNT MAXIMUM).END. DISPLAY "MAX-CREDIT STATISTICS FOR ALL CUSTOMERS:" SKIP(2) "AVERAGE =" (ACCUM AVERAGE Customer.CreditLimit) SKIP(1) "MAXIMUM =" (ACCUM MAXIMUM Customer.CreditLimit) SKIP(1) "NUMBER OF CUSTOMERS =" (ACCUM COUNT Customer.CreditLimit) 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 NO-LOCK: ACCUMULATE Item.OnHand * Item.Price (TOTAL). END. FOR EACH Item NO-LOCK BY Item.OnHand * Item.Price DESCENDING: DISPLAY Item.ItemNum Item.OnHand Item.Price Item.OnHand * Item.Price LABEL "Value" 100 * (Item.OnHand * Item.Price) / (ACCUM TOTAL Item.OnHand * Item.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 NO-LOCK BREAK BY Customer.SalesRep BY Customer.Country: ACCUMULATE Customer.Balance (TOTAL BY Customer.SalesRep BY Customer.Country). DISPLAY Customer.SalesRep WHEN FIRST-OF(Customer.SalesRrep) Customer.Country Customer.Name Customer.Balance. IF LAST-OF(Customer.Country) THEN DISPLAY ACCUM TOTAL BY Customer.Country Customer.Balance COLUMN-LABEL "Country!Total". IF LAST-OF(Customer.SalesRep) THEN DO: DISPLAY Customer.SalesRep ACCUM TOTAL BY Customer.SalesRep Customer.Balance COLUMN-LABEL "SalesRep!Total". DOWN 1. END. END. |