Delete all consolidated elements

Post Reply
chesteronrada
Posts: 6
Joined: Sat Oct 25, 2008 3:13 am
OLAP Product: IBM Cognos TM1
Version: 9.0 - 9.1 - 9.5.1 - 9.5.2
Excel Version: 2003

Delete all consolidated elements

Post by chesteronrada »

Hi...
need help with my TI...
i have this code to delete all consolidated elements(elements with type 'C') from my Product Dimension.

#######################
DimName = 'ProductDim';
eCnt = DIMSIZ(DimName);
x=1;
WHILE(x<=eCnt);
ElName = DIMNM(DimName,x);
IF(DTYPE(DimName,ElName)@='C');
DimensionElementDelete(DimName, ElName);
ENDIF;
x=x+1;
END;
#######################

but it does not work on a one time run. i have to run this a couple of times to make it work T_T
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Delete all consolidated elements

Post by Alan Kirk »

chesteronrada wrote:Hi...
need help with my TI...
i have this code to delete all consolidated elements(elements with type 'C') from my Product Dimension.

#######################
DimName = 'ProductDim';
eCnt = DIMSIZ(DimName);
x=1;
WHILE(x<=eCnt);
ElName = DIMNM(DimName,x);
IF(DTYPE(DimName,ElName)@='C');
DimensionElementDelete(DimName, ElName);
ENDIF;
x=x+1;
END;
#######################

but it does not work on a one time run. i have to run this a couple of times to make it work T_T
It's because you're counting forward, so every time you delete a consolidation it changes the DimNm index position of the next element.

Suppose that you have a dimension which has the following elements at index positions 1 to 5:
1/ N element 1
2/ C element 1
3/ C Element 2
4/ N Element 2
5/ C element 3

What will happen is that when x=2, you'll delete C element 1. However in doing so you cause C Element 2 to move up to index position 2. But because you've increased x by 1 in the loop, the next element it will look at is the new element 3, which will be N Element 2. Effectively C Element 2 is never checked, which is why it's not deleted in the first pass.

The solution?

Instead of counting forward, count backward from the end of the dim. The deletions will therefore never change the index order of the elements that the loop has yet to look through.

Code: Select all

DimName = 'ProductDim';

eCnt = DIMSIZ(DimName);

x = eCnt;

WHILE( x >= 1 );

   ElName = DIMNM( DimName,x);

   IF( DTYPE( DimName,ElName) @= 'C');
      DimensionElementDelete( DimName, ElName);
   ENDIF;

   x = x - 1;

END;

"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
chesteronrada
Posts: 6
Joined: Sat Oct 25, 2008 3:13 am
OLAP Product: IBM Cognos TM1
Version: 9.0 - 9.1 - 9.5.1 - 9.5.2
Excel Version: 2003

Re: Delete all consolidated elements

Post by chesteronrada »

noted... :shock:
i am sure still is a newbie :D
thanks a lot!
Post Reply