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

    • 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
    New Generation Software

    Put your IBM i Data to Work

    NGS-IQ makes it easy to securely access, format, analyze, and share critical business data across your organization.

    Join us for a look at the top challenges companies attending COMMON NAViGATE at TechXchange 2026 shared when it comes to getting reliable reports from their DB2 data — and how NGS-IQ can help provide the answers you need without breaking the budget.

    Register for the Webinar

    www.ngsi.com – (800)824-1220

    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

    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

    V6R1 Run SQL Scripts: Print and Save Result Sets Reader Input: /QOpenSys Redux, PC5250 Popup Keypads, and Even Farther Beyond Replication

    Leave a ReplyCancel 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

  • Power Systems Turns In Another Great Quarter
  • Big Blue Is Right On Schedule With Fall 2026 IBM i Tech Refreshes
  • Guru: Environment Variables – Global Variables Wearing Hiking Boots
  • A New IBM i Entity Takes Shape: Power By Fortra
  • IBM i PTF Guide, Volume 28, Number 38
  • Critical PHP2Shell Security Vulns Evoke ‘Black October’
  • Why Fortra Partnered with FalconStor to Launch Continuity Care: A Validated Recovery Service for IBM i
  • Guru: Analyzing User Session Statistics, Part 2
  • Fresche Launches OpsIQ, a Free AI-Based Operation Assistant for IBM i
  • IBM i PTF Guide, Volume 28, Number 37

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