|
That is the safe way. Because in a simple program without subprocedures if you checked %parms and tried to initialize a variable not passed it would blow chunks on you. However, in your subprocedure instead of using the local variable it uses the global variable. Scary. Better to stick with the logic: if %parms>x; WorkVar=ParmVar; // Use the passed parm if it was sent Else; clear WorkVar; EndIf; Rob Berendt -- "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." Benjamin Franklin Joel Cochran <jrc@xxxxxxxxxx> Sent by: rpg400-l-bounces@xxxxxxxxxxxx 08/08/2003 08:03 AM Please respond to RPG programming on the AS400 / iSeries To: RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx> cc: Fax to: Subject: Re: Value vs. Const Just to clarify so others can learn from my mistake: I *was* checking for whether or not the parm was passed using %parms(). My mistake came when the parm was not sent: I would then populate the parm with a default value and use the parm as a local variable. This is the no-no I was referring to before. Now by using const instead of value, I still use %parms() to check and see if the parm was passed, but now I have a local variable with my default value and I only change it if the parm was sent. Now in my program I'm using the lcoal variable instead and all is well. The only reason that I specify const instead of value is simply as a convention: now I cannot change the value of the parm to a default if not sent: if I want this behavior I'm forced to use a true local variable instead. Clear as mud? :-) Joel On Thu, 2003-08-07 at 18:54, Scott Klement wrote: > > One caveat that Barbara Morris pointed out to me is that using "value" > > and "options(*nopass)" on the same variable can be dangerous. If you > > want a variable to be *nopass and still take advantage of the VALUE > > benefits, then use CONST... > > Joel... there's nothing special about VALUE in this circumstance. You > should never reference ANY parameter that has not been passed. It does > not matter whether it's passed by VALUE or REFERENCE or CONST... you > should *always* check with %parms to before using an "optional" variable. > > > _______________________________________________ > This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list > To post a message email: RPG400-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/rpg400-l > or email: RPG400-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/rpg400-l. _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
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.