Ti Process (and lifecycle of a variable in it....)

Post Reply
Lorna
Posts: 15
Joined: Wed Jan 26, 2011 5:25 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Ti Process (and lifecycle of a variable in it....)

Post by Lorna »

Hi guys

I have a TI process....in the Prolog I want to do a once off calc to derive a date (in a different format) from which I am reading in from the cube.

Now....

1. I dont quite understand the 'lifetime' of a variable..meaning...if I define a variable in the "Variables" tab, does it get initialised every time it passes thru the Data tab?
2. If a variable is NOT defined in the "Variables" Tab....i e I define it in the code - what is the difference between a variable defined in code and one defined in the "variables" tab.
3. In my code - the initial CellgetN statement in the Prolog tab - is EXACTLY in the same format as in the Data tab. Although, upon execution, I get an error saying "Invalid Dimension - abank". I dont get it....why does it complain about it in the Prolog tab and not in the data tab??

Please have a look at the code. It works 100% in the Data tab, but then obviously, I get as many results as there are rows in my cell subset. So - I only want to execute in once...hence the prolog tab. BUT...in the prolog tab, my answer is blanks (as opposed to the Data tab)

Please help - I dont think I understand the difference between variable usage in the two tabs.

Code: Select all

Prolog tab...

#****Begin: Generated Statements***
#****End: Generated Statements****

cellgetn('atm test', 'Volume', abank,ateamno, acentre, teamtype,'Totkm',aregion, adate);

IF (subst(adate,5,2) @= '01') ;
     tmpmonth = 'Jan';
Elseif   (subst(adate,5,2) @= '02') ;
     tmpmonth = 'Feb';
ELSEIF (subst(adate,5,2) @= '03') ;
     tmpmonth = 'Mar';
ELSEIF (subst(adate,5,2) @= '04') ;
     tmpmonth = 'Apr';
ELSEIF (subst(adate,5,2) @= '05') ;
     tmpmonth = 'May';
ELSEIF (subst(adate,5,2) @= '06') ;
     tmpmonth = 'Jun';
ELSEIF (subst(adate,5,2) @= '07') ;
     tmpmonth = 'Jul';
ELSEIF (subst(adate,5,2) @= '08') ;
     tmpmonth = 'Aug';
ELSEIF (subst(adate,5,2) @= '09') ;
     tmpmonth = 'Sep';
ELSEIF (subst(adate,5,2) @= '10') ;
     tmpmonth = 'Oct';
ELSEIF (subst(adate,5,2) @= '11') ;
     tmpmonth = 'Nov';
ELSEIF (subst(adate,5,2) @= '12') ;
     tmpmonth = 'Dec';
ENDIF;

testdate = tmpmonth | ' - ' | subst(adate,1,4) ;
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:

Re: Ti Process (and lifecycle of a variable in it....)

Post by Alan Kirk »

Lorna wrote:Hi guys

I have a TI process....in the Prolog I want to do a once off calc to derive a date (in a different format) from which I am reading in from the cube.

Now....

1. I dont quite understand the 'lifetime' of a variable..meaning...if I define a variable in the "Variables" tab, does it get initialised every time it passes thru the Data tab?
Both the Metadata tab, and the Data tab. If you've defined this variable using the [Formula] button on the variables tab you should see generated code to do that; for instance, a variable defined as V2 containing a random number and with a Contents type of "Other" will produce this code on both tabs:

Code: Select all

#****Begin: Generated Statements***
V2=Rand();
#****End: Generated Statements****
Lorna wrote:2. If a variable is NOT defined in the "Variables" Tab....i e I define it in the code - what is the difference between a variable defined in code and one defined in the "variables" tab.
Effectively both end up being defined in code; the only question is whether you do it manually, or TI does it for you.
Lorna wrote:3. In my code - the initial CellgetN statement in the Prolog tab - is EXACTLY in the same format as in the Data tab. Although, upon execution, I get an error saying "Invalid Dimension - abank". I dont get it....why does it complain about it in the Prolog tab and not in the data tab??
Please re-read the process structure description that I gave you in this thread, specifically:
I wrote:
  • The execution flow of a TI process is as follows (this answers your second question):
    1. The prolog tab code executes once, when the process first triggers. This will run regardless of whether there is any data in your data source, or indeed whether there is a data source. Any constant value (and this answers question 3 of your post) should therefore be declared here. The value will be available on all of the following tabs.
Because the Prolog tab executes before any data is read, none of the process variables (the ones that appear on the Variables tab, as opposed to ones that you declare in the Prolog tab itself) have any context, meaning or values for code that appears on it. In other words, you can't use a function which refers to a data source variable (such as your CellGetN) in the Prolog tab because on the Prolog tab they have no value. If you want to do a CellGetN on the Prolog tab you have to manually tell TI what the element names that you want to use are. The data source variables can't do that, because those variables won't have a value until the first line of code of the Metadata tab or Data tab is executed, as the case may be.
"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.
Lorna
Posts: 15
Joined: Wed Jan 26, 2011 5:25 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Re: Ti Process (and lifecycle of a variable in it....)

Post by Lorna »

Thanx Alan

So if I understand your correctly, if I want to do a cellGetN in the Prolog tab, I'd have to do it in the format

CellgetN('myfield','mycube', abank.....)

The element name is abank (specifically referring to that one). That is...if in Architect I expand the dimensions for the cube, that shows up as the first one.
How should I refer to it then? In quotes?

Or...if that is not possible...how can I force an execution of code in the Data tab, to only execute once since I only want to get this new format date, once, for every iteration of this whole TI process

Sorry once again for the stupid questions! Ive been thrown into the deep end and I need to swim -):

thanx!
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:

Re: Ti Process (and lifecycle of a variable in it....)

Post by Alan Kirk »

