Access Global variable

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Access Global variable

  • Creator
    Topic
  • #51247
    Rick Pritchett
    Participant

    Is there any way to access a global variable created by a proc in an xlate?

Viewing 13 reply threads
  • Author
    Replies
    • #69345
      Jim Kosloskey
      Participant

      Rick,

      Where do you want to reference it from?

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #69346
      Rick Pritchett
      Participant

      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.

    • #69347
      Jim Kosloskey
      Participant

      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 29+ years Cloverleaf, 59 years IT - old fart.

    • #69348
      Charlie Bursell
      Participant

      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

    • #69349
      Jim Kosloskey
      Participant

      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 29+ years Cloverleaf, 59 years IT - old fart.

    • #69350
      Rick Pritchett
      Participant

      thank guys !  One last thing do i need to null out the global once i am finished with it.

    • #69351
      Charlie Bursell
      Participant

      Depends on what you mean by null out.

      To set to empty string:  set ::gvar “”

      To destroy it:  unset -nocomplain ::gvar

    • #69352
      Jim Kosloskey
      Participant

      Rick,

      Do you want to reset with each message or after some event has occurred?

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #69353
      Rick Pritchett
      Participant

      after i use it in the xalte

    • #69354
      Charlie Bursell
      Participant

      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]

    • #69355
      Russ Ross
      Participant

      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="http://clovertech.infor.com/viewtopic.php?t=1367&&#8221; class=”bbcode_url”>http://clovertech.infor.com/viewtopic.php?t=1367&amp;

      Russ Ross
      RussRoss318@gmail.com

    • #69356
      Rick Pritchett
      Participant

      Thanks guys!!

    • #69357
      Dennis Pfeifer
      Participant

      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

    • #69358
      Dennis Pfeifer
      Participant

      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

Viewing 13 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,297
Replies
34,440
Topic Tags
287
Empty Topic Tags
10