/
}bedrock.hier.consol.delete.pro
319 lines (287 loc) · 8.89 KB
/
}bedrock.hier.consol.delete.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
601,100
602,"}bedrock.hier.consol.delete"
562,"NULL"
586,
585,
564,
565,"sCY=QH5[bG;fpgr`lX1aew=9oE>VEL1WB`@de0N:l0hZ4:EVmYhFt>gUsgRKz2He?HZ<noIH[NO0KJieYe>jej_dz:ey@JOzayn5AnZLhTbI<rOt91r551CJEQ2qD9w?iS8wob4HJrY5EPfQDwGMw5\J;zoe^8W;3^YBHOk[9=ZvpL?H_WozL:VVYH6IWmrbAH3cm=Dz"
559,1
928,0
593,
594,
595,
597,
598,
596,
800,
801,
566,0
567,","
588,"."
589,","
568,""""
570,
571,
569,0
592,0
599,1000
560,6
pLogOutput
pStrictErrorHandling
pDim
pHier
pEle
pDelim
561,6
1
1
2
2
2
2
590,6
pLogOutput,0
pStrictErrorHandling,0
pDim,""
pHier,""
pEle,""
pDelim,"&"
637,6
pLogOutput,"OPTIONAL: Write parameters and action summary to server message log (Boolean True = 1)"
pStrictErrorHandling,"OPTIONAL: On encountering any error, exit with major error status by ProcessQuit after writing to the server message log (Boolean True = 1)"
pDim,"REQUIRED: Dimension name"
pHier,"OPTIONAL: Hierarchy name (if blank then same named hierarchy as dimension is assumed)"
pEle,"OPTIONAL: Filter on elements (element list separated by delimiter, accepts wildcards (if * then all the consolidation elements get deleted))"
pDelim,"OPTIONAL: Delimiter character for element list (default to '&' if blank)"
577,0
578,0
579,0
580,0
581,0
582,0
603,0
572,177
#Region CallThisProcess
# 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.
If( 1 = 0 );
ExecuteProcess( '}bedrock.hier.consol.delete', 'pLogOutput', pLogOutput,
'pStrictErrorHandling', pStrictErrorHandling,
'pDim', '', 'pHier', '', 'pEle', '',
'pDelim', '&'
);
EndIf;
#EndRegion CallThisProcess
#****Begin: Generated Statements***
#****End: Generated Statements****
#################################################################################################
##~~Join the bedrock TM1 community on GitHub https://github.com/cubewise-code/bedrock Ver 4.0~~##
#################################################################################################
#Region @DOC
# Description:
# This process will delete a specified C-Level item **or** ALL consolidations in the dimension hierarchy.
# Use case: Could be used during development or in production.
# 1/ Delete a specific or all C-Level items in a hierarchy.
# Note:
# Valid dimension name (pDim) is mandatory otherwise the process will abort. Control dimensions are excluded.
# The hierarchy (pHier) will default to pDim if not specified, otherwise it must be valid else the process will abort.
# **ALL** consoldidated items in hierarchy will be deleted if consolidated item (pEle) is specified as \*, otherwise it needs to contain valid c-level item(s).
# Caution: Target hierarchy (pHier) cannot be `Leaves`.
#EndRegion @DOC
##Global Variables
StringGlobalVariable('sProcessReturnCode');
NumericGlobalVariable('nProcessReturnCode');
nProcessReturnCode= 0;
### Constants ###
cThisProcName = GetProcessName();
cTimeStamp = TimSt( Now, '\Y\m\d\h\i\s' );
cRandomInt = NumberToString( INT( RAND( ) * 1000 ));
cTempSub = cThisProcName |'_'| cTimeStamp |'_'| cRandomInt;
cUserName = TM1User();
cMsgErrorLevel = 'ERROR';
cMsgErrorContent = 'User:%cUserName% Process:%cThisProcName% ErrorMsg:%sMessage%';
cLogInfo = 'Process:%cThisProcName% run with parameters pDim:%pDim%, pHier:%pHier%, pEle:%pEle%, pDelim:%pDelim%.';
## LogOutput parameters
IF( pLogoutput = 1 );
LogOutput('INFO', Expand( cLogInfo ) );
ENDIF;
### Validate Parameters ###
nErrors = 0;
If( Scan( ':', pDim ) > 0 & pHier @= '' );
# A hierarchy has been passed as dimension. Handle the input error by splitting dim:hier into dimension & hierarchy
pHier = SubSt( pDim, Scan( ':', pDim ) + 1, Long( pDim ) );
pDim = SubSt( pDim, 1, Scan( ':', pDim ) - 1 );
EndIf;
## Validate Dimension
If( Trim( pDim ) @= '' );
nErrors = 1;
sMessage = 'No dimension specified.';
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
ElseIf( DimensionExists( pDim ) = 0 );
nErrors = 1;
sMessage = 'Dimension: ' | pDim | ' does not exist on server.';
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
EndIf;
## Validate Hierarchy
IF(pHier @= 'Leaves' );
nErrors = 1;
sMessage = 'Invalid Hierarchy: ' | pDim |':'|pHier;
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
EndIf;
## Validate Elements
IF(pEle @= '' );
nErrors = 1;
sMessage = 'Element cannot be empty. Use * for all elements';
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
EndIf;
If( Trim( pHier ) @= '' );
sHier = pDim;
Else;
sHier = pHier;
EndIf;
If( HierarchyExists( pDim, sHier ) = 0 );
nErrors = 1;
sMessage = 'The Hierarchy ' | sHier | ' does not exist.';
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
EndIf;
# If blank delimiter specified then convert to default
If( pDelim @= '' );
pDelim = '&';
EndIf;
### Check for errors before continuing
If( nErrors > 0 );
If( pStrictErrorHandling = 1 );
ProcessQuit;
Else;
ProcessBreak;
EndIf;
EndIf;
sEles = pEle;
nDelimiterIndex = 1;
While( nDelimiterIndex <> 0 );
nDelimiterIndex = Scan( pDelim, sEles );
If( nDelimiterIndex = 0 );
sEle = sEles;
Else;
sEle = Trim( SubSt( sEles, 1, nDelimiterIndex - 1 ) );
sEles = Trim( Subst( sEles, nDelimiterIndex + Long(pDelim), Long( sEles ) ) );
EndIf;
# Check if a wildcard has been used to specify the Element name.
# If it hasn't then just delete the Element if it exists
If( sEle @= '*' );
nElementIndex = Dimsiz(pDim|':'|sHier);
While( nElementIndex >= 1 );
sEle = ElementName( pDim, sHier, nElementIndex );
sElType = ElementType( pDim, sHier, sEle );
If( sElType @= 'C' );
HierarchyElementDelete( pDim, sHier,sEle );
EndIf;
nElementIndex = nElementIndex - 1;
End;
ElseIf( Scan( '*', sEle ) = 0);
If( HierarchyElementExists( pDim,sHier, sEle ) = 1 );
sElType = ElementType( pDim, sHier, sEle );
If( sElType @='C' );
HierarchyElementDelete( pDim, sHier,sEle );
EndIf;
Else;
nErrors = 1;
sMessage = 'The Hierarchy ' | sHier | ' does not have element ' | sEle;
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
EndIf;
Else;
# Wildcard search string
sEle = '"'|sEle|'"';
sProc = '}bedrock.hier.sub.create.bymdx';
sMdx = '{TM1FILTERBYPATTERN( {TM1SUBSETALL([ ' |pDim|':'|sHier |' ])},'| sEle| ')}';
ExecuteProcess('}bedrock.hier.sub.create.bymdx',
'pLogOutput', pLogOutput,
'pStrictErrorHandling', pStrictErrorHandling,
'pDim', pDim,
'pHier', sHier,
'pSub', cTempSub,
'pMDXExpr', sMdx,
'pConvertToStatic', 1,
'pTemp', 1
);
nCount = HierarchySubsetGetSize(pDim, sHier, cTempSub);
While( nCount >= 1 );
sElement = HierarchySubsetGetElementName(pDim, sHier, cTempSub, nCount);
sElType = ElementType( pDim, sHier, sElement );
If( sElType @= 'C' );
HierarchyElementDelete( pDim, sHier,sElement );
EndIf;
nCount = nCount - 1;
End;
EndIf;
End;
### End Prolog ###
573,5
#****Begin: Generated Statements***
#****End: Generated Statements****
574,4
#****Begin: Generated Statements***
#****End: Generated Statements****
575,27
#****Begin: Generated Statements***
#****End: Generated Statements****
#################################################################################################
##~~Join the bedrock TM1 community on GitHub https://github.com/cubewise-code/bedrock Ver 4.0~~##
#################################################################################################
### Return code & final error message handling
If( nErrors > 0 );
sMessage = 'the process incurred at least 1 error. Please see above lines in this file for more details.';
nProcessReturnCode = 0;
LogOutput( cMsgErrorLevel, Expand( cMsgErrorContent ) );
sProcessReturnCode = Expand( '%sProcessReturnCode% Process:%cThisProcName% completed with errors. Check tm1server.log for details.' );
If( pStrictErrorHandling = 1 );
ProcessQuit;
EndIf;
Else;
sProcessAction = Expand( 'Process:%cThisProcName% successfully deleted the appropriate consolidated elements in hierarchy %pDim%:%pHier%.' );
sProcessReturnCode = Expand( '%sProcessReturnCode% %sProcessAction%' );
nProcessReturnCode = 1;
If( pLogoutput = 1 );
LogOutput('INFO', Expand( sProcessAction ) );
EndIf;
EndIf;
### End Epilog ###
576,CubeAction=1511DataAction=1503CubeLogChanges=0
930,0
638,1
804,0
1217,1
900,
901,
902,
938,0
937,
936,
935,
934,
932,0
933,0
903,
906,
929,
907,
908,
904,0
905,0
909,0
911,
912,
913,
914,
915,
916,
917,0
918,1
919,0
920,50000
921,""
922,""
923,0
924,""
925,""
926,""
927,""