• 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
    OCEAN User Group

    OCEAN TechCon25 Online

    It’s an Exciting Time for IBM i !

    July 16 & 17, 2025 – ONLINE

    Two virtual days of learning, presented by an outstanding group of IBM’ers and IBM Champions, featuring leading-edge topics.

    FREE for OCEAN members!

    Register NOW!

    Annual (12-month) Individual OCEAN Memberships are $80 and a Corporate Membership is $250. A Corporate Membership would allow your entire company to have full access to the OCEAN website & video library and to attend OCEAN events at member rates. Act now because rates are increasing on August 1, 2025.

    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

Content archive

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

Recent Posts

  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26
  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25

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