企业绩效管理网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2702|回复: 9

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

[复制链接]

86

主题

397

帖子

596

积分

高级会员

Rank: 4

积分
596
QQ
发表于 2014-6-29 17:29:38 | 显示全部楼层 |阅读模式
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: 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) ;

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

86

主题

402

帖子

589

积分

高级会员

Rank: 4

积分
589
QQ
发表于 2014-6-29 18:50:41 | 显示全部楼层
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: #****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):

    • 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.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

73

主题

375

帖子

530

积分

高级会员

Rank: 4

积分
530
QQ
发表于 2014-6-29 19:27:00 | 显示全部楼层
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!
回复 支持 反对

使用道具 举报

91

主题

437

帖子

644

积分

高级会员

Rank: 4

积分
644
QQ
发表于 2014-6-29 19:55:54 | 显示全部楼层
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.
回复 支持 反对

使用道具 举报

81

主题

411

帖子

598

积分

高级会员

Rank: 4

积分
598
QQ
发表于 2014-6-29 20:19:07 | 显示全部楼层
Hi Alan

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

Code: 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".   

What am I doing wrong?

Thanx

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

77

主题

412

帖子

590

积分

高级会员

Rank: 4

积分
590
QQ
发表于 2014-6-29 20:25:54 | 显示全部楼层
Lorna wrote:Hi Alan

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

Code: 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".   

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.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

74

主题

421

帖子

580

积分

高级会员

Rank: 4

积分
580
QQ
发表于 2014-6-29 20:33:47 | 显示全部楼层
Lorna wrote:Hi Alan

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

Code: 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.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

93

主题

423

帖子

630

积分

高级会员

Rank: 4

积分
630
QQ
发表于 2014-6-29 20:48:27 | 显示全部楼层
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
回复 支持 反对

使用道具 举报

83

主题

421

帖子

617

积分

高级会员

Rank: 4

积分
617
QQ
发表于 2014-6-29 21:13:08 | 显示全部楼层
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: l_RowNo=0;
Then make your first line of code in your Data tab
Code: 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.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

76

主题

403

帖子

586

积分

高级会员

Rank: 4

积分
586
QQ
发表于 2014-6-29 21:55:58 | 显示全部楼层
Thanx you're a star!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|企业绩效管理网 ( 京ICP备14007298号   

GMT+8, 2023-9-25 14:02 , Processed in 0.059450 second(s), 12 queries , Memcache On.

Powered by Discuz! X3.1 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表