Traverse Global Subscripts while using Indirection
Hi all,
I am trying to create a method to count the number of entries in a global, including all subscripts. I am having a bit of trouble getting the code to make it to the second subscript. When I get to the position where my key is "Canada" and I add a comma and empty quotes to it, it returns USA as the new key when I do the order function. Is the $Order or the global not able to use a single string to represent multiple subscripts?
Here is my global structure:
^Locations("Canada",2)="Vancouver"
^Locations("USA",1)="Michigan"
^Locations("USA",2)="Ohio"
^Locations("USA",3)="Florida"
Here is my method:
ClassMethod RecursiveGlobalCount(pGlobalName As %String, pKey As %String, pCount As %Integer) As %Integer
{
///if pCount is not populated set to zero for first run
if $Data(pCount)=0
{
set tCount = 0
}
else
{
set tCount = pCount
}
//pKey should only be undefined on first run
if $Data(pKey)=0
{
set tKey = $Order(@pGlobalName@(""))
w $Data(@pGlobalName@(tKey))
while tKey'=""
{
//check to see if global has descendents
if $Data(@pGlobalName@(tKey))=10
{
do ..RecursiveGlobalCount(pGlobalName,tKey,tCount)
}
set tKey = $Order(@pGlobalName@(tKey))
set tCount=tCount+1
}
}
else
{
set tKey = pKey
if ($Data(@pGlobalName@(tKey))=1)
{
set tKey=""
set tKey = $Order(@pGlobalName@(""))
while tKey'=""
{
set tKey = $Order(@pGlobalName@(tKey))
set tCount=tCount+1
}
}
elseif ($Data(@pGlobalName@(tKey))=10)
{
set tKey=pKey_","""""
set tKey = $Order(@pGlobalName@(tKey))
while tKey'=""
{
set tKey = $Order(@pGlobalName@(tKey))
set tCount=tCount+1
}
}
}
}