Generate a flat view in the beginning of a TI process

Ideas and tips for enhancing your TM1 application
Post Reply
User avatar
DevGreg
Posts: 14
Joined: Tue Sep 09, 2008 4:12 pm

Generate a flat view in the beginning of a TI process

Post by DevGreg »

Here is a little TI code I often use to generate a flat view on a cube.

I base my TI on the "Default" view, so that I can declare correctly my variables.
Then I use this bit of TI code to regenerate the source view, as needed.

I also sometimes use it to call the ViewZeroOut function instead of using it to define the source view.

Anyway, please look inside the code, during the loop on every dimension, I included an exception for a specific dimension, because you might want to restrain your view to a specific version if your cube contains such a dimension, etc...

Code: Select all

#---------------------------------
# TI process to create a flat view
#---------------------------------

vCube = 'MyCube';
vTemp = '_CustomName';

If (ViewExists(vCube, vTemp) = 1);
	ViewDestroy(vCube, vTemp);
EndIf;
ViewCreate(vCube, vTemp);

vIndex = 1;
While (TABDIM(vCube, vIndex) @<> '');
	vDim = TABDIM(vCube, vIndex);

		If (SubsetExists(vDim, vTemp) = 1);
			SubsetDestroy(vDim, vTemp);
		EndIf;
		SubsetCreate(vDim, vTemp);

		# Change the next two lines for specific conditions on a dimension
		
		If (vDim @= 'SpecificDim');
			SubsetElementInsert(vDim, vTemp, 'SpecificElement', 1);
		Else;
			SubsetIsAllSet(vDim, vTemp, 1);
		EndIf;

		ViewSubsetAssign(vCube, vTemp, vDim, vTemp);
		ViewRowDimensionSet(vCube, vTemp, vDim, vIndex);

	vIndex = vIndex + 1;
End;

# Change flag for the 3 next lines to exclude (1) or include (0) consolidations, zeroes, and rules

ViewExtractSkipCalcsSet(vCube, vTemp, 1);
ViewExtractSkipZeroesSet(vCube, vTemp, 1);
ViewExtractSkipRuleValuesSet(vCube, vTemp, 1);

DataSourceType = 'VIEW';
DatasourceNameForServer = vCube;
DatasourceCubeview = vTemp;
And in the Epilog, you can destroy all these temporary objects by doing:

Code: Select all

If (ViewExists(vCube, vTemp) = 1);
   ViewDestroy(vCube, vTemp);
EndIf;
vIndex = 1;
While (TABDIM(vCube, vIndex) @<> '');
	vDim = TABDIM(vCube, vIndex);
	If (SubsetExists(vDim, vTemp) = 1);
		SubsetDestroy(vDim, vTemp);
	EndIf;
	vIndex = vIndex + 1;
End;
Last edited by DevGreg on Thu Sep 18, 2008 8:33 am, edited 1 time in total.
Post Reply