Help with dynamic Xecute in curly brackets
Typically, I have time to review the documentation, which I'm sure is here. However, I have a workaround (TEST1) but I was wondering if anyone could assist me in advising how I would need to adapt the curly brace snippet (TEST2) to provide the same result.
Thanks for any help you can provide.
TEST1(STATUS=1) K (STATUS)X "S MSG=$S(STATUS:""HELLO"", 1:""GOODBYE"")"W !,MSGQTEST2(STATUS=1) PUBLIC {X "S MSG=$S(STATUS:""HELLO"", 1:""GOODBYE"")"W !,MSG}Discussion (3)1
Comments
2 possible solutions:
TEST3(STATUS=1) [STATUS,MSG] PUBLIC {
X "S MSG=$S(STATUS:""HELLO"", 1:""GOODBYE"")"
W !,MSG
}
X "S MSG=$S(STATUS:""HELLO"", 1:""GOODBYE"")"
W !,MSG
}
TEST4(%STATUS=1) PUBLIC {
X "S %MSG=$S(%STATUS:""HELLO"", 1:""GOODBYE"")"
W !,%MSG
}
X "S %MSG=$S(%STATUS:""HELLO"", 1:""GOODBYE"")"
W !,%MSG
}
see also my article Summary on Local Variable Scoping
Have you considered using $xecute?
Version:1.0 StartHTML:00000092 EndHTML:00001371 StartFragment:00000172 EndFragment:00001337 CachÙ Studio clip Class User.Exec [ Abstract ]{ClassMethod test(STATUS = 1) As %String{set greeting = $xecute("(STATUS) { return $S(STATUS:""HELLO"", 1:""GOODBYE"") }",STATUS)return greeting}}and here is this code in action:
PANTHER:XEP:DEV>w ##class(Exec).test() HELLO PANTHER:XEP:DEV>w ##class(Exec).test(0) GOODBYE
TEST1(STATUS=1)
N MSG
X ("(IN,OUT) S OUT=$S(IN:""HELLO"", 1:""GOODBYE"")",STATUS,.MSG)
W !,MSG
Q
TEST2(STATUS=1) PUBLIC {
X ("(IN,OUT) S OUT=$S(IN:""HELLO"", 1:""GOODBYE"")",STATUS,.MSG)
W !,MSG
}