Operating System - OpenVMS
1753479 Members
4875 Online
108794 Solutions
New Discussion юеВ

How to test if a symbol has been initialised

 
SOLVED
Go to solution
matt burns
Occasional Advisor

How to test if a symbol has been initialised

Is there a nice tidy way to test if a symbol has ever been initialised?

Cos the way I'm doing it seems a bit backwards.

$ON WARNING THEN GOTO WARNUSER
$!
$!This will fail if MYSYMBOL not set
$TEMP = MYSYMBOL
$!
$!Restore action upon warning
$ON WARNING THEN GOTO JOBERROR

When I joined this forum I thought I was quite good with DCL and OpenVms, having read a lot of this forum, I bow my head to you guys!
10 REPLIES 10
Willem Grooters
Honored Contributor
Solution

Re: How to test if a symbol has been initialised

Try this:

if f$type(MYSYMBOL) .eqs. "" then goto warnuser

If MYSYMBOL has been defined, f$type will hold it's type. Consequently, if MYSYMBOL hasn't been initilazed (not even to "") - so actually doesn't exist, f$type will return "".

So this can be exploited....
Willem Grooters
OpenVMS Developer & System Manager
matt burns
Occasional Advisor

Re: How to test if a symbol has been initialised


Thanks for the help willem but the batches I need to add the code to may have various actions to perforn in the event of a warning.

ie. they may start with
$ ON WARNING THEN GOTO JOBERROR

Your suggestion works ok on the commands line, but in the code, causes the batches to jump to label JOBERROR.
Is there a way to do it without causing any warnings at all?
Antoniov.
Honored Contributor

Re: How to test if a symbol has been initialised

Hi Matt,
if you will be sure symbol is initialized you can use this code run quicly than test f$type

$ MYSYMBOL="''MYSYMBOL'"

Otherwise you can assingn a value to another symbol, set null if symbol is not defined without test:

$ SYMBOL_TWO="''MYSYMBOL'"

Prior statement are functionally with string symbols. Using numeric symbol you need use f$type function.

Bye
Antoniov
Antonio Maria Vigliotti
matt burns
Occasional Advisor

Re: How to test if a symbol has been initialised

Antoniov, I beleive you have misunderstood me.
My whole problem is trying to discover if a symbol is initialised without raising a warning.

Your lines are basically assigning the string representation of MYSYMBOL to another symbol, (something that could also be done with the lexical f$string).

I need to find out if MYSYMBOL (global symbol) has ever been initialised (ie. in a calling batch)

I know I check search the result of
$ SHO SYM /GLOBAL MYSYMBOL

Or I can do what I am doing which is

$ SET NOON
$!
$ IF F$TYPE(MYSYMBOL) .EQS. ""
$ THEN
$ GOSUB JOBERROR
$ ENDIF
$!
$ SET ON
$!

I just want to know if there's a tidier way!
Antoniov.
Honored Contributor

Re: How to test if a symbol has been initialised

Ok Matt,
if you need only stop a batch, use f$type.

Sometimes you could need assing value without error and f$string can't work!
I've learned use of "''MYSYMBOL'" reading various VMS system files.

Bye
Antoniov
Antonio Maria Vigliotti
matt burns
Occasional Advisor

Re: How to test if a symbol has been initialised

Antoniov, I see what you mean now.

$ MYSYMBOL = "''MYSYMBOL'"

throws no warnings but will leave MYSYMBOL initialised to either the value or ""

Cheers
Dale A. Marcy
Trusted Contributor

Re: How to test if a symbol has been initialised

The lexical f$type(symbol_name) does not appear to trip the on warning code when I test it. It did when I added "s around the symbol name as the argument to the f$type call, but when I coded it properly without the "s, it works fine.
matt burns
Occasional Advisor

Re: How to test if a symbol has been initialised


Yes, you are right, I don't know what I tried before but it works ok now ??!?!?!!
Antoniov.
Honored Contributor

Re: How to test if a symbol has been initialised

Hi Matt
Excuse me
MY_SYMBOL=""MY_SYMBOL"" it's a error

If you set a symbol and you can accept null value if symbol not defined you can write
TWO_SYMBOL="''MY_SYMBOL'"
If MY_SYMBOL is not defined TWO_SYMBOL is set to "".
If you write
MY_SYMBOL="''MY_SYMBOL'" you are sure MY_SYMBOL is defined as value of caller (if defined) or null (if caller has not set MY_SYMBOL).
Same using == (to assing global values).
F$STRING permit convert a numeric symbol into string symbol. There are few differents between string symbol and numeric symbol.
If you stil need help about symbol post question.
Excuse me again for prior error.
Antoniov

Antonio Maria Vigliotti