Written by

Question 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

Comments

Robert Cemper · Apr 2, 2022
 
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
USER>zwrite
a("111","444")=99
a("444","111")=77
s1=111
s2=444
USER>

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

0
phillip jack  Apr 2, 2022 to Robert Cemper

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
 
SAMPLES>zw a
a("444"_$c(0),"111"_$c(0))=77
 
SAMPLES>
 
 
 

0
Oliver Wilms · Apr 2, 2022

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

0
phillip jack  Apr 2, 2022 to Oliver Wilms

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

0
Robert Cemper  Apr 3, 2022 to phillip jack

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
a(44)=1
a(111)=2
a("111.")=3
a("44.")=4
0
Steven Hobbs · Apr 4, 2022

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.

0
Julius Kavay  Apr 4, 2022 to Steven Hobbs

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.

0
Steven Hobbs  Apr 4, 2022 to Julius Kavay

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.

0
Steven Hobbs · Apr 4, 2022

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               
1
2
10
"1"
"10"
"2"
abc

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.

0
Hans-Peter Iten · Apr 5, 2022

Do you mean this?:

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

zw TAB
TAB("111"",""444")=""
 

0
Vitaliy Serdtsev · Apr 5, 2022

Can we find out what you need it for?

See Collation

Example:

<FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">sub1</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Collation</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">SqlString</FONT><FONT COLOR="#000000">(111),
 </FONT><FONT COLOR="#800000">sub2</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Util</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Collation</FONT><FONT COLOR="#000000">(444,8)
     
</FONT><FONT COLOR="#0000ff">k </FONT><FONT COLOR="#800000">t
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">sub1</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">sub2</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#008000">""
</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">sub2</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">sub1</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#008000">""
</FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#800000">t</FONT>

Output:

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

0