Mastering AS400: Unraveling the Secrets of Prototype and Prototype Interface
In this blog we are going to cover
- What is prototype and prototype interface.
- How to efficiently use other programs as modules.
- Pass the parameters to other programs.
- Understanding the optional parameters NOPASS, OMIT, and Constants.
What is prototype?
- Definition: A prototype (PR) is a declaration that tells the RPG program how to call an external program or procedure. It specifies the name of the external program or procedure, the parameters it accepts, and the return type (if any).
- Purpose: The prototype ensures that the calling program knows exactly how to interact with the external program, including how to pass arguments and what to expect in return.
Attached an example,
Caller
A rpgle named Program1 is calling an external rpgle program Greet2.
D GreetWithName PR ExtPgm('GREET2')
D name 20A The prototype name is user defined, it’s not necessary to be same as called program name or the name of the prototype in the callee.
What is prototype interface?
- Definition: A prototype interface (PI) is a structure that defines the parameters for procedures that will be implemented in the same program or that will be called from external programs. Unlike a prototype, which is about calling an external procedure, a prototype interface is about defining the procedure within the program.
- Purpose: The prototype interface is used to ensure that the parameters for a procedure are consistent and that the procedure can be correctly called either from within the same program or by another program.
Attached an example,
Callee
A prototype( PR ) and prototype interface is defined in the rpgle program Greet2.
D Main PR ExtPgm('GREET2')
D name 20A
D Main PI
D name 20APractical Use:
- Prototype: When your program needs to call an external program, you declare a prototype that matches the parameters and return type of the procedure in the external program.
- Prototype Interface: When you define a procedure in your program (which could be called internally or by an external program), you use a prototype interface to specify the parameters.
How to efficiently use other programs as modules.
Caller
Below a rpgle program named Program1 makes a call to Greet rpgle program to display greet messages. Lets see how it works!
D Greet PR ExtPgm('GREET')
dsply 'Displayed from program 1.';
callp Greet();
*inlr = *on; 0001.01
Using D spec lets us to call other programs inside it.
Placing D in first column and taking F4 lets us to declare the rpgle program Greet.
Name….Greet is the program name we are going to call.
Declaration….PR says it’s a prototype. Prototype means it says how the callee program should be called like with how many number of inputs, input datatypes, optional parameter, constant parameters, etc..
PR is generally copied from the callee.
Keywords….(Ext)ernal (P)rogram name is defined here which is Greet. Extpgm(‘Greet’). Ensure its enclosed within single quotes.
0001.02
dsply is used to print the string.
0003.01
callp Greet() (or) Greet().
callp can be used to call other programs. Greet doesn’t require any inputs so the paranthesis are empty.
0004.00
*inlr = *on ends the program. It signifies it is last line in the program to be executed.
Callee
Lets see what the Callee does.
Below is the source code of Greet rpgle.
D GREET PR ExtPgm('GREET')
D GREET PI
dsply 'From Greet,';
dsply 'Have a good day :>';
*inlr = *on; 0000.01
The name of the (pr)ototype can be different from the calling programs.
The same D spec is used to define how the program can be called from callers.
But (pi)program interface is the real one where it defines the datatypes for the inputs and outputs.
Compiler don’t compile the prototype as it is just a blueprint that how the callee can be called.
0000.02
It’s the program interface of the program Greet. It’s for internal use. Compiler compiles prototype interface.
Remaining code displays hardcoded values and indicator for last record is turned on (*inlr) to end the program.
Output
Command: call program1
PASS THE PARAMETERS TO OTHER PROGRAMS.
Passing strings.
Caller
Below is the rpgle program named program1 which is calling greet rpgle program with empty parameters and greet2 rpgle program with
name[20 length (A)lphanumeric] as paramter.
D GreetWithName PR ExtPgm('GREET2')
D name 20A
*
D name S 20A
*
name = 'Arc';
callp GreetWithName(name);
*inlr = *on; We can observe the prototype name of the Greet2 external program is GreetWithName.
So the GreetWithName term can be used to call the callee, which is
Code: callp GreetWithName(name);
name variable is initialised with the value ‘Arc’. Note that it is declared as a standalone variable with 20 length Alphanumeric.
Get Life@Twenty’s stories in your inbox
Join Medium for free to get updates from this writer.
Meanwhile the asterisk is used to comment the line. It could be placed in the second column of any record to comment out the line.
Do ponder why no error is thrown as the variable name is defined twice in the program!
Callee
Prototype( PR )
Below is the source code of the callee Greet2. In the first place the prototype is named as Main, which says that the callers should use the format as this prototype Main when making call to this program GREET2
D Main PR ExtPgm('GREET2')
D name 20A
D Main PI
D name 20A
dsply 'From Greet2,';
dsply ('Hi, ' + name + '.');
*inlr = *on; Prototype Interface( PI )
The prototype interface is used internally in the program.
The value passed from the caller is actually stored in the prototype interface.
The display command displays the value passed on.
Output
Command: call program1
Passing numerics.
Caller
The rpgle program named program1 has the prototype to the external rpgle program named ADD.
From protype we could infer that the external program requires 3 input parameters,
(i) ‘a’ with length 2 numeric and 0 decimal position.
(ii) ‘b’ with length 2 numeric and 0 decimal position.
(iii) ‘c’ with length 2 numeric and 0 decimal position. Most importantly the third paramter is an optional( *nopass ) paramter.
*nopass indicates the third paramter can be passed or ignored.
D Add PR ExtPgm('ADD')
D a 2S 0
D b 2S 0
D c 2S 0 Options(*nopass)
*
D a S 2S 0
D b S 2S 0
D c S 2S 0
*
a = 2;
b = 5;
callp Add(a: b);
a = 1;
b = 4;
c = 9;
callp Add(a: b: c);
*inlr = *on;Note that we have used two ca statements
callp Add(a: b);callp Add(a: b: c);Callee
The below is the source code for the rpgle program ADD.
D ADD PR ExtPgm('ADD')
D a 2S 0
D b 2S 0
D c 2S 0 Options(*nopass)
D ADD PI
D a 2S 0
D b 2S 0
D c 2S 0 Options(*nopass)
if (%parms >= 3);
dsply ('Three parameters are passed.');
dsply ('Result: ' + %char(a + b + c));
elseif %parms >= 2;
dsply ('Two parameters are passed.');
dsply ('Result: ' + %char(a + b));
endif;
*inlr = *on; The prototype in the caller is copied from the callee.
The prototype interface also named as ‘ADD’ has the actual values of the input parameters passed via callers.
%parms
%parms is a built in function which returns the integer value of how many input parameters are passed into the program.
It enables us to customize the processing of the input values.
For ADD program if 3 input parameters are passed then,
if (%parms >= 3);
dsply ('Three parameters are passed.');
dsply ('Result: ' + %char(a + b + c));the above if condition becomes true and adds all three values and displays to the console.
if 2 input parameters are passed then,
elseif %parms >= 2;
dsply ('Two parameters are passed.');
dsply ('Result: ' + %char(a + b));those two values are added up and displayed after turning the integer result to character using %char( build in function to convert numeric to character).
Output
Command: call program1
Understanding the optional parameters NOPASS, OMIT, and Constants.
Optional parameters offer flexibility and efficiency in programming by allowing you to call a function or subroutine without providing values for certain parameters.
NOPASS
- Meaning: “Don’t Pass This”
- Purpose: Lets you skip sending a value for a parameter when calling a program.
- Example: Imagine ordering pizza. You can choose to skip the crust type if you don’t care, and the pizza place will assume a default.
OMIT
- Meaning: “Leave This Blank”
- Purpose: Allows you to send a special value to indicate that a parameter is not being used.
- Example: Again, ordering pizza. You can say “omit” for toppings if you want a plain cheese pizza.
Constants
- Meaning: Fixed Values
- Purpose: Defines values that won’t change throughout the program.
- Example: The value of Pi (3.14159) is a constant used for calculations.
Key Differences between NOPASS and OMIT:
- NOPASS: Completely ignores the parameter.
- OMIT: Sends a special value to indicate the parameter is absent.
Imagine a program that calculates the area of a circle.
- Radius: Required parameter (you must provide it).
- Units: Optional parameter (default to centimeters if not provided).
You could use NOPASS for the Units parameter, allowing callers to omit it if they want the default.
While we’ve covered the basics of optional parameters in prototype interface,
the real power of this function becomes apparent through practical applications.
Be sure to check out our next blog for illustrative examples.
Ending Note
In the next blog more enlightening examples for “Understanding the optional parameters NOPASS, OMIT, and Constants.” are illustrated to help solidify the understanding, until then
Stay happy and cheers❤.
To stay updated with the blogs please follow Life@Twenty. It will really really make me to love my passion even more and more.









