TechTip: CALLing in Free-Format RPG IV

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

Discussion of free-format RPG IV usually takes on topics such as indenting, semicolons, and similar syntactical areas. Unsupported opcodes also create lively banter between advocates of free-format and those preferring fixed-format. In that vein of thought, our old friends CALL, PLIST, and CALLB are now on the chopping block. "OK," you might say, "so how do I handle calls in this new free-format world?"

Calling another program is commonplace in RPG, whether dynamic (using CALL) or bound (using CALLB). Parameters are specified for either of these two operations by use of PARM statements after the call or in a PLIST group elsewhere. The free-format style does not use any of these methods.

The only call possible in free-format is the prototype call: CALLP. It can be either a dynamic call or a bound call. The distinction is made in the keyword choice on the prototype statement in the D-specs. Keyword Extpgm and its value define an external program to be called dynamically. Keyword Extproc and its value define a bound procedure to be called statically. The prototype also defines the parameters used in the call, and for subprocedures, the definition of a return value. However, we'll save the details on subprocedures and parameters for a future TechTip.

The following example shows a typical call used in fixed-format RPG. Field definitions have been added in the example for clarity and would not normally be specified there:

     C     List1       Plist                                
     C                 Parm                  CustNo   7 2
     C                 Parm                  Invoice  5 0
     C                 ----------
     C                 ----------
     C                 Call   'PROG2'        List1
     C                 ----------
     C                 ----------


The equivalent in free-format RPG would be the following:

     D Program_2      PR             Extpgm('PROG2')
     D   Cust                 7 2
     D   Inv                  5  0 
      

      /free
       -----------
       CallP Program_2(CustNo:Invoice);
       -----------
      /end-free


Did you notice a couple of unusual things? First, the name on the prototype does not have to match the program being called, and on the CALLP operation, the prototype name is used instead of the program name. Second, the names used on the D-specs for the parameters don't seem to match anything. That's because the prototype for parameters does not use parameter names--just data type, length (and decimal places), and keywords. You could leave the name blank! Some kind of documentation is always useful, so go ahead and name the parameters.

On the CALLP operation, the parameters are the real variables to pass, not the names used on the prototype.

The same process is used for bound calls, but the keyword on the prototype statement is Extproc instead of Extpgm.

When coding the called program in free-format, you must code both the prototype and a procedure interface in the D-specs. For an example, the following is a shell for the called program PROG2. Notice that there is no *Entry PLIST.

F FileA IF E K Disk
D PROG2 PR
D Cust 7 2
D Inv 5 0
D PROG2 PI
D Customer 7 2
D Invoice 5 0

/free
---------
Chain (Customer:Invoice) FileA; // Use parameters from PI
---------
---------
/end-free

Using CALLP to call other programs or procedures is different from using CALL or CALLB, but it's not difficult. When you get a chance, give this new method a try!

Jim Martin, the author of Free-Format RPG IV, is a corporate technical instructor at Jack Henry & Associates in Monett, Missouri. He is a veteran of RPG programming, beginning in 1967 with a position at IBM as a systems engineer and later as a staff programmer at the Rochester systems programming lab. For eight years, he was at Lakeview Technology as an AS/400 and RPG instructor and was a speaker at various local midrange user group meetings and conferences. He can be reached by email at This email address is being protected from spambots. You need JavaScript enabled to view it..


JIM MARTIN

Jim Martin holds a BS degree in mathematics and an MS in computer science. For 26 years, he was employed by IBM, where he wrote RPG applications for customers and worked in the programming laboratory as a programmer on portions of CPF and the OS/400 operating system. After leaving IBM, Jim took post-graduate work in computer science and performed RPG training. He is an IBM-certified RPG IV developer and author of multiple bestselling editions of Free-Format RPG IV, which, since the book's initial publication in 2005, have taught thousands of RPG IV programmers how to be successful with the free-format coding style.


MC Press books written by Jim Martin available now on the MC Press Bookstore.

Free-Format RPG IV: Third Edition Free-Format RPG IV: Third Edition
Improve productivity, readability, and program maintenance with the free-format style of programming in RPG IV.
List Price $59.95

Now On Sale

Free-Format RPG IV: Second Edition Free-Format RPG IV: Second Edition
>Make the transition from coding in fixed-format RPG to free format.
List Price $59.95

Now On Sale

Functions in Free-Format RPG IV Functions in Free-Format RPG IV
Here’s the ultimate guide to writing RPG IV programs with functions in the free-format style.
List Price $59.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS