After reading the IBM documentation about RTNPARM keyword, it's still not clear, to me, how I have to handle it.
Could someone give me a small procedure example?
If it is much faster, why IBM didn't make it implicit?
RTNPARM is for procedures that return a very long character value that is frequently only partially used. The return value gets pushed onto the stack, and it takes longer to push a 64K character onto the stack vs. a 10 byte character. Parameters passed by reference only put a pointer on the stack. When you use the RTNPARM keyword, it treats the return value like a parameter passed by reference. Internally, the first parameter becomes the return value passed by reference. You still pass and retrieve the return value the same way you would normally, but if you want to get the number of parameters using %parms()
, the parameter numbers will be incremented by one. IBM introduced the %parmnum()
built-in to deal with this.
So here is a simple example:
dcl-proc sample;
dcl-pi *n Varchar(65535) RtnParm;
parm1 VarChar(256) const options(*nopass);
end-pi;
dcl-s result Varchar(65535) Inz('');
dcl-s str1 Varchar(256) Inz('');
if %parms() >= %parmnum(parm1);
str1 = parm1;
endif;
// do some stuff
return result;
end-proc;