Hi Guys,
Not sure if this was already discussed here. $o is giving me different results depending if I use local variable (array) or a global when I use strings bigger than 18 characters. For example:
S ^A("12345678901234567890")=""
S B=""
F S B=$O(^A(B)) Q:B="" W !,B
12345678901234567890
And this is ok. Now using array instead of global:
S A("12345678901234567890")=""
S B=""
F S B=$O(A(B)) Q:B="" W !,B
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
...
It seems to me that $O is converting my string to a numeric and truncating it on position 18 (because of the 18 digits accuracy for numeric).
Is there any workaround for this issue? I've tested this in both 5.4 and 5.3.
Cheers,
P
Yes, you are most likely correct that it has to do with the number-precision/string-conversion issue(s). Obviously, it's a really bad idea to use subscripts like that. If you are going to I think that using $Query() might be a viable option:
TEST> k A s A("12345678901234567890")="",A(99)="",A("12345678901234567890def")=""
TEST> s B="A" F i=1:1:10 S B=$Q(@B) Q:B="" zwr B
B="A(99)"
B="A(""12345678901234567890"")"
B="A(""12345678901234567890def"")"
Your best bet is to just ensure that the subscripts are ALWAYS treated as strings:
TEST> k A s A("\12345678901234567890")="",A("\"_99)="",A("\12345678901234567890def")="" s B="" F i=1:1:10 S B=$O(A(B
)) Q:B="" zwr B
B="\12345678901234567890"
B="\12345678901234567890def"
B="\99"
But, the slickest (slimy-est?) workaround I found is:
TEST-oes> k A s A("12345678901234567890")="",A(99)="",A("12345678901234567890def")="" s B="" F i=1:1:10 S B=$O(A(B)) Q:B
="" s c=+B zwr B
B=99
B="12345678901234567890"
B="12345678901234567890def"
Go figure...
-bob