× 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 Tony,

<snip>
As far as I know, each time a subprocedure is called, it's variables
are all initialized, so this means that, for each subprocedure, I need
a global set of variables in the main procedure that it can store
stuff in.  This just doesn't seem to go with what I believe
subprocedures were designed for.  If I want to use one of these
subprocedure in another program, I have to duplicate the global
variables from the main program.
</snip>

You can prevent your local variables from being re-initialised every time a subproc is called by using the STATIC keyword on your local variables - the variables are still local to your subprocedure, it's just that the compiler allocates STATIC storage to hold them - they're no longer treated as automatic variables.

Have a look at the thread entitled "Static procedure variables - how to re-initialise?" that has run over the last few days for more information about their use.

The biggest consideration is the fact that setting on *INLR in the program does not clear them down, so subsequent calls to the program will have initialised global variables, but un-initialised STATIC local variables.

It would appear that the two contending approaches to re-initialise these fields are to:
1) Put your subprocs into a module and create a *SRVPGM in a named activation group. Reclaim the activation group to reclaim all static storage, and thus clearing static local variables.
2) Include an optional (*nopass or *omit - your preference) parameter to the subprocedures and use it as a "mode" flag to initialise the variables.


HTH

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.