Dynamic variables

Post Reply
r0b1979
Posts: 6
Joined: Wed Aug 01, 2012 9:47 pm
OLAP Product: TM1, SQL Server
Version: 9.5.2
Excel Version: 2007 2010

Dynamic variables

Post by r0b1979 »

Hi all,

I was wondering if it was somehow possible to generate or declare variables dynamically within a TI process. Say, i would like a loop to generate a new variable, but only if a condition is met. As an example i think of looping through cube-dimensions and assign a variable (SrcDim1 -> SrcDimN) and give them the current Dimension name as value.

Simplified example:

DimCount=1;
While(TABDIM(SrcCube, DimCount) @<>'');
CurDim = TABDIM(SrcCube, DimCount);
SrcDim | Dimcount = CurDim;
DimCount = DimCount + 1;
END;

Obviously this 'concatenation' of SrcDim and DimCount wouldn't work, but i was wondering if there is any way to achieve this. I have searched extensively and did not find any workable solution that actually creates new variables when and only if needed. I only found general code which works for a fixed maximum number of (in this case) dimensions.

So, since I believe this is actually not possible I was about to give up on this idea. But of course i wouldn't do this without consulting all of your valuable experience...Anyone with a solution or workaround? Or confirmation that this IS indeed impossible?

Thx and regards,
Rob
User avatar
mattgoff
MVP
Posts: 516
Joined: Fri May 16, 2008 1:37 pm
OLAP Product: TM1
Version: 10.2.2.6
Excel Version: O365
Location: Florida, USA

Re: Dynamic variables

Post by mattgoff »

I don't believe it's possible, and I believe this is generally frowned upon even in languages which can do it (arrays or hashes are preferred, not that they're available in TM1 either. Even Fortran had arrays FFS).

Matt
Please read and follow the Request for Assistance Guidelines. It helps us answer your question and saves everyone a lot of time.
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Dynamic variables

Post by tomok »

There is a little box on the top right called Search. Type in "dynamic variables" and click on the Search button.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
r0b1979
Posts: 6
Joined: Wed Aug 01, 2012 9:47 pm
OLAP Product: TM1, SQL Server
Version: 9.5.2
Excel Version: 2007 2010

Re: Dynamic variables

Post by r0b1979 »

@mattgoff
Thanks for your reply and i believe you're right. Was hoping for a solution though.

@tomok
Off course i did that, and obviously i did not find the answer i was looking for or i would have saved myself the trouble of opening a new topic. I apologise if I have missed some previous discussion regarding the same issue.
lotsaram
MVP
Posts: 3702
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Dynamic variables

Post by lotsaram »

I think Tom might have been referring to this topic on Indirect Variables (as opposed to "dynamic variables"). Which you can find if you know what you're looking for.

I don't think there is a way to dynamically create variables as such. The best you can do is to explicitly create/declare each any every member of an "array" in advance to the maximum number of variables you might need and dynamically grab the variable name and value using the Expand function at runtime.

However what you can do dynamically is create temporary dimensions, elements and data and use these like you would a "dynamic array variable".
User avatar
Steve Rowe
Site Admin
Posts: 2456
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: Dynamic variables

Post by Steve Rowe »

If you really need an array like structure in a TI why not use a cube? It's pretty much an identical structure and can be built on the fly. I posted some code an age ago for creating array cubes.

Cheers,
Technical Director
www.infocat.co.uk
r0b1979
Posts: 6
Joined: Wed Aug 01, 2012 9:47 pm
OLAP Product: TM1, SQL Server
Version: 9.5.2
Excel Version: 2007 2010

Re: Dynamic variables

Post by r0b1979 »

@Lotsaram/Steve,

Thanks for the suggestions, i am going to look into arrays in temporary dimensions/cubes, see if that could help. I don't have a specific case but was just looking for ways to simplify creation of new TI Processes.

Regards,
Rob
User avatar
Harvey
Community Contributor
Posts: 236
Joined: Mon Aug 04, 2008 4:43 am
OLAP Product: PA, TM1, CX, Palo
Version: TM1 8.3 onwards
Excel Version: 2003 onwards
Contact:

Re: Dynamic variables

Post by Harvey »

If I need small arrays, I often use a comma separated list and parse it using SCAN and SUBST. It's pretty easy once you get used to it.

If you want examples, the easiest way is to dig into Bedrock's open source TI processes. Here's an example, adapted from the Dim.Sub.Create.ByElement process:

Code: Select all

pDelimeter = ',';
sElements = 'A,B,C,D,E,F';
nDelimIndex = 1;

# Split filter into seperate dimensions
While( nDelimIndex <> 0 & Long( sElements ) > 0 );
  nDelimIndex = Scan( pDelimiter, sElements );
  If( nDelimIndex <> 0 );
    sElement = Trim( SubSt( sElements, 1, nDelimIndex - 1 ) );
    sElements = Trim( SubSt( sElements, nDelimIndex + Long( pDelimiter ), Long( sElements ) ) );
  Else;
    sElement = Trim( sElements );
  EndIf;
End;
Bedrock is also a very good way to speed up TI development in general. You can get it here.
Take your TM1 experience to the next level - TM1Innovators.net
r0b1979
Posts: 6
Joined: Wed Aug 01, 2012 9:47 pm
OLAP Product: TM1, SQL Server
Version: 9.5.2
Excel Version: 2007 2010

Re: Dynamic variables

Post by r0b1979 »

Good suggestions Lazarus, they look helpful. Thank you.
Post Reply