How to create a global node, without knowing the number of keys in advance ?
Hello,
I would like to do the following :
set name = $name(^A)
for i=1:1:10
{
set $qsubscript(name, i) = "TEST"_i //dream code that does not work
}
set @name = "" //will create ^A("TEST1", "TEST2", "TEST3", ... , "TEST10") = ""
ObjectScriptObjectScript
Unfortunately, unlike $PIECE(), $QSUBSCRIPT() is not bidirectional.
Is there a way to do what I described, in a clean way ? (something supported by the system)
I would like to avoid :
- using a custom made solution (eg: appending keys one by one to a string, adding commas when needed) unless it's failproof (eg: can deal with commas in keys, non string keys, ...)
- having code that do multiple writes to database (eg: code that create ^A("TEST1") then ^A("TEST1", "TEST2"), ... sequentially. That's inefficient and not what I want.
Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT
set name = $name(^A) for i=1:1:10 { set name = $name(@name@("TEST"_i)) } set @name=""
By the way, you can also "shorten" a given node and start over...
// from the above example, // name = ^A("TEST1","TEST2", ... "TEST10") // now we take that global with the first two subscripts set name = $name(@name,2) // and add new subscripts set name = $name(@name@(3333,4444)) set @name = "new data"
Try it and then ZWRITE ^A to see the effect
Thanks. Do you have any reference to the official documentation for this @something@ syntax ?
EDIT : found it. It's called Subscript Indirection.
Would it be possible for you to share your reason for wanting to do this with the community?
For debugging reasons : I wanted to dump the stack to a global, to find out from where some piece of code was called.
there is a standard utility %ETN that writes such logs with the stack
and all other $system variables into the global ERRORs
if you call it by LOG^%ETN it does a kind of snapshot
details here take a look