theju112t
theju112t

Reputation: 37

Passing more parameters to an RPGLE program

I have an RPGLE program which is designed to accept 2 parameters. Though it makes no sense, I came across code calling this program (through callp) passing 3 parameters.

The calling program has defined a prototype as well with three parameters (Again, this is wrong).

So my question is, what would happen if more parameters are passed to an RPG program? To my surprise, there was no error when I tested. But was it a fluke? Is this a potential error waiting to happen?

Upvotes: 0

Views: 1422

Answers (2)

Victor Pomortseff
Victor Pomortseff

Reputation: 453

Parameters are passed to the program via the stack. Inside the program, the first parameter will be on the top of the stack, then the second, and so on (this is valid for C / C ++, RPG ... and, for example, in Pascal, the reverse order is used). Thus, if you pass more parameters to the program than it expects, nothing terrible will happen (if it is not Pascal :-) - all your additional parameters will be at the very bottom of the stack, the program will simply not extract them from there. believes that they are not there.

Upvotes: 0

nfgl
nfgl

Reputation: 3212

RPG programs don't check the number of parameters that are actually passed. If there's one missing and the program uses it then an exception occurs, you car prevent the case using %parms and %parmnum.

When there one more than expected it is ignored. So expect no error here... until you add a third parameter to the callee that is not of the type or length that the caller defined.

To prevent this kind of situation it's a common thing to share prototypes between caller and callee through /COPY or /INCLUDE sources

Upvotes: 6

Related Questions