Page 1 of 1
Building Dimension without deleting data
Posted: Wed Apr 13, 2011 9:49 pm
by BigG
Hi,
We have gone live, but previously in development I was using DimensionDeleteAllElements('Dim'); in Epilog of a dim build to tidy up the dimensions as we progressed. Now I have removed this I am wondering whether there is a need to use if(DIMIX(Element) = 1); then do not proceed with DIMENSIONELEMENTINSERT, due to the fact its already created but mostly I am concerned it will override, lose data? I have tested and it doesnt seem to be an issue not having DIMIX, but just would like a bit of confirmation.
Cheers
G
Re: Building Dimension without deleting data
Posted: Wed Apr 13, 2011 9:58 pm
by Alan Kirk
BigG wrote:
We have gone live, but previously in development I was using DimensionDeleteAllElements('Dim'); in Epilog of a dim build to tidy up the dimensions as we progressed. Now I have removed this I am wondering whether there is a need to use if(DIMIX(Element) = 1); then do not proceed with DIMENSIONELEMENTINSERT, due to the fact its already created but mostly I am concerned it will override, lose data? I have tested and it doesnt seem to be an issue not having DIMIX, but just would like a bit of confirmation.
1/ I'm not sure why you would be using DimensionDeleteAllElements in an Epilog; indeed I wouldn't recommend using it at all outside of a process which merely deletes and recreates a test structure. That thing is dangerous.
2/ (DIMIX(Element) = 1) will be true for only a single element. If you were to do such a test, it would be >0 rather than =1.
3/ You don't need to worry about it. If the element already exists then DimensionElementInsert won't do anything. We do that all the time. However I do sometimes do the DimIx test anyway; when it's 0 I export details of the element to a log file via AsciiOutput to give me a heads up that there's a new kid in town. However it definitely isn't necessary to do it before doing the Insert.
For the sake of completeness only, I'll mention that the function that has a risk of costing you data is DimensionElementComponentAdd. If you use that to add a child to an N level element it automatically converts to a C level one, then it's buh-bye to any data stored in it.
Re: Building Dimension without deleting data
Posted: Wed Apr 13, 2011 10:29 pm
by BigG
thanks Alan for quick response
1/ I'm not sure why you would be using DimensionDeleteAllElements in an Epilog; indeed I wouldn't recommend using it at all outside of a process which merely deletes and recreates a test structure. That thing is dangerous.
sorry didnt explain, was only used during dev and testing, not part of production
2/ (DIMIX(Element) = 1) will be true for only a single element. If you were to do such a test, it would be >0 rather than =1.
noted
3/ You don't need to worry about it. If the element already exists then DimensionElementInsert won't do anything. We do that all the time. However I do sometimes do the DimIx test anyway; when it's 0 I export details of the element to a log file via AsciiOutput to give me a heads up that there's a new kid in town. However it definitely isn't necessary to do it before doing the Insert.
great, just what I wanted
For the sake of completeness only, I'll mention that the function that has a risk of costing you data is DimensionElementComponentAdd.
yes good point, will test and retest the dimensions and ensure no data carrying leaf nodes are potentially rolled up into
THanks again.. G
Re: Building Dimension without deleting data
Posted: Fri Apr 15, 2011 9:33 am
by jacktuckerman
What you could consider is following this sort of approach:
Rather than deleting all the existing elements, you could "unwind" the dimensions consolidations and rebuild it based on the definitions of the data source, if it's changed:
dim='your dimension';
i = dimsiz(dim);
x=1;
While(x<=i);
vEl=dimnm(dim,x);
y=elcompn(dim,vEl);
While(y>0);
dimensionelementcomponentdelete(dim,vEl,elcomp(dim,vEl,y));
y=y-1;
End;
x=x+1;
if(x>dimsiz(dim)+100);processquit;endif;
End;
That way you wont lose any elements that existed before, and new ones will be added, and existing ones put into hierachy based on the new state of the datasource.
Elements not in the data source will not be added to a consolidation, so you might want to make a consolidation holder for them, called something like "orphans" and create a little process to dropping them in there too.