Article
· Nov 7 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.

Discussion (4)3
Log in or sign up to continue