CellGetN and CellPutN issue

Post Reply
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

CellGetN and CellPutN issue

Post by BariAbdul »

I am using CellGetN and CellPutN to add a numeric value in the Cube.When cube is empty and although I have defined variable value 500 ,When it should show '0+500' as 500 it still shows 0 when I open the Cube view,But when I enter manually 1 in the targeted cells and runs again It shows 1001 taking in to account the previous value. Could someone Please help me what could be the reason? Thanks.

Code: Select all

nVariable= 500;
NewElement=CellGetN('CellCube','ProductA','CustomerA','RegionA',cmeasures);
CreatedVariable=nVariable +NewElement ;
CellPutN( CreatedVariable , 'CellCube','ProductA','CustomerA','RegionA',cmeasures); 
Last edited by Alan Kirk on Wed Mar 05, 2014 5:57 am, edited 1 time in total.
Reason: Formatting corrected; you can't use colour (or most) tags inside Code blocks.
"You Never Fail Until You Stop Trying......"
Alan Kirk
Site Admin
Posts: 6667
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: CellGetN and CellPutN issue

Post by Alan Kirk »

BariAbdul wrote:I am using CellGetN and CellPutN to add a numeric value in the Cube.When cube is empty and although I have defined variable value 500 ,When it should show '0+500' as 500 it still shows 0 when I open the Cube view,But when I enter manually 1 in the targeted cells and runs again It shows 1001 taking in to account the previous value. Could someone Please help me what could be the reason? Thanks.

Code: Select all

nVariable= 500;
NewElement=CellGetN('CellCube','ProductA','CustomerA','RegionA',cmeasures);
CreatedVariable=nVariable +NewElement ;
CellPutN( CreatedVariable , 'CellCube','ProductA','CustomerA','RegionA',cmeasures); 
The obvious issues:
(a) There's no way that the code that you're describing is going to create a value of 1001 from a base value of 1 unless you're either running it twice or you have the same code on both the Metadata and Data tabs. Or haven't supplied the real code in your question. Speaking of which, you haven't indicated which tab(s) you do have the code on.
(b) The fact that it doesn't do anything when the value is 0 but does when the value is 1 suggests that you have a data source issue. Speaking of which, you haven't indicated the data source either but I'm betting that it's a cube view. If that is indeed the case you most likely have zeroes suppressed on the view. (And if you don't, that's probably unwise given the number of possible combinations.) If that's the case, then when the original value is 0 it's probably not part of your data source. When it's 1, it is.

If it's not part of the data source, then your code will never be executed for that combination.
"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.
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Re: CellGetN and CellPutN issue

Post by BariAbdul »

[quote(a) There's no way that the code that you're describing is going to create a value of 1001 from a base value of 1 unless you're either running it twice or you have the same code on both the Metadata and Data tabs. Or haven't supplied the real code in your question. Speaking of which, you haven't indicated which tab(s) you do have the code on][/quote]

Thanks a lot ,Alan,As always you are spot on.
You are right I have to run it twice to get 1001 and I did had it in metadata and data tab but when eliminated from metadata tab I was still having the same issue.Now the code is in the Data tab.
(b) The fact that it doesn't do anything when the value is 0 but does when the value is 1 suggests that you have a data source issue. Speaking of which, you haven't indicated the data source either but I'm betting that it's a cube view. If that is indeed the case you most likely have zeroes suppressed on the view
b)You are also correct that it is View as a source,In fact I have created the view from the same cube and used it as a source.It has no zero suppressed on, Could it be due to the fact this cube was empty with zero values is cause of the issue.
If that's the case, then when the original value is 0 it's probably not part of your data source. When it's 1, it is.

If it's not part of the data source, then your code will never be executed for that combination.
My apologies,I am not getting what you are actually trying to say here.Thanks a lot again.
"You Never Fail Until You Stop Trying......"
User avatar
Steve Rowe
Site Admin
Posts: 2464
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: CellGetN and CellPutN issue

Post by Steve Rowe »

What I think Alan is getting at is the following.

A. You have the cell that you are updating set to the data source of your TI.
B. The Metadata and Data tab is processed once for every (usually non-zero) row in the data source.

So if you start off with your cell =0 and then run the TI then the data and metadata tab is not executed at all and so your cell =0 at the end.

If you start off with the cell = 1 then your code executes twice, once each on the metadata and data tabs, leaving you with 1001.

You say "It has no zero suppressed on", I'm guessing that you suffering from the difference between a cube viewer view and a data source view, although they are broadly similar they are fundamentally different objects. So if your cube viewer view has been set as a data source and you have saved it with zero suppression off, this does not mean that your data source is zero suppressed.

To access the view as a data source definition you need to right click on the view object and select "Export as Text " (or maybe ASCII) and set the view up in this dialogue box. To set up a brand new one right click on the cube object itself.

The above view confusion is a long standing issue that IBM (and Applix and Cognos) have not addressed.

Anyway, hope this helps you understand what is going on.

Cheers,
Technical Director
www.infocat.co.uk
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Re: CellGetN and CellPutN issue

Post by BariAbdul »

Thanks Alan and Steve,It makes sense now,Appreciate your help.
"You Never Fail Until You Stop Trying......"
PlanningDev
Community Contributor
Posts: 349
Joined: Tue Aug 17, 2010 6:31 am
OLAP Product: Planning Analytics
Version: 2.0.5
Excel Version: 2016

Re: CellGetN and CellPutN issue

Post by PlanningDev »

FYI you no longer need to peform a CellGetN to variable and then use (Value + CellGetN Variable). There is a new function as of version 10 called CellIncrementN which will peform this operation for you.

1 less line of code right!
Post Reply