forked from cubewise-code/bedrock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bedrock.Cube.View.Create.pro
564 lines (469 loc) · 15.2 KB
/
Bedrock.Cube.View.Create.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
601,100
602,"Bedrock.Cube.View.Create"
562,"NULL"
586,"Variables"
585,"Variables"
564,
565,"o107s_0x?UNE^@5agv_4z1@f3wY;abMh41uxkn]5`>P<WUliPngCwIdQ_dAqLYXCOYC@?ae21jRbc0BcD>BOPY2:kW1prPGzy>_;QSd00nvqRkRoc^7ENwQ4Nz9rCA3R3VrB[q2yBD>\<KhgLuWmdc8g\ctyh@:JOrm:DRxEKItueNXCuf?oyYc`D8^zBfZ]quZSuH_S"
559,1
928,0
593,
594,
595,
597,
598,
596,
800,
801,
566,0
567,","
588,"."
589,
568,""""
570,All
571,
569,0
592,0
599,1000
560,10
pCube
pView
pFilter
pSuppressZero
pSuppressConsol
pSuppressRules
pDimensionDelim
pElementStartDelim
pElementDelim
pDebug
561,10
2
2
2
1
1
1
2
2
2
1
590,10
pCube,""
pView,""
pFilter,""
pSuppressZero,1
pSuppressConsol,1
pSuppressRules,1
pDimensionDelim,"&"
pElementStartDelim,":"
pElementDelim,"+"
pDebug,0
637,10
pCube,Cube Name
pView,Name of the View
pFilter,Filter: Year: 2006 + 2007 & Scenario: Actual + Budget & Organization: North America Operations
pSuppressZero,Suppress Zero Data (Skip = 1)
pSuppressConsol,Suppress Consolidations (Skip = 1)
pSuppressRules,Suppress Rules (Skip = 1)
pDimensionDelim,Delimiter for start of Dimension/Element set
pElementStartDelim,Delimiter for start of element list
pElementDelim,Delimiter between elements
pDebug,Debug: 0
577,0
578,0
579,0
580,0
581,0
582,0
572,402
#****Begin: Generated Statements***
#****End: Generated Statements****
#####################################################################################
##~~Copyright bedrocktm1.org 2011 www.bedrocktm1.org/how-to-licence.php Ver 3.1.0~~##
#####################################################################################
# This process automatically creates a view that can be used for exporting, copying and zeroing out numbers.
# Note:
# - The pFilter parameter contains the dimenson and elements to be used for filtering.
# - The format of the pFilter parameter is as follows delimiters of :, & and +:
# Dim1: Elem1 + Elem2 & Dim2: Elem3 + Elem4
# - The dimension parameters do not need to be given in the index order of dimensions in the cube.
# - The dimension name is specified as the first member of the delimited string of elements.
# - If consols are skipped the N level children of any consolidated filter elements will be used
# - Spaces are ignored so use them to make your filter more readable
### Constants ###
cProcess = 'Bedrock.Cube.View.Create';
cTimeStamp = TimSt( Now, '\Y\m\d\h\i\s' );
sRandomInt = NumberToString( INT( RAND( ) * 1000 ));
cDebugFile = GetProcessErrorFileDirectory | cProcess | '.' | cTimeStamp | '.' | sRandomInt ;
sSubset = pView;
sDelimDim = TRIM(pDimensionDelim);
sElementStartDelim = TRIM(pElementStartDelim);
sDelimElem = TRIM(pElementDelim);
nErrors = 0;
### Initialise Debug ###
If( pDebug >= 1 );
# Set debug file name
sDebugFile = cDebugFile | 'Prolog.debug';
# Log start time
AsciiOutput( sDebugFile, 'Process Started: ' | TimSt( Now, '\d-\m-\Y \h:\i:\s' ) );
# Log parameters
AsciiOutput( sDebugFile, 'Parameters: pCube: ' | pCube );
AsciiOutput( sDebugFile, ' pView: ' | pView );
AsciiOutput( sDebugFile, ' pFilter: ' | pFilter );
AsciiOutput( sDebugFile, ' pSuppressZero: ' | NumberToString( pSuppressZero) );
AsciiOutput( sDebugFile, ' pSuppressConsol: ' | NumberToString( pSuppressConsol) );
AsciiOutput( sDebugFile, ' pSuppressRules: ' | NumberToString( pSuppressRules) );
AsciiOutput( sDebugFile, ' pDimensionDelim: ' | pDimensionDelim );
AsciiOutput( sDebugFile, ' pElementStartDelim: ' | pElementStartDelim );
AsciiOutput( sDebugFile, ' pElementDelim: ' | pElementDelim );
EndIf;
# If specified cube does not exist then terminate process
If( CubeExists( pCube ) = 0 );
sMessage = 'Cube: ' | pCube | ' does not exist';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
nErrors = nErrors + 1;
ProcessQuit;
EndIf;
## Validate the View parameter
If( TRIM(pView) @= '' );
sMessage = 'A view name must be provided';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
nErrors = nErrors + 1;
ProcessQuit;
EndIf;
# Check the delimiters
If( sDelimDim @= '' );
sMessage = 'The dimension delimiter is blank';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
ProcessQuit;
EndIf;
If( sElementStartDelim @= '' );
sMessage = 'The dimension name delimiter is blank';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
ProcessQuit;
EndIf;
If( sDelimElem @= '' );
sMessage = 'The element delimiter is blank';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
ProcessQuit;
EndIf;
If( sDelimDim @= sElementStartDelim % sDelimDim @= sDelimElem % sElementStartDelim @= sDelimElem );
sMessage = 'The delimiters cannot me the same';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
ProcessQuit;
EndIf;
### Create View ###
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Creating view ' | pView | ' on cube ' | pCube );
EndIf;
If( pDebug <= 1 );
If( ViewExists( pCube, pView ) = 1 );
# Clear all of the subsets that may be attached to the view
nCount = 1;
While( TabDim( pCube, nCount ) @<> '' );
sCubeDimName = TabDim( pCube, nCount );
# Subset is the same name as the view
If( SubsetExists( sCubeDimName, pView ) = 1 );
# Clear the elements
SubsetDeleteAllElements( sCubeDimName, pView );
# Add all elements
If( SubsetIsAllSet(sCubeDimName, pView, 1) <> 1 );
If( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Unable to add all elements on subset ' | pView | ' on dimension ' | sCubeDimName );
EndIf;
ProcessQuit;
EndIf;
ENDIF;
nCount = nCount + 1;
End;
Else;
ViewCreate( pCube, pView );
EndIf;
ViewExtractSkipCalcsSet( pCube, pView, pSuppressConsol );
ViewExtractSkipZeroesSet( pCube, pView, pSuppressZero );
ViewExtractSkipRuleValuesSet( pCube, pView, pSuppressRules );
EndIf;
### Split filter and create subsets ###
sFilter = TRIM( pFilter );
nChar = 1;
nCharCount = LONG( sFilter );
sWord = '';
sLastDelim = '';
nIndex = 1;
# Add a trailing element delimiter so that the last element is picked up
If( nCharCount > 0 );
sFilter = sFilter | sDelimElem;
nCharCount = nCharCount + LONG(sDelimElem);
EndIf;
WHILE (nChar <= nCharCount);
sChar = SUBST( sFilter, nChar, 1);
If( pDebug >= 1 );
sMessage = 'Next character is: ' | sChar | ' at ' | NumberToString(nChar);
AsciiOutput( sDebugFile, sMessage );
EndIf;
# Used for delimiters, required for multiple character dilimiters
sDelim = '';
nAddExtra = 0;
# Ignore spaces
IF (TRIM(sChar) @<> '' );
### Dimension Name ###
# If the delimiter is more than 1 character peek ahead the same amount
# Ignore the first character
sDelim = sChar;
nCount = LONG(sElementStartDelim) - 1;
If( nCount > 0 & nChar + nCount <= nCharCount );
# Add the extra characters
sDelim = sDelim | SUBST( sFilter, nChar + 1, nCount);
# Move to the end of the delimter
nAddExtra = nCount;
EndIf;
If( sDelim @= sElementStartDelim );
sChar = sDelim;
If( sLastDelim @<> '' & sLastDelim @<> sDelimDim );
sMessage = 'The name of a dimension must follow a dimension delimiter (' | sDelimDim | ')';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
ProcessQuit;
EndIf;
sDimension = sWord;
If( pDebug >= 1 );
sMessage = 'Found dimension name: ' | sDimension | ' at ' | NumberToString(nChar);
AsciiOutput( sDebugFile, sMessage );
EndIf;
If( DimensionExists( sDimension ) = 0 );
# The dimension does not exist in the model. Cancel process
sMessage = 'Dimension: ' | sDimension | ' does not exist';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
nErrors = nErrors + 1;
ProcessQuit;
EndIf;
### Determine the dimension is a member of the cube ###
nCount = 1;
nDimensionIndex = 0;
While( TabDim( pCube, nCount ) @<> '' );
sCubeDimName = TabDim( pCube, nCount );
IF(
sDimension @= sCubeDimName);
nDimensionIndex = nCount;
ENDIF;
nCount = nCount + 1;
End;
If( nDimensionIndex = 0 );
# The dimension does not exist in the cube. Cancel process
sMessage = 'Dimension: ' | sDimension | ' is not a member of: '| pCube | 'cube.';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
nErrors = nErrors + 1;
ProcessQuit;
EndIf;
# Create the subset
If( SubsetExists( sDimension, sSubset ) = 1 );
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Subset ' | sSubset | ' exists on dimension ' | sDimension | '. Deleting all elements' );
EndIf;
If( pDebug <= 1 );
SubsetDeleteAllElements( sDimension, sSubset );
EndIf;
Else;
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Creating subset ' | sSubset | ' on dimension ' | sDimension );
EndIf;
If( pDebug <= 1 );
SubsetCreate( sDimension, sSubset );
EndIf;
EndIf;
# Attach to the view
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Assigning subset ' | sSubset | ' to view ' | pView );
EndIf;
If( pDebug <= 1 );
ViewSubsetAssign(pCube, pView, sDimension, sSubset);
EndIf;
nIndex = 1;
sLastDelim = sChar;
# Clear the word
sWord = '';
Else;
# Reset extra chars
nAddExtra = 0;
### Check both both dim delimiter and element delimiter ###
nIsDelimiter = 0;
## Check dimension delimiter first
# If the delimiter is more than 1 character peek ahead the same amount
# Ignore the first character
sDelim = sChar;
nCount = LONG(sDelimDim) - 1;
If( nCount > 0 & nChar + nCount <= nCharCount );
# Add the extra characters
sDelim = sDelim | SUBST( sFilter, nChar + 1, nCount);
# Move to the end of the delimter
nAddExtra = nCount;
EndIf;
If( sDelim @= sDelimDim );
nIsDelimiter = 1;
sChar = sDelim;
Else;
# Reset extra chars
nAddExtra = 0;
## Check element delimiter
# If the delimiter is more than 1 character peek ahead the same amount
# Ignore the first character
sDelim = sChar;
nCount = LONG(sDelimElem) - 1;
If( nCount > 0 & nChar + nCount <= nCharCount );
# Add the extra characters
sDelim = sDelim | SUBST( sFilter, nChar + 1, nCount);
# Move to the end of the delimter
nAddExtra = nCount;
EndIf;
If( sDelim @= sDelimElem );
nIsDelimiter = 1;
sChar = sDelim;
Else;
# Reset extra chars
nAddExtra = 0;
EndIf;
EndIf;
If ( nIsDelimiter = 1 );
If( sLastDelim @= '' % sLastDelim @= sDelimDim );
sMessage = 'An element delimiter must follow a dimension name: ' | sChar | ' (' | NumberToString(nChar) | ')';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
ProcessQuit;
EndIf;
sElement = sWord;
If( pDebug >= 1 );
sMessage = 'Inserting element: ' | sElement | ' at ' | NumberToString(nChar);
AsciiOutput( sDebugFile, sMessage );
EndIf;
If( DIMIX( sDimension, sElement ) = 0 );
# The element does not exist in the dimension. Cancel process
sMessage = 'Element: ' | sElement | ' in dimension ' | sDimension | ' does not exist';
If( pDebug >= 1 );
AsciiOutput( sDebugFile, sMessage );
EndIf;
nErrors = nErrors + 1;
ProcessQuit;
EndIf;
If ( pSuppressConsol = 1 & DTYPE( sDimension, sElement) @= 'C' );
# Add all N level elements to the subset
# Loop through all elements and check if it is an ancestor
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Element ' | sElement | ' is consolidated' );
EndIf;
nElCount = DIMSIZ ( sDimension );
n = 1;
WHILE ( n <= nElCount );
sEl = DIMNM( sDimension, n );
IF( DTYPE( sDimension, sEl) @<> 'C' & ELISANC( sDimension, sElement, sEl ) = 1 );
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Inserting element ' | sEl | ' into subset ' | sSubset | ' on dimension ' | sDimension);
EndIf;
If( pDebug <= 1 );
SubsetElementInsert( sDimension, sSubset, sEl, nIndex );
EndIf;
EndIf;
n = n + 1;
END;
Else;
# Add the element to the subset
If ( pDebug >= 1 );
AsciiOutput( sDebugFile, 'Inserting element ' | sElement | ' into subset ' | sSubset | ' on dimension ' | sDimension);
EndIf;
If( pDebug <= 1 );
SubsetElementInsert( sDimension, sSubset, sElement, nIndex );
EndIf;
EndIf;
nIndex = nIndex + 1;
sLastDelim = sChar;
# Clear the word
sWord = '';
Else;
sWord = sWord | sChar;
EndIf;
EndIf;
EndIf;
nChar = nChar + nAddExtra + 1;
If( pDebug >= 1 );
sMessage = 'Current word is: ' | sWord | ' at ' | NumberToString(nChar - 1);
AsciiOutput( sDebugFile, sMessage );
EndIf;
END;
573,4
#****Begin: Generated Statements***
#****End: Generated Statements****
574,4
#****Begin: Generated Statements***
#****End: Generated Statements****
575,40
#****Begin: Generated Statements***
#****End: Generated Statements****
#####################################################################################
##~~Copyright bedrocktm1.org 2011 www.bedrocktm1.org/how-to-licence.php Ver 3.1.0~~##
#####################################################################################
### Initialise Debug ###
If( pDebug >= 1 );
# Set debug file name
sDebugFile = cDebugFile | 'Epilog.debug';
# Log errors
If( nErrors <> 0 );
AsciiOutput( sDebugFile, 'Errors Occurred' );
EndIf;
# Log finish time
AsciiOutput( sDebugFile, 'Process Finished: ' | TimSt( Now, '\d-\m-\Y \h:\i:\s' ) );
EndIf;
### If errors occurred terminate process with a major error status ###
If( nErrors <> 0 );
ProcessQuit;
EndIf;
### End Epilog ###
576,CubeAction=1511DataAction=1503CubeLogChanges=0
930,0
638,1
804,0
1217,1
900,
901,
902,
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,""