Question
· Jan 9, 2023

How to know the size of a global

Exist some command for return the quantity row of a global?

Example:

^test(1)="aa"
^test(2)="aa"
^test(3)="aa"
^test(4)="aa"

Total rows = 4

Product version: Caché 2018.1
$ZV: 5.659.0
Discussion (10)4
Log in or sign up to continue

If you have multiple subscript levels, this may help:

SET I=0,G="^test("""")" FOR {SET G=$QUERY(@G) Q:G=""  SET I=I+1 WRITE G,!} WRITE "Total: ",I,!

Here's the data:

set ^test(1)="aa"
set ^test(1,1,1)="aa"
set ^test(2)="aa"
set ^test(2,1)="aa"
set ^test(2,2,1)="aa"
set ^test(3,1)="aa"
set ^test(4,1)="aa"

And here's the output:

^test(1)
^test(1,1,1)
^test(2)
^test(2,1)
^test(2,2,1)
^test(3,1)
^test(4,1)
Total: 7

If you only wanted the total (especially if the global is much larger) omit the 'WRITE G,!' portion out of the line of code above.

Hope this helps!

Hi!

Don't know if it's your case, but if you are able to generate the global data, you could use the $INCREMENT() function, which automatically stores the array length into global's head:

Set ^test($INCREMENT(^test)) = "aa"

Set ^test($INCREMENT(^test)) = "aa"

Set ^test($INCREMENT(^test)) = "aa"

Set ^test($INCREMENT(^test)) = "aa"

ZWrite ^test
^test=4
^test(1)="aa"
^test(2)="aa"
^test(3)="aa"
^test(4)="aa"

Write ^test
4

HTH,

José

Sure, the $Increment command can also decrement, and the values don't have to be 'just 1.'

Here's the documentation for the $Increment command:

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_FINCREMENT

Simply, you can do this to decrement by 1:

Set TEMP=$INCREMENT(^test,-1)

If you wanted to increment by 10, the command would be this:

Set TEMP=$INCREMENT(^test,10)

To test, try this:

S ^test=0 F  S TEMP=$INCREMENT(^test,10) Q:$G(^test)>100  W ^test,!

Hope this helps!