Page 1 of 1

Deleting elements without children

Posted: Tue Apr 08, 2014 10:21 am
by ralph007
Hi,

I'm trying to remove all consolidations elements without any children from dimension. This code below not working properly because deleting only some elements. What is wrong in this code below??

In this dimension I have multiple hierarchy.

Thanks for any suggestion.

sDimName = 'DestCustomer';

nX = 1;
nLimit = DIMSIZ(sDimName);

WHILE(nX<=nLimit);


sElementName = DIMNM(sDimName,nX);
sConElement = DTYPE(sDimName,sElementName);
sNumberOfChildren = ELCOMPN(sDimName,sElementName);

IF (sConElement @='C');
IF(sNumberOfChildren = 0);

DIMENSIONELEMENTDELETE(sDimName,sElementName);

ENDIF;
ENDIF;

nX = nX + 1;

END;

Regards

Rafal

Re: Deleting elements without children

Posted: Tue Apr 08, 2014 10:37 am
by declanr
Look at the advice I gave in your last post (that was irrelevant in that scenario.)

You also have a risk that you check element 1 and ignore it as it has child element 2... you then check element 2 which is a c with no children and delete it. Now element 1 still exists as a c with no children... follow?

Re: Deleting elements without children

Posted: Tue Apr 08, 2014 10:44 am
by ralph007
Hi,

I fixed the issue this code below working :

sDimName = 'DestCustomer';

nX = 1;
nLimit = DIMSIZ(sDimName);

WHILE(nX<=nLimit);


sElementName = DIMNM(sDimName,nX);
sConElement = DTYPE(sDimName,sElementName);
sNumberOfChildren = ELCOMPN(sDimName,sElementName);

IF (sConElement @='C');
IF(sNumberOfChildren = 0);

DIMENSIONELEMENTDELETE(sDimName,sElementName);

ENDIF;

ELSE;
nX = nLimit + 1;
ENDIF;

IF(sElementName@=DIMNM(sDimName,nX));
nX = nX + 1;
ENDIF;


END;

Re: Deleting elements without children

Posted: Tue Apr 08, 2014 10:52 am
by Gabor
sDimName = 'DestCustomer';
nLimit = DIMSIZ( sDimName );
nX = nLimit;

WHILE( nX >= 1 );

sElementName = DIMNM( sDimName, nX );
nlevel = ELLEV( sDimName, sElementName );

IF ( nLevel > 0 );
DIMENSIONELEMENTDELETE( sDimName, sElementName );
ENDIF;

nX = nX - 1;
END;

Re: Deleting elements without children

Posted: Tue Apr 08, 2014 11:02 am
by Gabor
Just saw your own feedback, so maybe I didn't catch your requirement. The above code simply deletes all consolidations.

Re: Deleting elements without children

Posted: Tue Apr 08, 2014 12:29 pm
by ralph007
Hi Gabor,

Many thanks for your help.

Regards

Rafal