May 3

0 comments

RPGLE parameters changing value in procedure calls

By NickLitten

May 3, 2011

#parameters, #parm, #procedure, #RPG, #RPGLE

RPG passes parameters by reference, IE the memory address. If you are calling a program there is a potential that the calling program can modify the value at that address.

If you do not want the value to change then set the parameter in the program or procedure to use the CONST keyword.

This simple keyword will prevent any chance of unwanted modifications.

Example:

D DOTHISBUSINESSLOGIC PR 
D CONOOM    2A CONST..
D ORDNOM    7A CONST
D ORDLOM    3P 0 CONST
D SLMNOM    5A

In this example SLMNOM is the only parameter which can be changed when returning from the *called* procedure….

in modern RPG this would look like this

dcl-pi doThisBusinessLogic char(5);
  inp_company_code char(2) const;
  inp_order_number char(7) const;
  inp_order_line packed(3:0) const;
end-pr;

returning the value as part of the return variable “char(5)” is a neater way of designing it. This means that the RETURN statement will simply show the value being returned:

dcl-s rtn_salesman char(5);

// mainline code could have logic that processes the input constants and then populates the return value for it to be returned at the end of the subprocedure. For example:

rtn_salesman = get_orderproc ( inp_company_code :  inp_order_number : inp_order_line );

return rtn_salesman;

 

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>

Snug CBD

 20% Discount

I have partnered with SNUG CBD givING you Organic CBD
20% discount code "NL20"