.st0{fill:#FFFFFF;}

RPGLE parameters changing value in procedure calls 

 May 3, 2011

By  NickLitten

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;

 

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Trekkie, Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.

Nick Litten

related posts:




{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

I’m always looking for awesome input, feedback and critique!

>