Question
· Feb 27

How to find Routine Mappings programmatically?

The goal is to identify programmatically all SOURCE namespaces on a server to which the routines are mapped. In the example below from the Namespaces page in Management Portal the answer would be USER. But some other namespaces on the same server could be mapped to a different namespace or even mapped to itself.

This code snippet prints all namespaces and source namespaces for their routines.
zn "%SYS"
set statement=##class(%SQL.Statement).%New()
set status=statement.%PrepareClassQuery("Config.Namespaces","List")
set resultset=statement.%Execute()
while resultset.%Next() {
    w %objcsd(1,13), $C(9),%objcsd(1,18),!
}

 

Product version: Caché 2017.1
Discussion (6)2
Log in or sign up to continue

Maybe (likely!) I misunderstood your question.

What do you mean with "But some other namespaces on the same server could be mapped to a different namespace or even mapped to itself." ?

A namespace cannot be mapped to another namespace.

A namespace definition consists of default database for globals, default database for "routines" (all code) and optionally global/package/routine mappings to different databases. (Plus some default system mapping)

You already answered your question....in the question! 😊

From %SYS namespace, use the List class query in the Config.Namespaces class:

%SYS>Set ResultSet=##class(Config.Namespaces).ListFunc()
 
%SYS>Do ResultSet.%Display()
Namespace       Globals Routines        System Globals  System Routines LibraryTemp Storage
%ALL    %DEFAULTDB      %DEFAULTDB      IRISSYS IRISSYS IRISLIB IRISTEMP
%SYS    IRISSYS IRISSYS IRISSYS IRISSYS IRISLIB IRISTEMP
USER    USER    USER    IRISSYS IRISSYS IRISLIB IRISTEMP
 
5 Rows(s) Affected
%SYS>

 Or, if you prefer:

%SYS>Set statement=##class(%SQL.Statement).%New()
 
%SYS>Set status=statement.%PrepareClassQuery("Config.Namespaces","List")
 
%SYS>Set resultset=statement.%Execute()
 
%SYS>While resultset.%Next() {  Write resultset.%Get("Namespace"),$c(9),resultset.%Get("Globals"),$c(9),resultset.%Get("Routines"),!}
%ALL    %DEFAULTDB      %DEFAULTDB
%SYS    IRISSYS IRISSYS
USER    USER    USER
 
%SYS>