Shared Variable

anandknr

Member
How to know if an shared variable is created or not . Any function for that ??

i have to replace the code
DEF SHARED VAR v-birth-cntry-desc no-undo
with
DEF NEW SHARED VAR v-birth-cntry-desc no-undo

if it is not yet created .

Any such check available ?
 
Ordinary we include all shared vars to 1 include file {system.i}

another choice

&IF DEFINED(VarName) = 0 &THEN
&GLOBAL-DEFINE VarName "Defined"
define new shared variable varname as character.
&ELSE
define shared variable varname as character.
&ENDIF
 

TomBascom

Curmudgeon
If you are going to use shared variables (which is, at best, questionable) then the "best practice" is to always define them as NEW GLOBAL SHARED.

That way they always exist and there is only one instance with a given name. (The "new" is ignored if it already exists.) If you leave out the GLOBAL then "new" behaves as you have observed -- at run time the variable must already be defined somewhere. You can also, potentially, have more than one instance of the variable with that name and the one available to your program depends on where you are in the call stack. And that is hardly ever what you really want.
 

tamhas

ProgressTalk.com Sponsor
The real answer is "Don't do that!"™ I can understand someone wanting to use shared variables if they are in a system full of shared variables, but shared variables were just a crutch to get us past not having proper parameters and there has been no good reason to use them for 20 years. If a routine needs a value, then create a parameter for that value and pass it on the run statement ... even if the source of the value is a shared variable because the run is in some legacy code that you haven't fixed ... yet. If you need to return a value, likewise. With parameters you know where a value is coming from and going to. With shared variables you have no idea who might be messing with it somewhere.
 
PERFECT answer, Shared-variables are soo redundant now.
Parameters have been the way forward for the last 20 years.
Which now are less. Progress is a parameter driven environment
 
Top