44586,"}Dimensions"
55585,"}Dimensions"
66564,
7- 565,"v2Ro>?=^[<xzbf5>egIxAPyK?1p;]2H[@>;urjCnA4W19Bd[v9tMDub2+[Qwo}JR;yS1]>[kEqt>rAn@mv^i;@dTCYQ:Jy1bOV6=smDMzlqQof\Gi^K1j8vPu?9kj\@k!kGBS;G=JXYfmoIn7==XF[EB]zk1]TT31GpaHis@\6=Y=iH]aiMv0v:26?d`qLc5S\d21D "
7+ 565,"c0vy=UZd]C7bY]Rn?Y<=XpnWWi\cSX;UP=a^UN=T=@k4iKow?9WtC9kUe*[QsIpzNIUZQN^UA1~t;yq_xWQ`noKz9lYQ?PY9n?O6mLIMR1C6Occ\g\M2Cq6mkuW6eZvgm,[JR1zkaVZ{IAEoIAy=]3a:S@]GOEX@0R=wk1@9KjVH7yisty3rfu0hLf^NydQL33uF_1Y= "
88559,1
99928,0
1010593,
2525569,0
2626592,0
2727599,1000
28- 560,5
28+ 560,6
2929pLogOutput
3030pStrictErrorHandling
3131pDim
3232pHier
3333pDelim
34- 561 ,5
34+ pReverse
35+ 561 ,6
35361
36371
37382
38392
39402
40- 590 ,5
41+ 1
42+ 590 ,6
4143pLogOutput ,0
4244pStrictErrorHandling ,0
4345pDim ,""
4446pHier ,""
4547pDelim ,"&"
46- 637 ,5
48+ pReverse ,0
49+ 637 ,6
4750pLogOutput ,"OPTIONAL: Write parameters and action summary to server message log (Boolean True = 1)"
4851pStrictErrorHandling ,"OPTIONAL: On encountering any error, exit with major error status by ProcessQuit after writing to the server message log (Boolean True = 1)"
4952pDim ,"REQUIRED: Dimension, accepts wildcards (all dimensions = *)"
5053pHier ,"OPTIONAL: Hierarchy, accepts wildcards (all hierarchies = *)"
5154pDelim ,"OPTIONAL: Delimiter character (default value if blank = '&')"
55+ pReverse ,"OPTIONAL: If true then also add any elements from the Leaves hierarchy not existing in the specified hierarchies to those hierarchies (under a consolidation bucket 'ORPHAN LEAVES')"
5256577 ,1
5357vDimHier
5458578 ,1
@@ -62,13 +66,12 @@ vDimHier
6266582 ,1
6367VarType =32 ColType =827
6468603 ,0
65- 572 ,162
69+ 572 ,170
6670#Region CallThisProcess
6771# A snippet of code provided as an example how to call this process should the developer be working on a system without access to an editor with auto -complete .
6872If ( 1 = 0 );
69- ExecuteProcess ( '}bedrock.hier.leaves.sync' , 'pLogOutput' , pLogOutput ,
70- 'pStrictErrorHandling' , pStrictErrorHandling ,
71- 'pDim' , '' , 'pHier' , '' , 'pDelim' , '&'
73+ ExecuteProcess ( '}bedrock.hier.leaves.sync' , 'pLogOutput' , pLogOutput , 'pStrictErrorHandling' , pStrictErrorHandling ,
74+ 'pDim' , '' , 'pHier' , '' , 'pDelim' , '&' , 'pReverse' , 0
7275 );
7376EndIf ;
7477#EndRegion CallThisProcess
@@ -117,19 +120,20 @@ cDimDimensions = '}Dimensions';
117120cCharAny = '?' ;
118121cStringAny = '*' ;
119122cHierLeaves = 'Leaves' ;
120- cSubMissing = 'Missing ' ;
123+ cRollupOrphan = 'ORPHAN LEAVES ' ;
121124
122125### LogOutput parameters
123126IF ( pLogoutput >= 1 );
124127 LogOutput ('INFO' , Expand ( cLogInfo ) );
125128ENDIF ;
126129
127130### Validate Parameters
128- nErrors = 0 ;
129- nDims = 0 ;
130- nDimsChanged = 0 ;
131- nElems = 0 ;
132- sDimPrev = '' ;
131+ sDimPrev = '' ;
132+ nErrors = 0 ;
133+ nDims = 0 ;
134+ nDimsChanged = 0 ;
135+ nElems = 0 ;
136+ nLeaves = 0 ;
133137
134138If ( Scan ( '*' , pDim ) = 0 & Scan ( '?' , pDim ) = 0 & Scan ( pDelim , pDim ) = 0 & Scan ( ':' , pDim ) > 0 & pHier @= '' );
135139 # A hierarchy has been passed as dimension . Handle the input error by splitting dim:hier into dimension & hierarchy
@@ -149,6 +153,11 @@ If( Trim( pDim ) @= '' );
149153 LogOutput ( cMsgErrorLevel , Expand ( cMsgErrorContent ) );
150154EndIf ;
151155
156+ ### Validate reverse sync option
157+ If ( pReverse <> 1 );
158+ pReverse = 0 ;
159+ EndIf ;
160+
152161### If errors occurred terminate process with a major error status ###
153162If ( nErrors <> 0 );
154163 If ( pStrictErrorHandling = 1 );
@@ -172,7 +181,7 @@ Else;
172181 EndIf ;
173182 sSearchDim = TRIM ( SUBST ( sDimTokenizer , 1 , nPos - 1 ) );
174183 If ( sMDX @= '' );
175- sMDX = Expand ( '{TM1FILTERBYPATTERN( {TM1SUBSETALL([%cDimDimensions%])}, "%sSearchDim%" )}' );
184+ sMDX = Expand ( '{TM1FILTERBYPATTERN( {TM1SUBSETALL([%cDimDimensions%])}, "%sSearchDim%* " )}' );
176185 Else ;
177186 sMDX = Expand ( '%sMDX% + {TM1FILTERBYPATTERN( {TM1SUBSETALL([%cDimDimensions%])}, "%sSearchDim%" )}' );
178187 EndIf ;
@@ -189,7 +198,7 @@ If ( TRIM( pHier ) @= cAll );
189198Else ;
190199 sHierTokenizer = TRIM ( pHier );
191200 If ( sHierTokenizer @= '' );
192- # we need only same named hierarchies - that means to exclude elements that have : in their names
201+ # if pHier blank then we need only same named hierarchies - that means to exclude elements that have : in their names
193202 sMDX = Expand ( '{FILTER( %sMDX1%, INSTR([%cDimDimensions%].CurrentMember.Name, '':'' ) = 0 )}' );
194203 Else ;
195204 sMDX = '' ;
@@ -212,6 +221,7 @@ Else;
212221 EndIf ;
213222EndIf ;
214223
224+ sMDX = Expand (' {EXCEPT( %sMDX%, {TM1FILTERBYPATTERN( {TM1SUBSETALL([%cDimDimensions%])}, "*:Leaves" )} )}' );
215225sMDXF = Expand ( '{ORDER( %sMDX%, [%cDimDimensions%].CurrentMember.Name, ASC )}' );
216226
217227### Create dimension :hierarchy subset
@@ -225,58 +235,95 @@ DatasourceNameForServer = cDimDimensions;
225235DatasourceNameForClient = cDimDimensions ;
226236DataSourceType = 'SUBSET' ;
227237DatasourceDimensionSubset = cTempSub ;
228- 573 ,47
238+
239+ ### END PROLOG
240+ 573 ,80
241+
229242#****Begin : Generated Statements ***
230243#****End : Generated Statements ****
231244
232- nDelimHier = SCAN ( ':' , vDimHier );
245+ # Get dimension & hierarchy from vDimHier
246+ nDelimHier = SCAN ( ':' , vDimHier );
233247If ( nDelimHier <> 0 );
234- sDim = SUBST ( vDimHier , 1 , nDelimHier - 1 );
235- sHier = SUBST ( vDimHier , nDelimHier + 1 , LONG ( vDimHier ) - nDelimHier );
248+ sDim = SUBST ( vDimHier , 1 , nDelimHier - 1 );
249+ sHier = SUBST ( vDimHier , nDelimHier + 1 , LONG ( vDimHier ) - nDelimHier );
236250Else ;
237- sDim = vDimHier ;
238- sHier = vDimHier ;
251+ sDim = vDimHier ;
252+ sHier = vDimHier ;
239253EndIf ;
240254
241- If ( sHier @= cHierLeaves );
242- ItemSkip ;
255+ If ( sHier @= cHierLeaves );
256+ ItemSkip ;
243257EndIf ;
244258
245- # Summary information printout
246- If ( sDimPrev @<> sDim );
247- If ( sDimPrev @<> '' & nElems <> 0 );
248- sElems = NumberToString ( nElems );
249- If ( pLogOutput <> 0 );
250- LogOutput ( cMsgInfoLevel , Expand ( 'Added [%sElems%] elements into [%cHierLeaves%] hierarchy of [%sDimPrev%] dimension.' ) );
251- EndIf ;
252- nDimsChanged = nDimsChanged + 1 ;
253- EndIf ;
254- nDims = nDims + 1 ;
255- nElems = 0 ;
256- sDimPrev = sDim ;
259+ # Set check counters
260+ If ( sDim @<> sDimPrev );
261+ nDims = nDims + 1 ;
257262EndIf ;
263+ nElems = 0 ;
264+ nLeaves = 0 ;
258265
266+ # Add leaves in hierarchy but (somehow ) not in Leaves hierarchy to Leaves
259267nElem = 1 ;
260268nMaxElem = ElementCount ( sDim , sHier );
261269While ( nElem <= nMaxElem );
262- sElem = ElementName ( sDim , sHier , nElem );
263- If ( ElementLevel ( sDim , sHier , sElem ) = 0 & HierarchyExists ( sDim , cHierLeaves ) <> 0 );
264- If ( ElementIndex ( sDim , cHierLeaves , sElem ) = 0 );
265- sType = ElementType ( sDim , sHier , sElem );
266- HierarchyElementInsert ( sDim , cHierLeaves , '' , sElem , sType ) ;
267- nElems = nElems + 1 ;
268- If ( pLogOutput > 1 );
269- LogOutput ( cMsgInfoLevel , Expand ( 'Adding element [%sElem%] of [%sType%] type into [%cHierLeaves%], element was found in hierarchy [%sHier%].' ) ) ;
270- EndIf ;
270+ sElem = ElementName ( sDim , sHier , nElem );
271+ If ( ElementLevel ( sDim , sHier , sElem ) = 0 & HierarchyExists ( sDim , cHierLeaves ) = 1 );
272+ If ( ElementIndex ( sDim , cHierLeaves , sElem ) = 0 & ElementType ( sDim , sHier , sElem ) @= 'N' );
273+ HierarchyElementInsert ( sDim , cHierLeaves , '' , sElem , 'N' );
274+ nElems = nElems + 1 ;
275+ If ( pLogOutput <> 0 ) ;
276+ LogOutput ( cMsgInfoLevel , Expand ( 'Adding element [%sElem%] of [%sType%] type into [%cHierLeaves%], element was found in hierarchy [%sHier%].' ) );
277+ EndIf ;
278+ EndIf ;
271279 EndIf ;
272- EndIf ;
273- nElem = nElem + 1 ;
280+ nElem = nElem + 1 ;
274281End ;
275282
276- 574 ,2
283+ # Add leaves not existing in hierarchy to the 'ORPHAN LEAVES' consolidation
284+ If ( pReverse = 1 & HierarchyExists ( sDim , cHierLeaves ) = 1 );
285+ nLeaf = 1 ;
286+ nMaxLeaves = ElementCount ( sDim , cHierLeaves );
287+ While ( nLeaf <= nMaxLeaves );
288+ sLeaf = ElementName ( sDim , cHierLeaves , nLeaf );
289+ If ( ElementIndex ( sDim , sHier , sLeaf ) = 0 );
290+ HierarchyElementInsert ( sDim , sHier , '' , cRollupOrphan , 'C' );
291+ HierarchyElementInsert ( sDim , sHier , '' , sLeaf , 'N' );
292+ HierarchyElementComponentAdd ( sDim , sHier , cRollupOrphan , sLeaf , 1 );
293+ nLeaves = nLeaves + 1 ;
294+ If ( pLogOutput <> 0 );
295+ LogOutput ( cMsgInfoLevel , Expand ( 'Adding leaf [%sLeaf%] into hierarchy [%sHier%].' ) );
296+ EndIf ;
297+ EndIf ;
298+ nLeaf = nLeaf + 1 ;
299+ End ;
300+ EndIf ;
301+
302+ # Summary information printout
303+ If ( nElems > 0 );
304+ sElems = NumberToString ( nElems );
305+ If ( pLogOutput <> 0 );
306+ LogOutput ( cMsgInfoLevel , Expand ( 'Added [%sElems%] elements from hierarchy [%sHier%] into [%cHierLeaves%] hierarchy of [%sDim%] dimension.' ) );
307+ EndIf ;
308+ EndIf ;
309+ If ( nLeaves > 0 );
310+ sLeaves = NumberToString ( nLeaves );
311+ If ( pLogOutput <> 0 );
312+ LogOutput ( cMsgInfoLevel , Expand ( 'Added [%sLeaves%] leaves into hierarchy [%sHier%] of [%sDim%] dimension.' ) );
313+ EndIf ;
314+ EndIf ;
315+ If ( sDim @<> sDimPrev & (nElems + nLeaves ) > 0 );
316+ nDimsChanged = nDimsChanged + 1 ;
317+ EndIf ;
318+ sDimPrev = sDim ;
319+
320+ ### END METADATA
321+ 574 ,4
322+
277323#****Begin : Generated Statements ***
278324#****End : Generated Statements ****
279- 575 ,38
325+
326+ 575 ,37
280327#****Begin : Generated Statements ***
281328#****End : Generated Statements ****
282329
@@ -299,8 +346,8 @@ EndIf;
299346If ( nDims <> 0 );
300347 sDims = NumberToString ( nDims );
301348 sDimsChanged = NumberToString ( nDimsChanged );
302- If ( nDimsChanged < > 0 );
303- sProcessAction = Expand ( 'Modified [%sDimsChanged%] dimensions out of [%sDims%] matching.' );
349+ If ( nDimsChanged > 0 );
350+ sProcessAction = Expand ( 'Modified [%sDimsChanged%] dimensions out of [%sDims%] matching the filter .' );
304351 Else ;
305352 sProcessAction = Expand ( 'Scanned [%sDims%] dimensions, all are ok.' );
306353 EndIf ;
@@ -313,8 +360,7 @@ If( pLogoutput <> 0 );
313360 LogOutput ( cMsgInfoLevel , Expand ( sProcessAction ) );
314361EndIf ;
315362
316-
317-
363+ ### END EPILOG
318364576 ,
319365930 ,0
320366638 ,1
0 commit comments