Written by

System Analyst at First Line Software
Question Flávio Lúcio Naves Júnior · May 19, 2021

Variable <Undefined> using Xecute command

Hello everyone,

I have a question, I am trying to use xecute command, but something wrong happen when i was using the command, and i don't know why hahahaha.
I created a file .mac with this code:

label(test) public{
       set routine="variable"
       set call="write routine,!"
       xecute call
       quit
}

But when i run the command, show me this message error:

<UNDEFINED>label+3^tstFJR3 *routine

After that i changed the code to:

label(test)
      set routine="variable"
      set call="write routine,!"
      xecute call
      quit

This solved the problem to me, and writed this content:

variable

Someone can explain to me, why this happend? 

Comments

Timothy Leavitt · May 19, 2021

First off, it's generally best to avoid xecute. ;)

In the first case, routine is private (it isn't visible in the xecute stack frame). In the second, it's public, so it is visible there.

You could get the best of both worlds with:

ClassMethod Run()
{
   set routine="variable"
   set call="(routine) write routine,!"
   xecute (call, routine)
   quit
}

For more info see https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KE…

0
Flávio Lúcio Naves Júnior  May 19, 2021 to Timothy Leavitt

I understand, but the text "public" below, don't should solve the problem of visibility?

label(test) public{
}
0
Dmitry Maslennikov  May 19, 2021 to Flávio Lúcio Naves Júnior

This is only for external access to this label, without it, you would not be able to call this from terminal or from another routine or class.

Curly braces makes it private by stack. 

0
Herman Slagman · May 19, 2021

Xecute and indirection (@) are outside of the scope of a procedure.

Change the label to:

label(test) [routine] public

Where [...] is the public-list, those variables are available outside the scope of a procedure.

If you leave out the procedure brackets, all variable are 'globally' availabe.

0