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

    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

  • 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