Question Norman W. Freeman · 8 hr ago

How to write at the end of a global ? (last node)

I have a global with multiple nodes : 

^A("ABC") = ""
^A("DEF") = ""
^A(123) = ""

How to create a new single node in that global, in a way it's always at the end of the global (eg: this will be the very last node being enumerated)

I end up with this code but maybe there is a cleaner and simpler approach : 

set ^A($char(65535)) = "" //should be bigger than any character inserted

I only need to write it once, this code is not intended to be used in a loop or something, just to add something at the end (like a footer).
Usually, the naked global would contains the key of the last node, but that's not something I can do in this case (my procedure is called by legacy code that I have no control over) 

set ^A = 1000
set ^A($I(^A)) = "" //will do set ^A(1001) = ""
Product version: IRIS 2024.1
$ZV: IRIS for Windows (x86-64) 2024.1.2 (Build 398U) Thu Oct 3 2024 14:01:59 EDT

Comments

Enrico Parisi · 7 hr ago

One option could be:

Set last=$o(^A(""),-1)

Set ^A(last_"z")="new last value"

In fact you can concatenate anything, not necessarily a "z"..

If the first subscript is always numeric, then:

Set last=$o(^A(""),-1)

Set ^A(last+1)="new last value"

0
Robert Cemper · 6 hr ago

The idea of 

set ^A($char(65535)) = ""

Looks good at first sight, but this might be the next follower

set ^A($char(65535),0) = ""
0