Article
· Aug 10, 2023 3m read

Remote Global Listing using NativeAPI for ObjectScript #2

As noted in the previous article Native API has some limits.
So I did some research on a more Terminal-like interface that
provides me with access like a console or the IRIS terminal
to allow my  $QUERY over a global and other nice commands
that are not supported/mapped in NativeAPI for ObjectScript.

The basic tools are well-prepared and available.

  • Connection() creates a fully operational and stable partition for me
  • Function() allows calling any routine or method I need
  • similar ClassMethodValue and ClassMethodVoid

There is just no method CommandLine and some already prepared code is needed.

My simple approach: Send the  code and let it eXECUTE
It is just a 1-liner to mimic a single command line

;; routine %ZX.int
x(%rcc) try {return $xecute(%rcc)} catch %rcc {return %rcc.DisplayString()}

If you don't have access to some programming tool you may use this
Stored Procedure from MgmtPortal/SQL for installation:

CREATE PROCEDURE %Zrcc.X()
LANGUAGE OBJECTSCRIPT
{
 set %rcc=##class(%Routine).%New("%ZX.int")
 set %rccline="x(%rcc) try {return $xecute(%rcc)} catch %rcc {return %rcc.DisplayString()}"
 do %rcc.WriteLine(%rccline)
 do %rcc.Save()
 quit %rcc.Compile()
}

And next you need your connection object

ClassMethod Connect(
    serverIP = "192.168.0.9",
    serverPORT = 1972,
    namespace = "USER",
    username = "_SYSTEM",
    password = "SYS") As %Net.DB.Iris
{
  try {
    set %rccon=##class(%Net.DB.DataSource).CreateConnection(serverIP
                           ,serverPORT,namespace,username,password)
    set %rccdb=%rccon.CreateIris()
    }
  catch { zw  b  }  ;; do some error handling
  quit %rccdb
}

Now a few preliminary examples using method Function
CON is my CommectionObject

USER>write CON.Function("%ZX","","quit $job")
1920

The 3rd argument will always return something as %RawString
And if something fails:

USER>write CON.Function("%ZX","","set x=27,y=0 quit x/y ; will fail")
<DIVIDE> 18 x^%ZX

and this is a simple Remote Global Lister.
Then making a copy or renaming is a rather trivial task:

gl ; list remote Global
  set global="^dc.MultiD"  ;; adjust as required
  set a=CON.Function("%ZX","","quit $LB($D("_global_",%rcc),%rcc)")
  Write !,global," = ",$li(a,2)," $DATA = ",$li(a),!
  if $li(a)#10 {
    for { 
      set a=CON.Function("%ZX","","q $LB($q(@$zr),@$ZR)")
      quit:$li(a)=""
      write $li(a), " = "
        ,##class(%Utility).FormatString($li(a,2)),! 
      }
    }
 Write "-------done----------",!

The focus is on getting all control local and just 1 call by Global node
Test action:

USER>do ^gl
 
^dc.MultiD = 5 $DATA = 11
^dc.MultiD(1) = $lb("Braam,Ted Q.",51353)
^dc.MultiD(1,"mJSON") = "{}"
^dc.MultiD(2) = $lb("Klingman,Uma C.",62459)
^dc.MultiD(2,2,"Multi","a") = 1
^dc.MultiD(2,2,"Multi","rob",1) = "rcc"
^dc.MultiD(2,2,"Multi","rob",2) = 2222
^dc.MultiD(2,"Multi","a") = 1
^dc.MultiD(2,"Multi","rob",1) = "rcc"
^dc.MultiD(2,"Multi","rob",2) = 2222
^dc.MultiD(2,"mJSON") = "{""A"":""ahahah"",""Rob"":""VIP"",""Rob2"":1111,""Rob3"":true}"
^dc.MultiD(3) = $lb("Goldman,Kenny H.",45831)
^dc.MultiD(3,"mJSON") = "{}"
^dc.MultiD(4) = $lb("","")
^dc.MultiD(4,"mJSON") = "{""rcc"":122}"
-------done----------

Of course, there are a lot of other activities than just Global listing possible
You may take a look into the ages-old Global ^% to get a feeling,
what programming with XECUTE + $XECUTE() can do.


BTW:
this is not a contribution to ePy contest
  😉
 

Discussion (1)1
Log in or sign up to continue