Lorna wrote:Thanx Alan

So if I understand your correctly, if I want to do a cellGetN in the Prolog tab, I'd have to do it in the format

CellgetN('myfield','mycube', abank.....)

The element name is abank (specifically referring to that one). That is...if in Architect I expand the dimensions for the cube, that shows up as the first one.
How should I refer to it then? In quotes?
Yes. If a word in your TI code is inside single quotes, it's a literal string. If it's not, TI takes it as a variable name.
"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.
Lorna
Posts: 15
Joined: Wed Jan 26, 2011 5:25 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Re: Ti Process (and lifecycle of a variable in it....)

Post by Lorna »

Hi Alan

After our discussion I changed my code to this...

Code: Select all

cellgetn('atm test', 'Volume', 'abank','ateamno', 'acentre', 'teamtype','Totkm','aregion', 'adate');

IF (subst('adate',5,2) @= '01') ;
     tmpmonth = 'Jan';
ENDIF;

testdate = tmpmonth | ' - ' | subst('adate',1,4) ;

ASCIIOutput('if.txt',testdate);
What I'm getting in my output file is ...." - adat" - and I am still getting the error "Invalid key dimension name "bank", Element name (key) "abank"I was hoping more in the line of "Jan - 2010". :P

What am I doing wrong?

Thanx
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:

Re: Ti Process (and lifecycle of a variable in it....)

Post by Alan Kirk »

Lorna wrote:Hi Alan

After our discussion I changed my code to this...

Code: Select all

cellgetn('atm test', 'Volume', 'abank','ateamno', 'acentre', 'teamtype','Totkm','aregion', 'adate');

IF (subst('adate',5,2) @= '01') ;
     tmpmonth = 'Jan';
ENDIF;

testdate = tmpmonth | ' - ' | subst('adate',1,4) ;

ASCIIOutput('if.txt',testdate);
What I'm getting in my output file is ...." - adat" - and I am still getting the error "Invalid key dimension name "bank", Element name (key) "abank"I was hoping more in the line of "Jan - 2010". :P

What am I doing wrong?

Thanx
The CellGetN has to use the names of one element in each dimension, not the dimension names. Reading your earlier post more closely it appears that you're doing the latter. (I thought you meant that you expanded the dimension list, then opened the dimension to get the first element.) Values are stored at the intersection of one element from each dimension. That's what CellGetN does; retrieves the value at the "coordinates" specified by the element names.
"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
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:

Re: Ti Process (and lifecycle of a variable in it....)

Post by Alan Kirk »

Lorna wrote:Hi Alan

After our discussion I changed my code to this...

Code: Select all

cellgetn('atm test', 'Volume', 'abank','ateamno', 'acentre', 'teamtype','Totkm','aregion', 'adate');

IF (subst('adate',5,2) @= '01') ;
     tmpmonth = 'Jan';
ENDIF;

testdate = tmpmonth | ' - ' | subst('adate',1,4) ;

ASCIIOutput('if.txt',testdate);
What I'm getting in my output file is ...." - adat" -
Also, subst('adate',5,2) is never going to return '01'. as I said, by enclosing it in quotes you're making it a literal string. Consequently it is always going to return 2 characters, starting at the 5th one. Which, in this case, will be "e" since it has only 5 characters to start off with. Rather than trying to fathom the syntax, it might be better to explain where the date that you're trying to use is supposed to come from. My suspicion is that it's from the data source, in which case you need to do your test, using variables, on the Data tab. But without knowing what it is that you're trying to achieve there's no way to be sure.
"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.
Lorna
Posts: 15
Joined: Wed Jan 26, 2011 5:25 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Re: Ti Process (and lifecycle of a variable in it....)

Post by Lorna »

I understand why that substring is returnining what it is.

Yes, I am trying to process data that I will be reading from the Data tab.

My data on the data tab is in the line of (these are now the dimension names....)..Abank, Aregion,Adate etc etc. Now, depending on what is in the FIRST line of the info, more specific the Date, I need to derive the date value that I can use to look up the Rate for this line...hence, the substring on the date.

I dont need/want to do this in the Data tab, cause this only needs to be done once. If I do it in the data Tab, it will execute N.....times.

Hope this sheds more light on what I want to do
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:

Re: Ti Process (and lifecycle of a variable in it....)

Post by Alan Kirk »

Lorna wrote:I understand why that substring is returnining what it is.

Yes, I am trying to process data that I will be reading from the Data tab.

My data on the data tab is in the line of (these are now the dimension names....)..Abank, Aregion,Adate etc etc. Now, depending on what is in the FIRST line of the info, more specific the Date, I need to derive the date value that I can use to look up the Rate for this line...hence, the substring on the date.

I dont need/want to do this in the Data tab, cause this only needs to be done once. If I do it in the data Tab, it will execute N.....times.

Hope this sheds more light on what I want to do
As previously discussed, the Prolog executes before the first line of data so you won't have that line of data until the Data tab code starts. (Assuming that there's no code on the Metadata tab, and if there was that will execute N times as well.) The Data tab will execute all of its code for each record (unless some code is ItemSkipped, which doesn't apply here).

But what you can do, if you need the date from the first row and the first row alone, is to declare a variable on the Prolog tab of:

Code: Select all

l_RowNo=0;
Then make your first line of code in your Data tab

Code: Select all

l_RowNo=l_RowNo+1;
You can then put your date evaluation code inside an If() block, testing for whether l_RowNo=1 and executing the block only where that is true.

If you assign your calculated date to a variable inside that block, it will remain available for every record in the Data tab's code.
"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.
Lorna
Posts: 15
Joined: Wed Jan 26, 2011 5:25 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Re: Ti Process (and lifecycle of a variable in it....)

Post by Lorna »

Thanx you're a star!
Post Reply