Previous Next

Aggregate phrase
Identifies one or more values to calculate based on a change in an expression or a break group.
Syntax 
 
{   AVERAGE
  | COUNT
  | MAXIMUM
  | MINIMUM
  | TOTAL
  | SUB-AVERAGE
  | SUB-COUNT
  | SUB-MAXIMUM
  | SUB-MINIMUM
  | SUB-TOTAL
} ... [ LABEL aggr-label ] [ BY break-group ] ...
AVERAGE
Calculates the average of all of the values of the expression in a break group and the average of all of the values of the expression in all break groups.
COUNT
Calculates the number of times the expression was counted in a break group and the count of all the values in all break groups.
MAXIMUM
Calculates the maximum of all of the values of the expression in a break group and the maximum of all the values of the expression in all break groups.
MINIMUM
Calculates the minimum of all of the values of the expression in a break group and the minimum of all the values of the expression in all break groups.
TOTAL
Calculates the subtotal of all of the values of the expression in a break group and the grand total of all of the values of the expression in all break groups. When you use default aggregates, the actual display of the grand total is deferred until the frame goes out of scope.
SUB-AVERAGE
Averages values in a break group. Does not supply an average for all records, just for those in each break group.
SUB-COUNT
Counts the number of times an expression is in a break group. Does not supply a count for all records, just for those in each break group.
SUB-MAXIMUM
Shows the maximum value of an expression in a break group. Does not supply a maximum value for all records, just for those in each break group.
SUB-MINIMUM
Shows the minimum value of an expression in a break group. Does not supply a minimum value for all records, just for those in each break group.
SUB-TOTAL
Subtotals all of the values of the expression in a break group. Does not supply a total value for all records, just for those in each break group.
BY break-group
Performs aggregation for break groups if you use the BREAK option in a FOR EACH block header.
LABEL aggr-label
Specifies a label for the aggregate value. aggr-label is a standard ABL string and can use a string attribute. The string can be translated by Translation Manager II. You can specify a maximum length attribute that is greater than the length of the longest label translation.
Examples 
This procedure lists the customer information for all customers (categorized by country) and a subtotal of each country’s balance. If you use TOTAL instead of SUB-TOTAL, the AVM displays a grand total.
 
FOR EACH Customer NO-LOCK BREAK BY Customer.Country:
  DISPLAY Customer.Name Customer.Country Customer.Balance 
    (SUB-TOTAL BY Customer.country).
END.
In the following procedure, the AVM displays the result of the COUNT aggregate even though no accumulation has occurred. In this example, COUNT displays as 0.
 
DEFINE VARIABLE prntr AS LOGICAL NO-UNDO.
 
FOR EACH Item NO-LOCK:
  IF prntr THEN
    DISPLAY Item.ItemName Item.Price(COUNT) WITH FRAME pr.
END.
In the following procedure, the AVM uses “Avg. Credit Limit” and “Max. Credit Limit” as the labels for the AVERAGE and MAXIMUM aggregates respectively.
 
FOR EACH Customer NO-LOCK:
  DISPLAY Customer.Name Customer.CreditLimit
    (AVERAGE LABEL "Avg. Credit Limit"
     MAXIMUM LABEL "Max. Credit Limit" 
     TOTAL) WITH FRAME frame1 12 DOWN.
 END.
Notes 
*
*
*
*
*
You can build your own algorithms to generate aggregates for break groups in situations that do not adhere to these guidelines. For example, you can use variables to store aggregate values for use in expressions that generate the appropriate aggregate values for break groups across blocks in a procedure.
See also 
ACCUMULATE statement, FOR statement

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.