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

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • 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

    Insurance Company Taps CoSentry for Co-Location Services Q&A With Power Systems Top Brass, Part Two

    Leave a Reply Cancel 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

  • The Turning Point For Power Systems Is Here, And Now
  • How IBM i Users Can Compete In The Digital Era With Composable Commerce
  • IBM Streamlines Data Migration With New Partition Mirror Tech
  • Profound Logic Adds MCP To IBM i AI Tool
  • IBM i PTF Guide, Volume 27, Number 29
  • Power11 Entry Machines: The Power S1124 And Power L1124
  • BRMS Isn’t The Only Backup Product With A Security Problem
  • Guru: A Faster Way To Sign A JWT
  • Maxis Adds IBM i Support To Database Modernization Tool
  • IBM i PTF Guide, Volume 27, Number 28

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