• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • No More Global Variables!

    June 24, 2009 Ted Holt

    Last December, I shared four ways to avoid problems caused by the use of global data in RPG programs. I mentioned that a discussion of i 6.1 (or as I call it, V6R1) data-localization features would have to wait for another day. Well, that day is here.

    With V6R1, it is possible to write programs that have no global identifiers. (By identifiers, I mean variables and constants. By variables, I not only mean scalar variables, but also arrays and data structures.) You only need to change two programming practices.

    First, lose the RPG cycle. It breaks my heart to think of RPG without a cycle. I learned RPG on a S/3 Model 12, did my first production work on the S/34, and later worked on the S/36. I prided myself on my understanding of the RPG cycle. But frankly, I have used so little of the cycle over the past 20 years or so, that getting rid of the rest of it is no big deal.

    To create an RPG program that has no embedded cycle logic, use the MAIN keyword in the H specs. MAIN requires one argument–the name of the controlling subprocedure.

    H Main(AR100)
    H dftactgrp(*no) actgrp(*caller)
    H option(*srcstmt: *nodebugio)
    
    D AR100           pr                  extpgm('AR100')
    D   From                         4a   const
    D   To                           4a   const
    
    P AR100           b 
    D                 pi
    D   From                         4a   const
    D   To                           4a   const
    
      ... etc. ...
    
    P                 e
    
    

    In this example, there is no RPG cycle–no detail calcs, no total calcs, no check for page overflow, no check for control breaks, no matching records, none of that stuff. When this program loads, subprocedure AR100 gets control and runs.

    The second thing you must do to avoid global data is to put file declarations inside of subprocedures.

    P GetCustName     b 
    
    FCustMasterif   e           k disk    usropn
    
    D                 pi
    D   Company                      3p 0 const
    D   Customer                     9p 0 const
    
      ... etc. ...
    
    P                 e
    

    In this example, the customer master file is declared within subprocedure “GetCustName,” and is not directly accessible from other subprocedures. There’s a good bit more to say about the use of files within subprocedures. That will have to wait until yet another day.

    Your program source code consists of H specs, D specs for prototypes and record-format templates, and subprocedures. Subprocedures contain P specs, F specs, D specs, and C specs. The end result is a program with no global identifiers.

    RELATED STORY

    Four Ways to Avoid Problems Caused by Global Data



                         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

    New Generation Software:  FREE Query Migration Planning Webinar, June 25, 2 p.m. EST
    Tri-Delta Resources:  Free 90 Night Disaster Recovery Service For Your IBM i
    looksoftware:  Why Service-Enable? View the On-Demand Webinar

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    Rational and Happy: IBM Wins Evans’ Development Tool Survey Again Midrange Shops Shift Priorities This Year

    Leave a Reply Cancel reply

Volume 9, Number 21 -- June 24, 2009
THIS ISSUE SPONSORED BY:

Help/Systems
Profound Logic Software
CNX

Table of Contents

  • V6R1 Run SQL Scripts: Print and Save Result Sets
  • No More Global Variables!
  • Reader Input: /QOpenSys Redux, PC5250 Popup Keypads, and Even Farther Beyond Replication

Content archive

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

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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