Global Variable Scope in TI; a Public Service Announcement

Post Reply
User avatar
Alan Kirk
Site Admin
Posts: 6606
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Global Variable Scope in TI; a Public Service Announcement

Post by Alan Kirk »

OK, this one is a little bit me not reading the manual fully and properly, and a little bit whoever wrote the manual not being correct in the details.

I have a series of processes which consists of a master process (process 010) which calls worker processes (process 100, 110 and possibly 120). Process 010 defines various global variables so that the worker processes can populate them and pass them down the line. It is the one and only process defined in a chore which runs overnight, every night. The other processes are called (or not) by 010 via ExecuteProcess().

In summary:
  • Process 100 grabs a list of all new payruns from the payroll system via ODBC, and writes their details into a Payruns cube.
  • Process 110 scans through those payruns to check for any anomalies, and also compiles a list of the payruns which have been paid but not yet uploaded into the reporting cube. It stores that list in a delimited global string variable, because it's not like we have arrays or dictionaries, much less objects in TI, is it IBM??
  • If that string is empty, the chore's nightly work is done, and it ends.
  • Otherwise, process 120 is called. Process 120 does a pull of the payrun data (again by ODBC) for all of the payruns listed in the global string that process 110 populated. It runs a validation process to check for errors such as invalid element names, employees who don't have master data, etc. If it finds any, it will write out error logs, or, if the data is bad but there is a known workaround, it will write advisory logs. (Eg if an entry uses an invalid account number, but the process knows what the right one is, it writes a log saying "For this entry I'll use account 123456 instad of ThisIsAStuffedAccount.")
Now here's the thing. The upload to the reporting cube is only ever triggered manually, once the process above has confirmed that there are no critical errors.

I ran that on Saturday morning.

But during the Saturday night, and the Sunday night, the payrun process kept generating the advisory warnings.

Except those payruns had been uploaded, so process 110 should not have been finding any new payruns to check, meaning that process 120 should not run, meaning that there should be no advisory logs.

Why were the logs there?

I ran the 010 process manually. It correctly stopped after process 110.

I ran the chore. It called process 120, which it should not have.

This is what the manual has to say about Global Variables:
IBM wrote:Global variables can be declared within a process that is part of a given chore. Once declared, the global variables are available to all other processes that are part of the chore.
Yup, uh-huh, I knew that...
IBM wrote:The variables persist while the chore is executing
Yup, knew that too.
IBM wrote:and for the duration of the current server session. Global variables are destroyed upon server shutdown.
Uh-oh.

Except... this isn't entirely true. I've been using global variables for years and have never come up against this problem. The difference is that:
(a) With most global variables I've explicitly initialised them each session; with this one I didn't; and
(b) A lot of the processes in which I use globals are not scheduled constantly.

And that's the key. The information above is wrong. The values do NOT persist for the duration of the server session. They do however persist for processes which are called as part of a chore... as long as that chore remains scheduled. That's why when I ran process 010 independently, there was no value in that variable, while there WAS a value when I ran the chore before I turned the chore schedule off. HOWEVER, as soon as I turned off the chore scheduling and ran the chore again... the variable was clear, because the value was dropped.

So, remember boys and girls, when you use global variables? Explicitly declare the value of the damn things so that the value will never carry over from a previous run.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
User avatar
gtonkin
MVP
Posts: 1202
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Global Variable Scope in TI; a Public Service Announcement

Post by gtonkin »

Been caught out before with a chore reporting failures each day. Running the process was fine though.
Turned out to be exactly this, old value retained from chore to chore each day.
After Initialising in the first process's Prolog, all smooth.
Post Reply