· 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.


Discussion (3)0
Log in or sign up to continue


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