phillip jack · Apr 2, 2022

Subscript with double quoted

Hi Team,

I would like to save the array subscript with in double quotes 

eg sub1=111,sub2=444 (these values are dynamic)

set array(sub1,sub2)=""

It will be saved as array(111,444)=""

but I want to save it as array("111","444")=""

I am trying to save it from the class like """"_sub1_"""" but its not displaying as expected.

Kindly do the need full.

Thanks in Advance

0 216
Discussion (11)2
Log in or sign up to continue
USER>set s1=111,s2=444
USER>set a(s2_$c(0),s1_$c(0))=77
USER>set a($c(0)_s1,$c(0)_s2)=99

"save it from the class " ?  whatever that may mean .... ?

I am trying to save / set the array from the class method.

I have tried the above mentioned code from the terminal but the char value of 0 is not triggered instead of null value its coming as char(0)

SAMPLES>set s1=111,s2=444
SAMPLES>set a(s2_$c(0),s1_$c(0))=77

In Cache or IRIS globals subscripts, numbers do not get quoted. There is no difference between ^GLOBAL(1) and ^GLOBAL("1")

Completely agree !!  but If I want to save the number like a string ( with in quotes) then how can we achieve it ?

To force it to string you have to append some non numeric character ! 
but this one is then part of the subscript as $c(0) or whatever you append
in addition, you break the numeric sort and change to string sorting.

USER>set s1=111,s2=444,q="."
USER>set a(s2)=1,a(s1)=2,a(s1_q)=3,a(s2_q)=4
USER>zw a

You might consider looking at the ##class(%GlobalEdit).Create(...) method.  It has a 'Collation' argument which allows you to change the collation from the namespace default.  Just choose a collation that does *NOT* sort canonical numeric strings in front of non-numeric strings.

I don't recommend ever changing the default collation of a namespace as many utility routines depend on canonical numeric strings sorting in numeric order and not sorting in string order.  Those utilities may not work in such a namespace.

First, as you alread wrote, changing the collation of an already existing installation is dengerious,
second, as far as I know, the database creation page (of ManagementPortal) offers you "Cache/IRIS-standard" and "Cache/IRIS-standard string" only. Nevertheless, changing to "standard string" only affects the collation and not the display, i.e. string subscripts will be displayed quoted but numeric subscripts are not quoted.

I wasn't advocating changing a system collation or changing a namespace collation.  I only recommended using ##class(%Library.GlobalEdit) to change the subscript collation of a newly created individual global variable, leaving all other globals unchanged.

You can see the collations loaded into an instance by executing 'DO  ^|"%SYS"|COLLATE' .  I believe in this case the user wants to use built-in collation 133, which should be the version of collation 5 that sorts only strings and does not sort numbers.  It looks like 133 is now considered to be a "legacy collation" as I have problems finding it in the on-line documentation.

Consider the following:

USER>set num1=1,str1="""1""",num2=2,str2="""2""",num10=10,str10="""10""",abc="abc"

USER>set (x(num1),x(str1),x(num2),x(str2),x(num10),x(str10),x(abc))=""            

USER>set i="" do { set i=$order(x(i))  q:i=""   write i,! } while 1               

The WRITE command treats its expression arguments as ObjectScript string expressions so any argument expression with a numeric value is converted to a string value containing characters.  Note that variables str1 and str2 are strings containing 3 characters starting with one double-quote character, ".  The str1 and str2 values sort among other strings where the first character is a double-quote character.  When you print these subscript strings, the subscripts from variables num1 and num2 print as one character strings,  the subscript from variable num10 prints as a two character string, the subscripts from variables sub1, sub2 and abc print as three character strings and the subscript from variable str10 prints as a 4 character string.

If you use ZWRITE instead of WRITE then ZWRITE will add extra quote marks, will add $C(int) expression syntax and will add other things so that the textual representation that is printed does not contain any unprintable characters and you can see trailing white space.

Do you mean this?:

S sub1=111,sub2=444
S TAB(""_sub1_""","""_""_sub2_"")=""

zw TAB

Can we find out what you need it for?

See Collation


zw t


t(" 111"," 444")=""
t(" 444"," 111")=""