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;
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;