Tops-down child/parent dimension export
Posted: Fri Apr 18, 2014 3:58 pm
I thought I'd share the following process as I wasn't able to find anything in the archive that quite fit the bill.
Objectives:
1) For a given consolidated member and its descendants, output:
Child, Parent, Child_Alias, Weight
2) Output in a tops-down manner where parents are always defined before children
3) Support alternative rollups
The last two objectives conflicted with most of the previous export examples I'd read in the forum. They typically worked from the bottoms-up and relied on elpar( pDim, pElem, 1) which isn't going to play well with alternative hierarchies.
To accomplish this, I utilized two approaches that aren't great for performance, but get the job done: ExecuteProcess recursion and an ExecuteCommand system call to append output rather than use ASCIIOUTPUT.
One important callout is that you do need to delete the output file before calling the process:
I'd love to hear suggestions on if and how this can be accomplished more efficiently.
-- John
Objectives:
1) For a given consolidated member and its descendants, output:
Child, Parent, Child_Alias, Weight
2) Output in a tops-down manner where parents are always defined before children
3) Support alternative rollups
The last two objectives conflicted with most of the previous export examples I'd read in the forum. They typically worked from the bottoms-up and relied on elpar( pDim, pElem, 1) which isn't going to play well with alternative hierarchies.
To accomplish this, I utilized two approaches that aren't great for performance, but get the job done: ExecuteProcess recursion and an ExecuteCommand system call to append output rather than use ASCIIOUTPUT.
One important callout is that you do need to delete the output file before calling the process:
Code: Select all
# sys_dim_export_child_parent_alias_weight
#
# Required Parameters
# pDim = DimensionName
# pElem = Starting Consolidated Element
# pAlias = Name of Alias to Include
# pFile = Filename
numChild = ELCOMPN ( pDim, pElem );
vChildAlias = ATTRS ( pDim, pElem, pAlias );
if ( pParent @<> '' );
vChildWeight = NUMBERTOSTRING ( ELWEIGHT ( pDim, pParent, pElem ) );
else;
vChildWeight = '0';
endIf;
vOutput = pElem | ',' | pParent | ',' | vChildAlias | ',' | vChildWeight;
# adjust to just 'echo' if using Windows
vCmd = '/usr/bin/echo "' | vOutput | '" >> "' | pFile | '"';
ExecuteCommand ( vCmd, 1 );
if ( numChild > 0 );
i = 1;
while ( i <= numChild ) ;
vChild = ELCOMP ( pDim, pElem, i );
# recurse
ExecuteProcess ( 'sys_dim_export_child_parent_alias_weight',
'pDim', pdim,
'pElem', vChild,
'pParent', pElem,
'pAlias', pAlias,
'pFile', pFile
);
i = i + 1;
end;
endIf;
-- John