How to Discover What's Inside the Global?

Primary tabs

Greetings,

If given a global, how can I discover information on that global?  More specifically,  how can I discover how many indices it contains?  ie:  ^G(1,2,3,4,5)   How can I discover that there are 5 subscripts within the Global ^G if I did not already know.

Please advise, and thanks in advance for everyone's time.

  • 0
  • 0
  • 230
  • 2
  • 1

Answers

That seems to be a very specific question. What is the actual problem you're trying to solve?
(on a sidenote, check out $QUERY, which allows you to do what you are asking for)

If I an given a global, ^G, how can I discover how many subscripts are included?  In other words, how can I determine if the global has 3, 5, 7, ect... or more subscripts?  If I want to $Order through the global I would need to know how many subscripts as I build my code to read the elements, correct?

f  s x1=$o(^G(x1))  d...

f  s x2=$o(^G(x1,x2))  d...

f  s x3=$o(^G(x1,x2,x3)  d...

How can I determine by looking at some type of meta data for a given global, that I have 3, 5, or whatever subscripts?

Please advise,

Thanks...

You can use $query as Fabian suggested along with indirection this will allow you to traverse the global without the need of creating a recursive call.

You can use $qlength along with $query to discover how deep (how many subscripts) you are in the global.

You can use $qsubscript along with an index to fetch it's name.

There's a sample within the $query documentation.

Also, $order uses the lastest subscript you provided to find the next one. So, no, you don't need to know how many subscripts you have. But you need to know when to stop.

I suggest you to check [@Sergey Kamenev]'s articles for a deep understanding about globals.