ibm-midrangerpglerpg

Prototype not used in called RPGLE program , but the program still works


I have a program SS150R where the PI is declared as

Dcl-pi SS150R;                        
pCompcd Char(4);                  
ptrncd Packed(3:0);               
pErrMsg Char(30) options(*nopass);
pSuccess Char(1) options(*nopass);
End-pi;                                 

There is no prototype (PR) declared for this (PI), but still the program is working fine.

My question is that I have always read that a prototype has to be declared if there is a named PI , if its not a named PI like

dcl-pi *n ;
Parm char(1) ;
end-pi ;

Then there is no need for the prototype declaration. Can some one explain in case of my program SS150R there is a named PI and no PR for it , but how is it still working?

Note: My program is called by old Non-RPG program.


Solution

  • First, prototypes are only used by the compiler to define parameters for a CALLP op code. But the compiler is smart enough (since v7.1) that if the procedure is defined within the same source as the CALLP, it can get the parameter definitions from the procedure interface. A prototype is not a runtime object, so does not affect the running of a program once it is successfully compiled.

    A prototype is really only required if the procedure or program is called by an external program or procedure using CALLP. But I usually create prototypes for all EXPORTed procedures and MAIN procedures because I will likely want to call them from some other RPGLE program or procedure, and I only use CALLP these days.

    So here are the various scenarios:

    • Procedure called by another procedure in the same source - prototype not needed.
    • Procedure or program called by another procedure or program (Not RPGLE) - prototype not needed.
    • Program called by OPM program - prototype not needed (not recommended)
    • Procedure or program called by another procedure or program (Not using CALLP) - prototype not needed (not recommended)
    • Procedure or program called by another procedure or program using CALLP - prototype required.

    Just to reiterate, If I am defining a procedure in a module, and that procedure is declared with EXPORT, then I always create a prototype. In addition I always declare a prototype for all program main procedures. These prototypes are always defined in a copy book so the same prototypes can be used in any potential calling program or procedure. I only use CALLP these days to call procedures or programs from RPGLE, and that op code is always implicit.

    Procedures that are defined without EXPORT never require prototypes, so I do not code them.

    NOTE: CALL and CALLB must always be explicitly included, I don't use either of those any more.