× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Peter wrote:
>I'd really like to know what's going on, and where
>it's appropriate to use VALUE instead of CONST.

VALUE and CONST should be used when passing parameters to
procedures where the procedure does not change the value
passed.  Reference parameters are used when you want the
procedure to change the value of a particular variable.

How to choose between VALUE and CONST?  CONST parameters
are like reference parameters in that an address is pushed
on the stack.  (CONST parameters must not be changed
within the procedure.  VALUE parameters can be changed
within the procedure, without affecting any variable
passed in the call.)  So, one rough rule of thumb is that
if the item is bigger than a pointer, use CONST, otherwise,
use VALUE.

But it's not quite that simple.  For example, I recently
posted a sample procedure for centering text on the RPG
forum at the iseriesnetwork.com web site.  I chose to
pass the varying length string parameter by VALUE.  Why?
Because the first thing my procedure did was %TRIM the
string.  By passing the string by VALUE, I was able to
change the value of the string parameter, and I didn't
need to define a separate variable within the procedure.
It made the coding of the procedure a bit easier.

Generally though, strings should be passed as CONST
VARYING.  Smallish items should be passed as VALUE.  If
you need to return a value from a procedure, use the
the RETURN opcode.  If you need to return multiple values,
you might be tempted to define several reference
parameters.  But I'd recommend returning a data structure
instead.  In V5R1, that has been made much easier now that
you can code LIKEDS as the type of the return value.

Cheers!  Hans

Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.