• 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 3

    August 11, 2004 Dear Readers

    Faithful reader Doug Eckersley sent me an example of how he would write a control break program like the one I presented in the May 12 issue. Doug mentions two things he likes about his method. First, it uses subroutines, which makes the program modular, and, second, he uses no hold fields. Here’s his code.

    D K1              C                   1
    D K2              C                   2
    D K3              C                   3
    D Key           E DS                  extname(SALES:*key)
    
         Begsr $Main;
    
           NewPage = *on;
           CompanyTotal = 0;
           Except REPORTHEADER;
           Setll *start SALES;
           Read SALES;  
                     
           Dow not %eof(SALES);    
              Exsr $Level1;    
              Read SALES;
           Enddo;
           
           Except REPORTFOOTER;
    
         Endsr;
         
         Begsr $Level1;
    
           // Store
           StoreTotal = 0;  
           Except STOREHDR;   
           
           Dow not %eof(SALES);
              Exsr $Level2;
              Reade %kds(Key:K1) SALES;
           Enddo; 
           
           Except STOREFOOTER;
           CompanyTotal += StoreTotal;
           Setgt %kds(Key:K1) SALES;
    
         Endsr;
         
         Begsr $Level2
    
            // Department  
            DepartmentTotal = 0;  
            Except DEPTHDR;
         
            Dow not %eof(SALES);
               Exsr $Level3;
               Reade %kds(Key:K2) SALES;
            Enddo; 
         
            Except DEPTFOOTER;
            StoreTotal += DepartmentTotal;
            Setgt %kds(Key:K2) SALES;
    
         Endsr; 
         
         Begsr $Level3;
    
            // SalesPerson  
            SalesPersonTotal = 0;
            Except SPHDR;
         
            Dow not %eof(SALES);
              Exsr $Detail;
              Reade %kds(Key:K3) SALES;
            Enddo;
         
            Except SPFOOTER;
            DepartmentTotal += SalesPersonTotal;
            Setgt %kds(Key:K3) SALES;
    
         Endsr;
         
         Begsr $Detail;
    
            Exsr $NewPage
            Except DETAIL;
            SalesPersonTotal += SaleAmount;
    
         Endsr;
         

    I’d like to add an observation or three. It’s true that Doug’s method doesn’t require hold fields, but it does require random I/O (that is, SETGT), which may hamper performance. The fact that Doug uses a keyed file means that he has to have an access path over the data, at least at compile time. Also, this method doesn’t work with embedded SQL.

    But I sound more critical than I mean to be. Both Doug and Mike (in the July 28 issue) have presented techniques that are well thought out, and I am grateful to have learned other ways to handle a common task.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Califon Systems Ships New Release of OS/400 Security Module Fast400 Founder Sues Big Blue

    Leave a Reply Cancel reply

Volume 4, Number 27 -- August 11, 2004
THIS ISSUE
SPONSORED BY:

T.L. Ashford
WorksRight Software
Damon Technologies

Table of Contents

  • Listing Spool Files
  • Optional Parameters and CL Procedures
  • Control Break Programs, Version 3

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