Normally it should not be necessary to reset static variables.
But sometimes there is a need to do so as dennis pointed out for example to
reset totals.

In this situations I use an optional parameter (simply an indicator). If
this parameter is passed, the static variables first get initialized.
At the first call, I pass the optional parameter (with *ON) and for all
subsequent the parameter is either not passed or passed with *OFF.

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Dennis Lovelady
Gesendet: Tuesday, 26. January 2010 14:28
An: 'RPG programming on the IBM i / System i'
Betreff: RE: Correct use of STATIC variables

I think the point of STATIC variables is, you DON'T initialize them
between program calls. At least, not according to this description from
the RPG Reference on static variables. I mean, how do you initialize
something that is not visible outside of its context, such as a
procedure?

Upon occasion I will have a procedure that needs to know if it needs to be
"reset." Maybe it's accumulating some total for groups of data or ...

For example, if one parameter is a flag that is passed to indicate "First
call from this entity" (whatever that entity may be). When the procedure
sees that flag is set, it can do its re-initialization.

Is this what the OP had in mind?

Dennis Lovelady
http://www.linkedin.com/in/dennislovelady
--
"If only God would give me some clear sign! Like making a large deposit in
my name at a Swiss bank."
-- Woody Allen




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.