fhg
Volume 9, Number 21 -- June 24, 2009

No More Global Variables!

Published: June 24, 2009

by 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


Sponsored By
PROFOUND LOGIC SOFTWARE


Now is the time to take control of your
application modernization.

You may have already tried or looked at
various solutions and methods. If you have not
achieved phenomenal results in record time, you
must download one of our webinars.

Download now and see the difference.



Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Erwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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


 
The Four Hundred
AS/400:Still Kicking After 21 Years

Power Systems i Weather Report: Partly Cloudy Soon

IBM i Manifest Takes Root in Japan

Help Wanted: AS/400 Advocate

COMMON Europe: Doing the Math on Top i Concerns

Four Hundred Stuff
IBM to Offer Free EGL Tool for Web 2.0

Infor Spurs Customer Upgrades with 'Flex' Incentives

Application Maintenance Becomes a Service at vLegaci

Companies Put PHP to Work With BCD's WebSmart

ASCI Adds i OS Support to Job Scheduler

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
June 20, 2009: Volume 11, Number 25

June 13, 2009: Volume 11, Number 24

June 6, 2009: Volume 11, Number 23

May 30, 2009: Volume 11, Number 22

May 23, 2009: Volume 11, Number 21

May 16, 2009: Volume 11, Number 20

TPM at The Register
VMLogix plugs virt jukebox into Amazon cloud

Platform leaps from grids to clouds

Mellanox cranks up InfiniBand switches

Wall Street hammers for sale sign in Novell lawn

iSuppli: Moore's Law to take a breather

Sun kicks out VirtualBox 3.0 beta

Canucks buy 300 teraflops Blue iDataPlex super

EnterpriseDB revs Postgres database

Dell grows Intel 'Nehalem EP' iron

Canonical certs Ubuntu on ProLiants

IDC: Server market to decline through 2010

Red Hat's standalone hypervisor goes beta

Citrix ships XenServer 5.5

Wind River punts homegrown hypervisor

THIS ISSUE SPONSORED BY:

Help/Systems
Profound Logic Software
CNX


Printer Friendly Version


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

Reader Feedback: Advanced DB2 for i Data Access Techniques with .NET

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
PHP CLI Call

Perl, PHP, and/or ZendCore

batch printing PDF files from RPG program

Using db2_connect in PHP on iSeries

How to return value from CL program?

ADO.NET/IBM.Data.DB2.iSeries/ iDB2Connection

Order by alias names




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2009 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement