In this part, we will look at the below topics:
- CALLB (Call a Bound Module) Op code.
- Using Prototypes effectively.
- Using Import and Export.
CALLB Op code
The CALLB opcode can be considered as an older version of CALLP. It is not as versatile and does not support all features that CALLP does.
The limitations of CALLB are:
- Supported only in Fixed format RPG
- Does not support Prototyping
- Does not allow Return values.
The format of CALLB is similar to that of CALL. Factor 2 must specify the name of a *MODULE object as a literal or procedure pointer or a named constant.
The factor 2 module object specified must be bound to the program object that calls it. It cannot be a program object bound separately.
D ProcName C 'ProcXYZ'
D PPtr S PROCPTR
* Examples of CALLB: one where the called procedure is specified as a
* Literal, one where a constant is used to specify the called procedure,
* and one where a procedure pointer, PPtr, is used to indicate the called
* procedure.
C CALLB 'ProcXYZ'
. . .
C CALLB ProcName
. . .
C EVAL PPtr = %PADDR('ProcXYZ')
C CALLB PPtr
This opcode has been considered just for the sake of completeness. As already mentioned, CALLP is a better and modern option to use.
Using Prototypes effectively
As mentioned earlier, RPGIV passes parameters by reference. However, there are options to pass parameters by value as well. This is by making use of the VALUE keyword in the Prototype. An example is shown below where all the parameters to the Payment Procedure will be passed as values and their reference will not be passed.

In the called procedure, the procedure interface definition must also specify the VALUE keyword to match the prototype.
You can mix passing methods if necessary. If you omit the VALUE keyword for a parameter, the parameter is passed by reference.
Another keyword that can be used similar to VALUE is CONST that can be used to pass an argument to a procedure as a constant. The called program will not be able to change the value of the parameter passed as the constant.

The snippet above shows an example where the first parameter being passed to the procedure is passed as a Constant and it will be not be modifiable in the called program.
Using Import and Export
Import and Export keywords are used to define intermodular “super-global” fields which can be accessed across modules of a program which have been bound together.
If a variable needs to be defined as a super global field, declare it in the required module and specify ‘EXPORT’ in the definition. Then declare the same variable across all the required modules mentioning ‘IMPORT’ in the definition. An example of the EXPORT and IMPORT is shown below is shown below.

Few things to note:
- Super global variables cannot be specified as Parameter items.
- The procedure exporting the data item is responsible for initializing it.
That completes the topics that needed to be covered in this part. The last and final part of Modular programming (coming up next) will complete this post.