Question Norman W. Freeman · Jun 28, 2022

Is it possible to call a method in a specific namespace without changing current namespace ?

I want to call a method which is in %SYS namespace : 

set NS = $NAMESPACEZN"%SYS"do ##class(Config.MapGlobals).Delete(...)
ZN NS

In reality code is even more complex (eg: need a try catch block to make sure namespace is switched back even if there is some error).
Is it possible to do this without changing current namespace ?
For example (does not work) :

do ##class(%SYS.Config.MapGlobals).Delete(...)
Product version: IRIS 2022.1

Comments

Julius Kavay · Jun 28, 2022

First, the correct (or better) way for the above code snipet were:

new$NAMESPACEzn"%SYS"do##class(Config.MapGlobals).Delete(...)
quit

second, one can call routines (and (class)methodes are compiled to rotines) from another namespace by using extended syntax, but in that case such a routine uses the globals (if the routine does a global access) from the CALLING namespace. In Your case this won't work because the Config.MapGlobals uses globals which resides in %SYS namespace and not in the namesspace you are in.

0
Norman W. Freeman  Jun 28, 2022 to Julius Kavay

Thanks. Out of curiosity, can you show the extended syntax to call a method from another namespace ?

Also : when you say Config.MapGlobals use globals in %SYS, what are they used for ? AFAIK mappings are stored in IRIS.cpf file, not in globals (or maybe you are referring something else).

0
Julius Kavay  Jun 28, 2022 to Norman W. Freeman

The general syntax for calling routines from another namespace is:

do label^|namesapce|routine

where

- you can omit the label and

- namespace is either the name of the namespace (like set namesapce="USER") or the path to the database (preceded by two carets), where the routine resides.

I see right now, Config.MapGlobals accesses the ^SYS global via the path to the database (take a look at the Storage section) - so in theory, you  can  call all classmethods from the above class as:

do zClassmethodname^|"%SYS"|Config.MapGlobals.1(args...)

merely, I do NOT recommend to do this (the cass is in deployed mode, so we do not know, what the code really does and (instance)methods are private, so you can't call them from outside).

0
Robert Cemper  Jun 29, 2022 to Norman W. Freeman

Just to  complete it:

iris.cpf  could be understood as kind of .ini file that is loaded during system start. Regular access during normal operation would be a desaster to perfomance.

0