GKern@xxxxxxxxxxxxxxxx wrote:
I've seen a few instances of where the actual code for a prototype (or 
more than one prototype) is found at the bottom of an RPG source member.
I think you're confusing the terms "prototype" and "procedure".  The 
prototype is the part in the D-specs that must be included in the module 
that uses the CALLP opcode.  It can be included by /copy, and often is 
as Matt has described.  Prototypes can be used to call both procedures 
_and_ programs.  The main purpose of the prototype is to allow the 
compiler to do magic like warning you about parameter mismatches and 
automatically doing type conversion for you (eg. packed to zoned, 
character to varying character, ...).
The procedure what contains the actual code, the part you are seeing at 
the bottom of the RPG source.
The only reason I see for doing this would be to be able to use them like 
subroutines that could accept parameters where the process is performed 
only within a single program. But then wouldn't that still lend itself to 
a /copy book?
Yes.  If you are familiar with Java or other OO languages, this is like 
a "private" method.  You essentially get a subroutine that can avoid 
using global variables and has a well defined interface.  One benefit is 
that if you later realize that this is something that could be used in 
multiple programs after all, it is a lot easier to move it to a service 
program than if it was originally written as a subroutine.
The fact that procedures can be (and should be, where possible) written 
so they have no side effects leads to IMO the biggest benefit of 
procedures over subroutines.  Maintenance is a lot simpler if you can 
just look at the CALLP line and determine whether the variables you are 
interested in are used or changed by the procedure.  With subroutines, 
you have look at the subroutine code and determine which variables are 
updated and which key lists are used before you can confidently change 
any of the code surrounding the EXSR.
Also, just to be clear, it would be the prototype in the copybook, not 
the procedure.  Your instinct is right however.  If the code is reusable 
within a single program, there is a good chance it can be reused in 
other programs as well.
HTH,
Adam
As an Amazon Associate we earn from qualifying purchases.