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



David

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?

=================================================================
Local definitions use automatic storage. *Automatic storage* is storage that exists only for the duration of the call to the procedure. Variables in automatic storage do not save their values across calls.
Global definitions, on the other hand, use static storage. *Static storage* is storage that has a constant location in memory for all calls of a program or procedure. It keeps its value across calls.
Specify the STATIC keyword to indicate that a local field definition use static storage, in which case it will keep its value on each call to the procedure. If the keyword STATIC is specified, the item will be initialized at module initialization time.
Static storage in the main procedure is subject to the RPG cycle, and so the value changes on the next call if LR was on at the end of the last call. However, local static variables will not get reinitialized because of LR in the main procedure.
=================================================================

My first question is, what are you trying to accomplish when you use the STATIC keyword? I don't find many uses for it, to tell the truth. There is the idea of thread-local storage - this is a separate copy of the variables for a procedure that is called in different threads of a job. If you are using it for performance reasons, to avoid initializing the storage on each call, that is a waste of development time, in most cases. Someone once said that the 3 rules of optimization are "Don't! Don't! Don't!" At least not down to the most minute level.

So it'd help to know why it is being used - even things like counters can be handled with parameters instead of static variables.

I believe the scratchpad of SQL functions can be static storage - but does not need to be, apparently. Just looked it up!!

HTH
Vern

David FOXWELL wrote:
What is the normal manner to initialize such variables between program calls? Without using activation group *NEW. Currently, it seems we are relying on a CLP that issues a RCLRSC.

Thanks.


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.