• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Sharing Simplifies Source Code

    May 11, 2011 Ted Holt

    I hate huge programs. For one thing, I’m not smart enough to wrap my mind around a big program. And it seems that modifying one part of the program invariably causes something to go amiss elsewhere. Dividing a program into subprocedures, modules, and multiple programs is a good way to manage large tasks. But what do you do when you’ve divided a program into two or more modules and/or programs, and more than one of them needs to contribute to a single report? You share.

    Suppose you have a program that builds a report of accounts receivable. It’s a manageable program. Then one day someone asks you to add a recap to the end of the report. Adding the recap adds complexity to the program. Here’s another way to tackle the challenge.

    First, here’s DDS for a printer file that defines the report:

    A          R PAGEHDR                   SKIPB(01) SPACEA(1)
    A                                     1'A R Summary Report'
    A                                   +10DATE EDTWRD('  -  -  ')
    A                                    +4TIME EDTWRD('  :  :  ')
    A                                    +8'Page'
    A                                    +1PAGNBR EDTCDE(4)
    A
    A          R DETAIL01                  SPACEB(1)
    A            NAME          12A        1
    A            STATE          2A       15
    A            BALDUE         9  2     18EDTCDE(J)
    A
    A          R RECAP01                   SPACEB(1)
    A            STATE          2A        1
    A            BALDUE         9  2     18EDTCDE(J)
    

    Here’s the first RPG program, AR101R, which prints the detail lines:

    H dftactgrp(*no) actgrp(*caller)
    
    Fqcustcdt  if   e             disk    usropn prefix('C_')
    Far100p    o    e             printer usropn prefix('P_')
    F                                     oflind(Overflow)
    F                                     ignore(Recap01)
    
    D Overflow        s               n
    
     /free
         open qcustcdt;
         open ar100p;
         write PageHdr;
    
         dow '1';
            read cusrec;
            if %eof();
               leave;
            endif;
            if Overflow;
               write PageHdr;
               Overflow = *off;
            endif;
            P_Name = %trim(C_lstnam) + ', ' + C_init;
            P_State = C_State;
            P_BalDue = C_BalDue;
            write Detail01;
         enddo;
    
         return;
    

    Here’s program AR102R, which prints the recap.

    H dftactgrp(*no) actgrp(*caller)
    
    Far100p    o    e             printer usropn prefix('P_')
    F                                     oflind(Overflow)
    F                                     ignore(Detail01)
    
    D Overflow        s               n
    
    D RecapData       ds                  qualified inz
    D  State                         2a
    D  BalDue                        9p 2
    
     /free
         exec sql
            declare Recap cursor for
               select c.state, sum(c.baldue)
                 from qcustcdt as c
                group by c.state
                order by c.state;
         exec sql
            open Recap;
         open ar100p;
         write PageHdr;
    
         dow '1';
            exec sql
               fetch Recap into :RecapData;
            if SqlState >= '02000';
               leave;
            endif;
            if Overflow;
               write PageHdr;
               Overflow = *off;
            endif;
            P_State = RecapData.State;
            P_BalDue = RecapData.BalDue;
            write Recap01;
         enddo;
    
         return;
    

    Here’s the CL procedure AR101C, which runs the show.

    pgm
    
    ovrprtf ar100p share(*yes)
    call    ar101r
    call    ar102r
    dltovr  ar100p
    
    endpgm
    

    And here’s the report, all nice and together in one spool file.

    A R Summary Report           5-11-11    13:42:51        Page    1
    
    Henning, G K  TX        37.00
    Jones, B D    NY       100.00
    Vine, S S     VT       439.00
    Johnson, J A  GA     3,987.50
    Tyron, W E    NY          .00
    Stevens, K L  CO        58.75
    Alison, J S   MN        10.00
    Doe, J W      CA       250.00
    Thomas, A N   WY          .00
    Williams, E   TX        25.00
    Lee, F L      NY       489.50
    Abraham, M T  MN       500.00
    
    A R Summary Report           5-11-11    13:42:51        Page    2
    
    CA                     250.00
    CO                      58.75
    GA                   3,987.50
    MN                     510.00
    NY                     589.50
    TX                      62.00
    VT                     439.00
    WY                        .00
    

    To make this happen, the two programs must share one open data path. The Override with Printer File (OVRPRTF) command in the CL procedure makes this happen.

    Second, the first RPG must not close the printer file. If the first program closes the printer file, the second RPG program opens another spool file. That’s why the first program doesn’t set on the LR indicator. (The second one doesn’t set on LR either, but it doesn’t matter.) To make the system clean up the active programs, I compiled the CL program to run in a *NEW activation group and the RPG programs to run in the caller’s activation group. When the job ends, the system cleans up everything nicely by destroying the activation group. This method is not the only possibility.

    I’ve illustrated sharing with two programs that run sequentially, but sharing also works when one program calls another.

    It is not necessary for all code that builds a report to reside in the same module. Dividing a big program into smaller, more manageable ones is feasible, even when more than one module has to help build a report.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    Lightedge

    Your IBM Power Cloud Strategy Should Start With “Why?”

    Moving IBM i to the cloud isn’t just an infrastructure decision.

    A hardware refresh, data center exit, IBM i skills gap, disaster recovery requirement, or broader cloud initiative can each lead to a very different architecture.

    At Lightedge, we start by understanding what you’re trying to accomplish. Then we look at the workload, application dependencies, resiliency requirements, operating model, and long-term strategy to determine where that workload belongs.

    Managed IBM Power cloud? IBM Power Virtual Server? DR in the cloud? A hybrid architecture connecting IBM Power with AWS or Azure?

    There isn’t one right answer for every IBM i environment.

    Start with the business requirement. Understand the workload. Then decide where it belongs.

    Explore IBM Power cloud, managed services, and hybrid solutions from Lightedge.

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Sponsored Links

    looksoftware:  FREE Webcast: RPG Open Access Demystified. June 7 (Europe) & June 8 (USA)
    RJS Software Systems:  Go paperless, automate business process and save money.
    Shield Advanced Solutions:  JobQGenie ~ the perfect companion for your high availability solution

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    Retrieve Column Descriptions in your ADO Client/Server Applications Admin Alert: Critical Information That Every i Administrator Should Have Handy

    Leave a ReplyCancel reply

Volume 11, Number 15 -- May 11, 2011
THIS ISSUE SPONSORED BY:

SEQUEL Software
ProData Computer Services
WorksRight Software

Table of Contents

  • Retrieve Column Descriptions in your ADO Client/Server Applications
  • Sharing Simplifies Source Code
  • Admin Alert: Critical Information That Every i Administrator Should Have Handy

Content archive

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

Recent Posts

  • IBM’s Bob AI Assistant Can Now Live In Your Datacenter
  • Start Where the Data Lives: Best Practices for Taking IBM i Into AI
  • Guru: A Modernization Experiment Using IBM Bob 2.0
  • How Are IBM i Shops Using AI? Fortra and COMMON Want to Know
  • IBM i PTF Guide, Volume 28, Number 34
  • It Is Time Once Again To Take The IBM i Marketplace Survey
  • PHP’s Evolution On The IBM i Platform Continues
  • Protecting IBM i Data For The AI Revolution
  • Guru: Two More Small But Handy RPG Enhancements: LIKE(*EXT) And %LOOKUPNE
  • IBM i Integration Gives Costco Shoppers Real-Time Inventory

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