Why do we use procedure prototype (PR) and procedure Interface (PI) in the RPGLE program?
Is this the replacement of *ENTRY parameters in the RPG program?
Provide an example of a simple program that makes use of PR and PI for creating and calling a procedure.
The procedure prototype (PR) is referred to by the compiler when calling the program or procedure and ensures that the caller passes the right arguments as per the defined PR.
The procedure entry parameters are declared using the procedure interface (PI).
Every parameter on the Procedure Interface (PI) should match the parameters on the Prototype (PR) w.r.t data type, size, and return value.
Declaring PR and PI in RPG Fixed format:
D ADD PR
D PARM1 10A CONST
D PARM2 3P 0 CONST
D ADD PI
D PARM1 10A CONST
D PARM2 3P 0 CONST
Declaring PR and PI in RPG fully free format:
DCL-PR ADD;
PARM1 CHAR(10) CONST;
PARM2 PACKED(3) CONST;
END-PR;
A free-form prototype specification begins with a DCL-PR statement, followed by the prototype’s name, keywords, and a semicolon.
To end the prototype, use the END-PR statement. END-PR may be included in the DCL-PR statement if 0 params.
DCL-PROC ADD;
DCL-PI *N;
PARM1 CHAR(10) CONST;
PARM2 PACKED(3) CONST;
END-PI;
END-PROC;
A free-form technique. The interface specification begins with a DCL-PI statement, followed by the procedure name (or *N if you do not wish to repeat the procedure name), keywords, and a semicolon at the end.
The END-PI command ends the prototype. If no arguments are supplied, the DCL-PI statement may include END-PI.
If no prototype is specified for a cycle-main process, the procedure interface can be named *N.
Please ensure that we use DCL-PROC and END-PROC, which are P specs-free formats in RPG AS400 because we use *N with the procedure interface name.