Written by

Question Pedro Lopes · Jul 26, 2023

How do I retrieve the name of the first GLOBAL from within the GLOBAL directory?

How do I retrieve the name of the first GLOBAL from within the GLOBAL directory?
Should I use some syntax with $Order or $Query or is there another way?

Comments

Alexander Neuber · Jul 26, 2023

Hi, look at ^$GLOBAL

GLOB   
  SET NAME=""
  WRITE !,"The following globals are in ",$NAMESPACE
  FOR I=1:1 {
    SET NAME=$ORDER(^$GLOBAL(NAME))
    WRITE !,NAME
    QUIT:NAME=""
    SET GLOBAL(I)=NAME
  }
  WRITE !,"All done"
  QUIT

I hope it is what you need

0
Julius Kavay · Jul 26, 2023

As others already wrote,

write $order(^$GLOBAL(""))

gives you the first global name accessible from a given namespace. Usually, this will be a percent-global (^%...) but if you want to get the first (or all) global, which resides in a given database, the do the same as above but with extended global access

set dir = "^^c:\databases\mydb\"  // "^^" and "the path to your CACHE/IRIS.dat file"
write $order(^$|dir|GLOBAL(""))
0