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
To list a global (that's what ^%G does) it might be easier to run a FOR loop using $QUERY() function.
example in docs
It may be easier to make an analogue of ^% G ?
Something like this:
```
ClassMethod AlterG(gn = "", Output rep) As %Status
{
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:
{
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