OK, I like a challenge. So, here's the solution using the built-in aggregation functions of Progress.
First, some housekeeping: setting up the temp-table and filling it:
DEFINE TEMP-TABLE ttTest
FIELD ItemNo AS CHARACTER
FIELD Quantity AS INTEGER
INDEX ItemNo ItemNo.
RUN ipCreateTest("ItemA",100).
RUN ipCreateTest("ItemA",200).
RUN ipCreateTest("ItemC",300).
RUN ipCreateTest("ItemB",400).
RUN ipCreateTest("ItemA",500).
RUN ipCreateTest("ItemB",600).
PROCEDURE ipCreateTest:
DEFINE INPUT PARAMETER pcItem AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER piQty AS INTEGER NO-UNDO.
CREATE ttTest.
ASSIGN
ttTest.ItemNo = pcItem
ttTest.Quantity = piQty
.
END.
Then, the actual reporting part:
FOR EACH ttTest
NO-LOCK
BREAK BY ttTest.ItemNo:
ACCUMULATE ttTest.Quantity
(MINIMUM MAXIMUM AVERAGE TOTAL COUNT BY ttTest.Itemno).
IF LAST-OF(ttTest.itemNo) THEN DO:
DISPLAY
ttTest.ItemNo
ACCUM MINIMUM BY ttTest.ItemNo ttTest.Quantity
COLUMN-LABEL "Min1"
ACCUM MAXIMUM BY ttTest.ItemNo ttTest.Quantity
COLUMN-LABEL "Max1"
ACCUM AVERAGE BY ttTest.ItemNo ttTest.Quantity
COLUMN-LABEL "Avg1"
ACCUM TOTAL BY ttTest.ItemNo ttTest.Quantity
COLUMN-LABEL "Sum1"
ACCUM COUNT BY ttTest.ItemNo ttTest.Quantity
COLUMN-LABEL "Count1"
.
END.
END.
The built-in functions work, but the syntax is very counter-intuitive IMHO. I would go with Tim's solution, mainly because I probably would have finished the problem with that strategy in the time it took me to get to the second iteration with ACCUM and ACCUMULATE, figuring out where the brackets go... :)