TI for creating array cubes

Ideas and tips for enhancing your TM1 application
Post Reply
User avatar
Steve Rowe
Site Admin
Posts: 1688
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: 10.2.2., PAW
Excel Version: Nearly all of them

TI for creating array cubes

Post by Steve Rowe » Wed May 05, 2010 4:02 pm

Something I wrote in order to create array cubes, it's designed to be called from within another TI process. I don't think that I ended up using it in the end so it's possible there are a few wrinkles.

EDIT : You also need a dimension called ValueString, this contains a numeric element called Value and a string element called String. This allows the array to hold numbers or strings.

To build a 2d array called MyArray that is 100 x 1 you'd call the TI in the following way. The 1 bit comes from the ValueString dimension.

Code: Select all

ans=ExecuteProcess('ADMIN - Create Array Cube',
'Suffix' , 'MyArray',
'CreateDelete1or0', 1,
'ElementsInD1',100,
'ElementsInD2',0,
'ElementsInD3',0,
'ElementsInD4',0);
To delete the array once you are done with it. (Note that the values for the ElementsInDX parameters are not relevant for this call)

Code: Select all

ans=ExecuteProcess('ADMIN - Create Array Cube',
'Suffix' , 'MyArray',
'CreateDelete1or0', 0,
'ElementsInD1',100,
'ElementsInD2',0,
'ElementsInD3',0,
'ElementsInD4',0);
I don't seem to be able to add the file so here is the code

Prolog

Code: Select all

#TI to create an arraycube
ElType='N';
InsertionPoint='';

If(CreateDelete1or0=1);
#Creation section

#Dim 1
ixCount=1;
DimName=Suffix | '1';
DimensionCreate(DimName);

#Populate the dimension
While (ixCount <= ElementsInD1);
    DimensionElementInsert(DimName, InsertionPoint, NumberToString(ixCount), ElType);
    ixCount=ixCount+1;
End;

#Dim2
If (ElementsInD2>0);
   ixCount=1;
   DimName=Suffix | '2';
   DimensionCreate(DimName);

#Populate the dimension
While (ixCount <= ElementsInD2);
    DimensionElementInsert(DimName, InsertionPoint, NumberToString(ixCount), ElType);
    ixCount=ixCount+1;
End;

EndIf;

#Dim3
If (ElementsInD3>0);
   ixCount=1;
   DimName=Suffix | '3';
   DimensionCreate(DimName);

#Populate the dimension
While (ixCount <= ElementsInD3);
    DimensionElementInsert(DimName, InsertionPoint, NumberToString(ixCount), ElType);
    ixCount=ixCount+1;
End;

EndIf;

#Dim4
If (ElementsInD4>0);
   ixCount=1;
   DimName=Suffix | '4';
   DimensionCreate(DimName);

#Populate the dimension
While (ixCount <= ElementsInD4);
    DimensionElementInsert(DimName, InsertionPoint, NumberToString(ixCount), ElType);
    ixCount=ixCount+1;
End;

EndIf;

#Create the Cube
If (ElementsInD4>0);
   CubeCreate (Suffix, Suffix | '1', Suffix | '2', Suffix | '3', Suffix | '4', 'ValueString');
ElseIf(ElementsInD3>0);
   CubeCreate (Suffix, Suffix | '1', Suffix | '2', Suffix | '3', 'ValueString');
ElseIf(ElementsInD2>0);
   CubeCreate (Suffix, Suffix | '1', Suffix | '2', 'ValueString');
ElseIf(ElementsInD1>0);
   CubeCreate (Suffix, Suffix | '1', 'ValueString');
EndIf;

#End of creation section
EndIf;
Epilog

Code: Select all

#Deletion Section

If(CreateDelete1or0=0);
RefDimName='}Dimensions';
   CubeDestroy(Suffix);
   If ( Dimix( RefDimName, Suffix |'1')>0);
       DimensionDestroy(Suffix |'1');
   EndIf;
   If ( Dimix( RefDimName, Suffix |'2')>0);
       DimensionDestroy(Suffix |'2');
   EndIf;
   If ( Dimix( RefDimName, Suffix |'3')>0);
       DimensionDestroy(Suffix |'3');
   EndIf;
   If ( Dimix( RefDimName, Suffix |'4')>0);
       DimensionDestroy(Suffix |'4');
   EndIf;
#End of delete section.
EndIf;
Screeenshot of parameter definitions, the TI has no data source
para.gif
para.gif (7.57 KiB) Viewed 1532 times
I have a vague recollection of putting this up before put I couldn't see it when I searched.

Anyway if anyone finds a use for the code you're welcome!
Cheers

Post Reply