Im just trying to verify something when Im running a while loop in a TI.
Currently Im looping a dimension and looking for any elements that have more than 1 parent. If they have more than one parent then I want to remove the component from all parents after the first one.
The issue I have is that when you delete an element from a consolidation then the element no longer has the same number of parents. During the while loop you are looking at the parent index which is changed if you delete the element from a consolidation.
Is this a true statement? and if so then do you simply delete 1 from the parent count if you perform a delete instead of adding 1 to the index during the loop?
While Loop Parent Counts with Component Delete
-
- Community Contributor
- Posts: 349
- Joined: Tue Aug 17, 2010 6:31 am
- OLAP Product: Planning Analytics
- Version: 2.0.5
- Excel Version: 2016
-
- Community Contributor
- Posts: 126
- Joined: Sun Jun 29, 2008 9:33 am
- OLAP Product: TM1
- Version: 10.2.2
- Excel Version: 2016
- Location: Karlsruhe
Re: While Loop Parent Counts with Component Delete
Yes, this is correct, the indices (for your ELPAR check) of your parents are changing. To avoid it you could use a backward instead of a forward loop through your ELPARs and stop before the first parent.The issue I have is that when you delete an element from a consolidation then the element no longer has the same number of parents. During the while loop you are looking at the parent index which is changed if you delete the element from a consolidation.
Is this a true statement?
Check the following code:
Code: Select all
dim = 'model';
k=1;
elem = DIMNM(dim, k);
WHILE(LONG(elem)>0);
j = ELPARN(Dim, elem);
IF(ELPARN(Dim, elem)>1);
i = j;
par = ELPAR(dim, elem, i);
WHILE(i >1);
DimensionElementComponentDelete(dim, par, elem);
i = i-1;
par = ELPAR(dim, elem, i);
END;
ENDIF;
k = k+1;
elem = DIMNM(dim, k);
END;