Written by

Product Support at InterSystems Japan
Article Megumi Kakechi · Nov 7, 2024 1m read

How to programmatically obtain a list of configured namespaces

InterSystems FAQ rubric

It can be obtained with a List query of the %SYS.Namespace class.

1. Create a routine like this:

getnsp
   set statement=##class(%SQL.Statement).%New()
   set status=statement.%PrepareClassQuery("%SYS.Namespace","List")
   set resultset=statement.%Execute()
   while resultset.%Next() {
       write resultset.%Get("Nsp"),!
   }
   quit

2. Run it in your terminal

USER>do ^getnsp
%SYS
DOCBOOK
SAMPLES
USER

The method of executing class queries introduced in this article can be applied in a variety of cases.

You can see various class queries in the class reference. For example,
 %SYS.DatabaseQuery: GetFreeSpace() Free space in database
 %SYS.GlobalQuery: DirectoryList            List of global names in database
 %SYS.GlobalQuery: Size                              Size List of global sizes in database
 %SYS.ProcessQuery: SS                           Process information (same as the list that can be confirmed by the ^%SS utility)
and so on.

There are many other options available, so please feel free to use them.

Comments

Enrico Parisi · Nov 7, 2024

Another option in one line:

do ##class(%SYS.Namespace).ListFunc().%Display()

0
Dan Pasco  Nov 8, 2024 to Enrico Parisi

Basically the same as Enrico's:

LATEST:USER>set result = $system.SQL.Execute("select * from %SYS.Namespace_List()")

LATEST:USER>do result.%Display()
Nsp    Status    Remote
%SYS    1    0
B360    1    0
USER    1    0

3 Rows(s) Affected

0
Eduard Lebedyuk · Nov 8, 2024

Local:

Do##class(%SYS.Namespace).ListAll(.result)
0
Joseph Moukhtafi · Dec 2, 2024

you may run the below if needed:

%SYS> zw ^%SYS("Ensemble","RunningNamespace") This will get for you currently running Namespaces

%SYS> zw ^%SYS("Ensemble","InstalledNamespace") This will get current configured Namespaces

%SYS> zw ^CONFIG("Namespaces") This will get current configured Namespaces with the configured globals/routines databases.

0