Yes, this is the correct behavior. Section "function: Define a Named
Task" in the STAX User's Guide at
http://staf.sourceforge.net/current/STAX/staxug.html#Header_Function talks
about a functions scope attribute as follows:
scope - specifies the scope of the function. It is a literal and, if
specified, must be set to either global or local. It is optional and the
default is global.
global - the function uses the same namespace so that the effects of
variables defined/changed inside the function are global (within the same
STAX-Thread).
local - the function provides a nested namespace which localizes the
variables it uses. All variables assigned in a function are local to that
function and exist only while the function runs. Variables previously
defined in other functions with a global scope are still visible, however,
any changes to these variables or new variables created are not visible to
the caller after the function completes, unless the variable is an
instance of the STAXGlobal class. Changes to STAXGlobal variables persist
after a function completes.
The branch variable is visible to the "Try" function, but if the "Try"
function made any changes to the branch variable, these changes would not
be visible to the caller "main" function after the function completes. For
example, if you changed the "Try" function as follows to assign a new
value (e.g. 'XXX") to the branch variable and then after the "main"
function calls the "Try" function, if it accessed the value of the branch
variable, it would not reflect the new value that the "Try" function
assigned (since the "Try" function has a local scope and the branch
variable is not an instance of the STAXGlobal class).
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<script>
BUILD = 'MainBuild'
</script>
<defaultcall function="main"/>
<function name="main" scope="local">
<sequence>
<script>
if BUILD == 'MainBuild':
branch = ''
else:
branch = '_cbgvbvb'
</script>
<call function="'Try'"/>
<log message="1">'main: branch=%s' % (branch)</log>
</sequence>
</function>
<function name="Try" scope="local">
<sequence>
<log message="1">'Try: branch=%s' % (branch)</log>
<script>branch = 'XXX'</script>
</sequence>
</function>
</stax>
The STAX Job User log after running this job would show:
Date-Time Level Message
----------------- ----- -------------
20150625-13:22:40 Info Try: branch=
20150625-13:22:40 Info main: branch=
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
From: "Zhu, Cindy" <cindy....@ihs.com>
To: "staf-users@lists.sourceforge.net"
<staf-users@lists.sourceforge.net>
Date: 06/25/2015 12:57 PM
Subject: [staf-users] Scope of variables in the Main function
Hi,
I am wondering what the scope of variables declared is in the Main
function.
I have the following simple STAX job:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "D:\DistributedTesting\stax.dtd">
<stax>
<script>
BUILD = 'MainBuild'
</script>
<defaultcall function="main"/>
<function name="main" scope="local">
<sequence>
<script>
if BUILD == 'MainBuild':
branch =
''
else:
branch =
'_cbgvbvb'
</script>
<call function="'Try'"/>
</sequence>
</function>
<function name="Try" scope="local">
<log message="1">branch</log>
</function>
</stax>
In this simple STAX job ran on STAF 3.4.7 onwards, the value of variable
“branch” was passed into the sub function “Try” without passing argument
to the function.
Is it the correct behaviour?
Thanks,
Cindy Zhu
Senior SQA Engineer
Quality Assurance
Phone: 1 403 213 4231
cindy....@ihs.com
IHS | Information | Analytics | Expertise
www.ihs.com
This email message is for the sole use of the intended recipient(s) and
may contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply e-mail and destroy
all copies of the original message. Thank you.
Please consider the environment before printing this e-mail.
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors
network devices and physical & virtual servers, alerts via email & sms
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users