Written by

Question Lynn Lantz · Jun 25, 2024

How to send WRITE formatted output to a variable

I'm trying to keep all writes in local memory.

If you have    S %A="""HI THERE"",!,#,33.33,"" "",$ZTIMESTAMP"

and you         O 2 U 2 W @%A C 2 ZW ^SPOOL                    
^SPOOL(1,1)="HI THERE"_$c(13,10)
^SPOOL(1,2)=$c(13,12)
^SPOOL(1,3)="33.33 67016,59246.6188873"

It works just fine and the output is in the ^SPOOL global. 

However, I'm trying to avoid writing to disk.

I can't find anything besides using the SPOOL device that will allow the use of the "@" indirection.

I tried using streams but it will not allow @indirection.  Neither will set, or execute, or anything.

Is there any easy way to just set a variable to the formatted write output that the @indirection creates??

Thanks!

Product version: IRIS 2022.1

Comments

Yaron Munz · Jun 26, 2024

The @ (indirection) is not used only to write to a device (spool is a special type of device with number 2).
You may use the @ (indirection) to set any variable, array, list, object property or stream, while keeping this in memory:

S %A="""HI THERE"",!,#,33.33,"" "",$ZTIMESTAMP"
S %B=@A
S %C("key1","key2")=@A
 
0
Lynn Lantz  Jun 26, 2024 to Yaron Munz

Sorry but that is just not true.   You cannot SET %B=@%A,  you always get a syntax error.

0
Robert Cemper  Jun 26, 2024 to Lynn Lantz

because of output formatting with !, # , ?n

0