Super Procedures as a Replacement for Global Vars

I know that this seems so simple, I am almost embarrassed to even post it. I know how to create super procedures, and run them persistently. Can someone give me an example of how to use the technique to replace the need for global shared variables? I know I am missing something here! Thanks.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tamhas's picture

First, I suppose that one

First, I suppose that one should actually say, "create procedures, run them persistently, and make them super" since that is the right sequence ... but ... :)

To replace the use of a GSV, all you need is getter and setter methods in your SP to return or set the value. Once you have created a session super, then those methods are available to everything in the session.

So just:

run GetMyValue(output GSVValue).

It is possible to use functions as well, but then you have to forward reference the function at the top of the procedure where it is used, which isn't very elegant.

Note that if one is refactoring shared variables, one typically wants to turn them into parameters in the run link instead since that makes it clear what is passed across the interface. Lots of values stuffed in SPs can lead to the same kind of difficulty in analysis that SV and GSV do in the first place, so limit them to usage like context values.


Makes sense, thanks!

Makes sense, thanks!