Re: RPG subroutine with SQL
You are correct that having both a prototype and procedure interface in the same source member is unnecessary duplication. I suggest you put the prototype in a separate source member.
Consider program X, which several other programs call. I create a prototype of X in member X of a source physical file called PROTOTYPES. I use /include in X and in all of the callers to copy this prototype into all the programs during compilation. If the prototype does not match the procedure interface, X does not compile, so I am assured that the prototype is correct. Since all callers /include the same prototype, I have greatly reduced the chances that a caller will pass an incorrect set of parameters. With the old *ENTRY PLIST method, no such check is possible.
If you want the compiler to catch mismatched parameters, then prototyping is your friend.
Is the method I use foolproof? No. If the first two parameters, for example, of a routine are defined identically, a caller could pass the arguments in reverse order, and compilation would not catch the error.
I work in a 7.1 shop, so I do not use prototypes for internal subprocedures, i.e. the ones that function as local subroutines within a source member. I no longer use subroutines.
Originally posted by Huddy
View Post
Consider program X, which several other programs call. I create a prototype of X in member X of a source physical file called PROTOTYPES. I use /include in X and in all of the callers to copy this prototype into all the programs during compilation. If the prototype does not match the procedure interface, X does not compile, so I am assured that the prototype is correct. Since all callers /include the same prototype, I have greatly reduced the chances that a caller will pass an incorrect set of parameters. With the old *ENTRY PLIST method, no such check is possible.
If you want the compiler to catch mismatched parameters, then prototyping is your friend.
Is the method I use foolproof? No. If the first two parameters, for example, of a routine are defined identically, a caller could pass the arguments in reverse order, and compilation would not catch the error.
I work in a 7.1 shop, so I do not use prototypes for internal subprocedures, i.e. the ones that function as local subroutines within a source member. I no longer use subroutines.
Comment