· Mar 17, 2022

How to write "zwrite" output to $$$TRACE?

SET ^||fruit(1)="apple",^||fruit(4)="banana",^||fruit(8)="cherry"
SET ^||fruit(1,1)="Macintosh",^||fruit(1,2)="Delicious",^||fruit(1,3)="Granny Smith"
SET ^||fruit(1,2,1)="Red Delicious",^||fruit(1,2,2)="Golden Delicious"
SET ^||fruit="Fruits"
ZWRITE ^||fruit

^||fruit(1,2,1)="Red Delicious"
^||fruit(1,2,2)="Golden Delicious"
^||fruit(1,3)="Granny Smith"

How I do send the output of zwrite to $$$TRACE()?

Product version: IRIS 2021.2
Discussion (4)1
Log in or sign up to continue

I'm quite shure, the above code won't work as expected, or with the words of Joseph Weizenbaum: “A computer will do what you tell it to do, but that may be much different from what you had in mind.”

The content of your myf variable is always 0 (the result of comparing nullstring with a filename), the size of tmpFile stream is also 0 (you never write into the stream).

Sometimes it's faster to write a "oneliner" to solve a simple problem then searching and downloading a solution from openexchange or from whereever... That's the beauty of the ObjectScript.

And if you think, the oneliner is worth to be reused, then make it to a method, add some small adjustments for a general usability...

The oneliner

s str="",tmp=##class(%File).TempFilename("txt") o tmp:"NWRU":0 i $t { u tmp zw ^||fruit s s=$zpos r:'$zseek(0) str#s c tmp:"D" }

The more general version

ClassMethod ToString(ref,max=32000)
    s tmp=##class(%File).TempFilename("txt") o tmp:"NWRU":0 q:'$t ""
    u tmp zw @ref s siz=$zpos r:'$zseek(0) str#$s(siz>max:max,1:siz) c tmp:"D" q str

Use it as

write ##(your.class).ToString($na(^||fruit))