› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Access Global variable
Rick,
Where do you want to reference it from?
email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.
I want to create the global in a proc and access it in a copy command inside the xlate tool if possible. The proc is located in the pre-xlate.
Rick,
I am not sure if that will work however, this should work:
In the pre_xlate proc place the data you want in the metadata USERDATA field (I use a keyed list but you can do whatever you want). Then get the value for the keyed list enty from the USERDATA metadata field of the message in the Xlate with an xltp type proc.
email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.
Yes it will work since they run in the same interprter. You can access the variable by declarining it global in both places or giving it a namespace path like ::gvar.
I have done this on many occasions
Charlie,
Thanks that is good to know. I have never had a need to do what Rick is trying but I have used the USERDATA when I wanted something I set in the inbound thread to be known in an outbound thread.
email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.
thank guys ! One last thing do i need to null out the global once i am finished with it.
Depends on what you mean by null out.
To set to empty string: set ::gvar “”
To destroy it: unset -nocomplain ::gvar
Rick,
Do you want to reset with each message or after some event has occurred?
email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.
after i use it in the xalte
Regarding my answer to Jim Koslosky concerning the use of globals in the Xlate thread, I got this response from one of the developers:
FYI, this will not work in 5.8. The interp used in the xlate was hardcoded which killed things in threaded xlates so Tcl fragments in the xlate no longer run in the same interp as the pre/post Tps.
Therefore, for forward compatibility, you best choice to communicate would be as Jim suggested and use the USERDATA meta field of the message.[/quote]
I was going to mention that using a global variable solution is riskier and less robust because it makes an assumption that creates a denpendancy that might not hold up over time.
Now that Charlie has already come up with such an example I’m willing to add my voice to this concern.
Here is a URL with a tanglible example to help show how to value the USERDATA metatadata in an xlate and retrieve the value in an outbound thread that is even in a different process.
<a href="https://usspvlclovertch2.infor.com/viewtopic.php?t=1367&” class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=1367&
Russ Ross
RussRoss318@gmail.com
Thanks guys!!
An instance where I have used a global in the Xlate thread, was in using a global across multiple interfaces, but all in the same process. My specific example was tracking patients’ room and bed. I could have used a file on disk, or database, but instead, I used memory. Updates were written to disk (to support startup), but ‘reads’ came from the global which was shared across multiple ‘Xlates’ …. saved some disk I/O.
Dennis
Oh, Ya, after reading another ‘thread’ .. I realized that we also do this for database connections…
If the connection exisits, we use the global… which is shared amoungst all Xlates in the same process.
Dennis