Question

Say I have Caché ObjectScript procedure that expects to receive a by reference array parameter:

TotalArray(Arr)
 S Total=0
 S K=""
 F {
  S K=$O(Arr(K))
  Q:K=""

  S Total=Total+Arr(K)
 }
 Q Total

I can call that procedure with a regular array by reference with the dot syntax:

S A(1)=5
S A(2)=10
W $$TotalArray(.A)

But when I try to do it with a global reference, I get a syntax error with the dot syntax:

S ^A(0)=5
S ^A(1)=10
W $$TotalArray(.^A)

What is the correct way to pass a global array by reference to an ObjectScript procedure? I also want to be able to pass process private globals (the ^||Array convention)

Was it helpful?

Solution

If you use it with indirection as Brandon suggested:

TotalArray(ArrName)
 S Total=0
 S K=""
 F {
  S K=$O(@ArrName@(K))
  Q:K=""

  S Total=Total+@ArrName@(K)
 }
 Q Total

and then you call it like this

W $$TotalArray("^A")

or even

W $$TotalArray("^A(""someIndex"")")

OTHER TIPS

This is not possible. You could either

  1. Pass the name of the global, and access it by Indirection, or
  2. MERGE the global into a local variable (if it is small enough), and pass that by reference.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top