• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • 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



    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Mrc Christens New Java Development Tool: M-Power There’s a New iSeries General Manager in Town

    Leave a Reply Cancel reply

Volume 4, Number 25 -- July 28, 2004
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
WorksRight Software
Guild Companies

Table of Contents

  • Backup and Recovery Just Got Easier with BRMS V5R3
  • Control Break Programs, Version 2
  • Auditing Users with All-Object Authority

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle