I wonder if there's a more efficient way to retrieve the top parent (by top parent I mean the 'highest' consolidated element) of an element.
In other word, for all leaf-level elements in a source dimension, I want to retrieve the top parent/ancestor and recreate it in a target dimension.
Code: Select all
#==================================================
# Retrieve Top Parent and Create it if doesn't exist
# Maximum of 4 level is allowed here.
#==================================================
sParent1 = ELPAR( sDimSource, vElement, 1 );
IF(ELPARN( sDimSource, sParent1 ) <> 0 );
sParent2 = ELPAR( sDimSource, sParent1, 1 );
IF(ELPARN( sDimSource, sParent2 ) <> 0 );
sParent3 = ELPAR( sDimSource, sParent2, 1 );
IF(ELPARN( sDimSource, sParent3 ) <> 0 );
sParent4 = ELPAR( sDimSource, sParent3, 1 );
sTopParent= sParent4;
ELSE;
sTopParent = sParent3;
ENDIF;
ELSE;
sTopParent = sParent2;
ENDIF;
ELSE;
sTopParent = sParent1;
ENDIF;
IF(DIMIX( sDimTarget, sTopParent ) = 0);
DimensionElementInsertDirect( sDimTarget, '', sTopParent, 'C' );
ENDIF;
Jack