× 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.




Hi All,

OK, admittedly I am coming into this thread very late and probably ill-informed about the ongoing debate but...

I fail to see the problem with the way in which we check for valid parameter access in RPG.

What is difficult about:


parm3 in proto with *OMIT : *NOPASS
local3 like parm3 in local D-specs (optionally initialised to a non-default value)

if %parms() >= 3 and %addr(parm3) <> *null;
local3 = parm3;
endif;

work with local3...


This logic is obvious and clean. the procedure ONLY accesses local3, with the exception of populating it from parm3, if passed.
It ensures you ALWAYS check %parms() BEFORE %addr() if *OMIT and *NOPASS is specified for a parameter:
1) *NOPASS: Is a parameter passed?
2) *OMIT: Is the address of the passed parameter a null?

As *OMIT passes an address (albeit a null address) it will count as a parameter when checking %parms(). Calling myProc(*OMIT : parm2 : *OMIT : parm4) will set %parms() to 4 inside myProc. So check it is passed before checking its address is null.

This code also gives you the ability to initialise local3 with a non-default value to be used if parm3 is not passed. Parm3 is simply an override value.

When using this in a procedure overloading scenario - you simply call the other procedure passing the additional data using the local variables.

This is a similar mechanism to overloading constructors. The constructor that takes the most parms usually performs the work. The other variants simply supplement the missing parms with locals (derived or otherwise) and call the full constructor.

Cheers

Larry Ducie



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.