Question
Bob Ebbert · Sep 29, 2020

cache - for D ^%G , in a program how would I send it the name of the global?

Hi,  Need to run the ^%G command from a program, send it the name of the global and capture the result into a variable,

I need it in a variable so that I can do a FIND on the result.

Thanks,
Bob

10
0 3 95 2

Replies

To list a global (that's what ^%G does) it might be easier to run a FOR loop using $QUERY() function.
example in docs

Hi, Bob
It may be easier to make an analogue of ^% G ?
Something like this:
```
ClassMethod 
AlterG(gn = "", Output rep) As %Status
{
   OPEN 2:$job USE 2
 zwrite @gn ;
 CLOSE 2
 set i="",rep=""
 for set i=$order(^SPOOL($job,i),1,s) quit:i=""
  set rep=rep_s
 }
 KILL ^SPOOL($job)
}

H

There are system utilities that allow you to retrieve a list of globals based on a wildcard.

Here is some code that gets a list of Globals in a namespace. You can modify it to suit your needs:

Method GetGlobalList(ByRef globallist As %String(MAXLEN=3000) = "", globalnameprefix As %String) As %Status
{
    set $ztrap="Error",tSC=$$$OK,globallist=""
    set gbl=""
    for {
        set gbl=$o(^$GLOBAL(gbl)) q:gbl=""
        if globalnameprefix[$p(gbl,".",1) set globallist=globallist_gbl_","
    }
    set globallist=$e(globallist,1,$l(globallist)-1)
End ;
    quit tSC
Error ;
    set $ztrap="",tSC=$$$ERROR(5001,"Code Error: "_$ze) goto End
}

This uses old style $ztrap error handling and would be better written as a TRY/CATCH

I hope this helps

Yours

Nigel