Globals QuickStart

time to complete
10 minutes

InterSystems IRIS® data platform contains an extremely efficient data model known as globals. Individually, a global is a persistent multidimensional array. Data added to globals is immediately stored and available to multiple processes, not just the process that stored it.

The benefits of using globals are vast. Globals are:

  • Efficient: They grow based on need, without upfront declaration of size or structure.
  • Multi-model: They store objects, tables and indexes, JSON and XML documents, even documentation.
  • Typeless: They can contain integer, named, or any other subscript type, even at the same subscript level.
  • Automatically sorted: They sort subscripts automatically at each dimension.
  • Flexible: They allow flexibility in node structure and data storage to contain any number of subscripts and any type of data.
  • Safe: You can lock any node to keep other processes from changing value, while keeping other nodes at same level accessible.

Note that globals are not just another storage model. In fact, they are so powerful and flexible that they are actually at the core of all InterSystems models, giving you freedom from database remodels.

Interested in seeing it for yourself? Check out the exercise below.

Launch the development sandbox and click the Management Portal link to begin.

Globals’ typeless nodes provide great flexibility

  1. First, make sure you have an instance of InterSystems IRIS and an IDE ready to go.
    Need InterSystems IRIS?
    Get a free, online development sandbox here. Log in with your InterSystems login account, or register for one below.
  2. In the IDE, use the menu at the top to navigate to the InterSystems IRIS terminal. Select InterSystems Web Terminal. Create the following globals (Hint: You can copy all lines at once and paste!):
    set ^Stock("dress", 4, "blue", "floral") = 52
    set ^Stock("dress", 8, "green", "solid") = 10
    set ^Stock("dress", 4, "blue", "striped") = 7
    set ^Stock("dress", 4, "blue", "solid") = 117
    set ^Stock("dress", "location") = "aisle A"

    Here, you are storing this data directly to InterSystems IRIS in your own custom structure. This example contains one node for each pattern and an additional node for the location of the dresses in the store. Notice the subscripts within a global ("dress" and 4) can have different types. Furthermore, subscripts even within the same position (4 and "location") can also have different types, supporting your ability to dynamically and efficiently store sparse and varied data.

Globals are automatically sorted and easy to retrieve

  1. To easily see if there are any size 4 blue dresses with a floral pattern, you can access the correct data node by executing:
    write ^Stock("dress", 4, "blue", "floral")
  2. This data is automatically sorted and easy to filter. View globals of only size 4 dresses, automatically sorted, by entering into Terminal:
    zwrite ^Stock("dress",4)

Globals are easy and performant

  1. Display the amount in stock of all size 4 blue dresses simply by iterating through all of the data nodes below the ^Stock("dress", 4, "blue") node.
  2. Copy and paste the following line and execute it in Terminal:
    set key = "" for { set key =
    $order(^Stock("dress",4,"blue",key))  quit:key=""  write !
    ,key_":"_$get(^Stock("dress",4,"blue",key)) }
  3. Unrelated nodes, such as the location of dresses, are not touched, optimizing the performance of the retrieval. Note that while you can run this in one line, a slightly more formatted version of this breaks down the key aspects of this code:
    Code snippet. Six lines of code.
    set key = “”
    for {
    set key = $order(^Stock(“dress”,4,”blue”,key))
    write ! ,key_”:”_$get(^Stock(“dress”,4,”blue”,key))
    Legend. 4 items. $order: Function to loop through nodes. “dress”,4,”blue”: base node. !: New line.key_”:”_$get(^Stock(“dress”,4,”blue”,key)): String concatenation of the key, a literal colon, and the value of each node.
  4. To exit the InterSystems Terminal, type halt.
Up Next
Globals Deep Dive
time to complete
10 minutes