Back to: ILE RPG in Easy Bytes

Unit 13 continues coverage of modular programming techniques by discussing procedures. You learn how procedures differ from subroutines and called programs, and the advantages of using procedures. The unit compares three different programming constructs: cycle main programs, linear main programs, and Nomain modules. It also shows how to compile modular components and bind them to callable program objects. Finally, this unit introduces several other application development topics related to the Integrated Language Environment (ILE), including passing parameters by value and using binder language.
This course includes hands-on lab exercises to help you understand the concepts behind procedures, modular programming, and binding directories.
This course is a unit of the ILE RPG in Easy Bytes series, a complete introductory ILE RPG programming self-guided tutorial.
- Before starting this course you must complete the required prerequisite course: 12. Calling Programs – ILE RPG in Easy Bytes
One-Time Payment
Members Only
Instead of paying for each unit individually, you may purchase a membership which will automatically enroll you at a discount in the entire “ILE RPG in Easy Bytes” series.
Building Modular Programs with Procedures
In this environment, the calling programs and the called programs are complete in themselves, having been individually compiled. This technique is called a dynamic program call. With this technique, when a program encounters the Callp operation to invoke another program, the system goes looking for the called program dynamically, during runtime, using an internal process known as resolution.
Dcl-proc proc-name {keywords}; … End-proc {proc-name}; Between these instructions, the subprocedure can include the following: A procedure interface Declarations Processing statements (calculations) To understand the basic coding requirements for a procedure, let’s look at an example. The following procedure converts a Fahrenheit temperature value into its Celsius equivalent:
A cycle main program has a main procedure implicitly specified in the main section of the program. In a cycle main program, the main procedure does not have a name; it is the main procedure by virtue of its location in the program code. A cycle main program includes a main source section (the main procedure), followed by zero or more subprocedure sections.
A linear main program explicitly names a procedure to be the main procedure for the program. A linear main program includes a Ctl-opt instruction with the Main keyword to name the main procedure: Ctl-opt Main(proc-name); You then code the main procedure just as any other subprocedure, starting with a Dcl-proc instruction and ending with an End-proc instruction.
They include a main procedure, along with all the other required subprocedures, coded within one source member, or compile unit. ILE also enhances modular programming concepts by allowing you to code a source member that consists of a segment of a program without a main procedure. The resulting Nomain module contains only subprocedures (one or more) that you can combine with other modules to create a program.
The CRTBNDRPG command combines the two program-creation steps: Compile—translate the ILE RPG source member into a machine language module (*Module) object Bind—copy and organize the module to produce a program (*Pgm) object With the introduction of ILE, the system now allows, and sometimes requires, you to separate the compile and binding steps by using two CL commands: CRTRPGMOD (Create RPG Module) CRTPGM (Create Program) When you compile source code with the CRTRPGMOD command, the compiler creates a *Module object, rather than an executable program (*Pgm) object.
pass by reference and pass by read-only reference. You can also use these two methods to pass parameters between procedures. In addition, procedures afford a third method:
Learn how to write ILE RPG IV procedures. Code Nomain procedures; pass parameters by value; use a binding directory and conditional compilation directives.
Every procedure begins with a P-spec and ends with a P-spec. As you might expect, the P-spec has a P in position 6. You name the procedure in positions 7–21 (Name+++++++++++).
- Before starting this course you must complete the required prerequisite course: 12. Calling Programs – ILE RPG in Easy Bytes