Delete a cube and its dimensions

Introduction

This article shows you Turbo Integrator code to delete a cube and all of its dimensions. It looks for cases where a dimension is used in other cubes, and if this is the case, the dimension is not deleted. It would generate an error in TM1 anyway as you cannot delete a dimension if it is used in a cube.

Break function

The code uses the Break function to escape out of a loop and avoid unnecessary looping. Other than that, the code is straightforward.

##### # Wim Gielis # http://www.wimgielis.com #####
##### # This code will delete a cube. # Also its dimensions will be deleted as long as they are not used in one or more other cubes # USE THIS CODE WITH CAUTION # It can still be that dimensions are useful even without (not any more) being used in a cube (like lookup dimensions) #####
If( CubeExists( pCube ) = 1 ); # If( Subst( pCube, 1, 1) &<> '}' ); # PART 1: track dimensions of the cube pCube to be deleted i = 1; vDimensionsToDelete = ''; While( Long( Tabdim( pCube, i )) > 0 ); vDimension = Tabdim( pCube, i ); vDimensionCanBeDeleted = 1; # If( Subst( vDimension, 1, 1) &= '}' ); # vDimensionCanBeDeleted = 0; # EndIf; c = 1; While(( c <= Dimsiz( '}Cubes' )) & ( vDimensionCanBeDeleted = 1 )); vCube = Dimnm( '}Cubes', c ); If( Subst( vCube, 1, 1) @<> '}' ); If( Dimix( '}Cubes', pCube ) <> Dimix( '}Cubes', vCube ) ); j = 1; While( Long( Tabdim( vCube, j )) > 0 ); vDimension2 = Tabdim( vCube, j ); If( Dimix( '}Dimensions', vDimension ) = Dimix( '}Dimensions', vDimension2 ) ); vDimensionCanBeDeleted = 0; Break; EndIf; j = j + 1; End; EndIf; EndIf; c = c + 1; End; If( vDimensionCanBeDeleted = 1 ); vDimensionsToDelete = vDimensionsToDelete | vDimension | '\'; EndIf; i = i + 1; End; # PART 2: delete the cube and also the dimensions that were marked for deletion CubeDestroy( pCube ); While( Long( vDimensionsToDelete ) > 0 ); vDimension = Subst( vDimensionsToDelete, 1, Scan( '\', vDimensionsToDelete ) - 1 ); DimensionDestroy( vDimension ); vDimensionsToDelete = Delet( vDimensionsToDelete, 1, Scan( '\', vDimensionsToDelete )); End; # EndIf; EndIf;

Have a look at the treatment of control objects (cubes and dimensions) in the code above because you might want to treat them differently than I do. Consider also the concatenation of dimension names with the \ character, since this character is invalid in a dimension name. Hence, it's the perfect candidate for a concatenation like this !

Enjoy your weekend!




Homepage

Section contents

About Wim

Wim Gielis is a Business Intelligence consultant and Excel expert

Other links