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 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 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
LATEST COMMENTS
MC Press Online