The Midrange Manager: Using Modules and Procedures

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Making the move to RPG IV with modules and procedures isn't as difficult as you might expect. There is some mystery surrounding the idea of using modules and procedures instead of traditional programs, but the concept--and the implementation of it--is not really that complex.

With traditional RPG III on AS/400, you had source members that, when compiled, created program objects (*PGM). Pretty straightforward; edit "the program" with SEU, compile "the program" with PDM option 14, and (assuming no syntax errors) you end up with a *PGM object.

When you need to jump from one program to another, a simple CALL operation is performed. The CALL interface between programs is notoriously slow, but the overall performance of the CALL operation has improved over the years with new, faster chips.

With modules and procedures, you still end up with a program, but sometimes a couple of additional steps are required to get to the program object. The reason for this is that programs are actually made up of modules. If a program is created from a single source member, that program contains one module. If a program is created from the compilation of several source members, each source member yields a module. Consequently, the program is made up of multiple modules.

A module is an object very much like the old program object created with RPG III. The primary difference is that module (*MODULE) objects are not called. Instead, modules contain routines that are called from other routines. These routines are referred to as "procedures." These procedures can be called by other procedures. Although technically it is possible to call a module, it does not make sense to do so and is rarely practiced. Today, best practice is to call procedures, which are the routines stored in a module.

Procedures are the code that is run within a module object. Procedures are created using source code written with any ILE language, such as C, C++, RPG IV, COBOL, and even CL. A procedure has a starting point and an exit point. Procedures may accept parameters if required, and they support local variables. This allows the programmer to create a procedure that has its own variables--variables that are not visible and therefore do not conflict or interfere with other areas of the eventual program in which they will be stored.

One advantage of using procedures is that the modules in which they are contained are created from a single source member, yet multiple modules are used to create programs. So procedures may be stored in any number of individual source members. Since modules may contain any number of procedures and calling between procedures within the same program is simple, you are encouraged create several small source members in which to store your procedures. Then, when maintenance is required, you need only worry about modifying the small source member and not the 3,000- to 7,000-line, all-in-one source program you previously managed.

This I just a quick look at modules and procedures. You should consider replacing all new code with RPG IV and modules and procedures, and you should strongly consider allowing developers to use this technology with their maintenance assignments. It helps give them the skills to write better applications for your shops, and it will also help reduce the overall amount of time required to make a change to an application.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: