Question
· Jan 26

Can globals exist without SQL access?

Hello everyone,

My team lead mentioned that users can sometimes create globals directly without associating them with tables or classes. In this case, these globals would not be accessible via SQL.

Is this correct? Can a global exist independently in this way, and if so, is there a specific approach to access or manage them without SQL?

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

Yes, globals can exist independently without any association with SQL tables or classes, and in such situations, they wouldn't be accessible via SQL. Globals are a unique storage structure in InterSystems IRIS, serving as persistent multidimensional sparse arrays. These can be directly manipulated with ObjectScript or other programming languages compatible with IRIS, allowing the creation of custom data structures not adhering to relational or object models. Without SQL integration or object class mapping, such globals are strictly managed at the global level [1][2].

Sources:


Globals can be defined and accessed directly using a caret (^) symbol. For example, you can set or access a global with: 

// define a global by setting a value
set ^GlobalName = "Hello World"
// Access different sub-nodes 
set ^GlobalName(1, "foo") = "bar"
// You access the global in a similar way
write ^GlobalName // prints Hello World
// write all global values
zwrite ^GlobalName
// ^GlobalName = "Hello World"
// ^GlobalName(1,"foo") = "bar"

This can be useful for quickly saving values globally or looking up values.

I recommend having a look at the Using Caché Globals section of the Cache documentation because it has far more information on globals usage than could be relayed in a comment.