Control Break Programs, Version 2
July 28, 2004 Hey, Ted
Ken Orr taught me this one. Assuming an input file called SALES that contains the daily sales of all stores sorted by store number, department number, and, finally, sales person number. The file also contains item number and sales amounts.
This example shows where to print headers and footers of a report (excluding page headers and page footers), where to accumulate totals, and where to reset totals. The basic structure is a set of nested loops.
EVAL CompanyTotal = 0 EXCPT REPORTHEADER READ SALES DOW not %eof(SALES) EXCEPT STOREHDR EVAL StoreTotal = 0 EVAL oldStoreNum = StoreNum DOW not %eof(SALES) and oldStoreNum = StoreNum EXCEPT DEPTHDR EVAL DepartmentTotal = 0 EVAL oldDepartmentNum = DepartmentNum DOW not %eof(SALES) and oldStoreNum = StoreNum and oldDepartmentNum = DepartmentNum EXCEPT SPHDR EVAL SalesPersonTotal = 0 EVAL oldSalesPersonNum = SalesPersomNum DOW not %eof(SALES) and oldStoreNum = StoreNum and oldDepartmentNum = DepartmentNum and oldSalesPersonNum = SalesPersomNum EXCEPT DETAIL EVAL SalesPersonTotal = SalesPersonTotal + SaleAmount READ SALES ENDDO EXCEPT SPFOOTER EVAL DepartmentTotal = DepartmentTotal + SalesPersonTotal ENDDO EXCEPT DEPTFOOTER EVAL StoreTotal = StoreTotal + DepartmentTotal ENDDO EXCEPT STOREFOOTER EVAL CompanyTotal = CompanyTotal + StoreTotal ENDDO EXCEPT REPORTFOOTER
–Mike
The method you present is similar in philosophy to the one I presented, Mike, but it has been implemented with less code. I notice that control totals are reset before each group, as I like to do. The redundant tests on the do-while loops ensure that major breaks force minor breaks. I notice that your code doesn’t account for null values, but those tests could easily be added.
Thanks for sharing this example with other readers of Four Hundred Guru, Mike.
–Ted