PreviousNextIndex

ACCUMULATE statement

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
aggregate-phrase
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 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. 

Note

You can use the ACCUMULATE statement only in blocks with the implicit looping property. ABL automatically supplies looping services to REPEAT and FOR EACH blocks. See OpenEdge Getting Started: ABL Essentials for more information on block properties.

See also

ACCUM function, Aggregate phrase


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex