Question
· Aug 4, 2023

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") = ""

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
Discussion (6)2
Log in or sign up to continue

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