-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTECH_double counting I.pro
1619 lines (1272 loc) · 58.5 KB
/
TECH_double counting I.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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
601,100
602,"TECH_double counting I"
562,"SUBSET"
586,"}Clients"
585,"}Clients"
564,
565,"t7eDgg?w7:xCq4p4TVNGa1Bq368HEOZP@BKm=kla;Zt5<B]iBjHZ8`hr4>XHq:kGUpCWGFuE0WLa<kwgwsGJXhc9Ay<nXXDRSI51a`@PvyePqvzAI1nY@:L?Cz0QZ9E?>@ItQd:K56ewBfFu<QC[ddQaGz<giDal^`?OSLrgQp1iqxWVMtK1a0Tsgh^CYbuO7eQvn;eA"
559,1
928,0
593,
594,
595,
597,
598,
596,
800,
801,
566,0
567,","
588,"."
589,","
568,""""
570,
571,All
569,0
592,0
599,1000
560,13
pName
pMode
pAction
pOutput_QuickCheck
pOutput_CreateTextFile
pOutput_AddSubsetAndAttrToOriginalDim
pOutput_AddDimensionProperty
pOutput_KeepTempCube
pOutput_DetermineWeights
pAddHelperAttributes
pHier
pConsol
pConsol_Exclude
561,13
2
1
1
1
1
1
1
1
1
1
2
2
2
590,13
pName,""
pMode,3
pAction,1
pOutput_QuickCheck,0
pOutput_CreateTextFile,1
pOutput_AddSubsetAndAttrToOriginalDim,1
pOutput_AddDimensionProperty,1
pOutput_KeepTempCube,1
pOutput_DetermineWeights,1
pAddHelperAttributes,1
pHier,""
pConsol,""
pConsol_Exclude,""
637,13
pName,"Inspect what dimension / cube for double countings ?"
pMode,"Inspection Mode ? ( 1 = 1 dimension / 2 = dimensions of 1 cube / 3 = all dimensions 'light' / 4 = all dimensions 'full' / 5 = insert Input element / All else = No action )"
pAction,"Action ? ( 1 = Destroy objects & Run again / 2 = Destroy objects )"
pOutput_QuickCheck,"Quick check (stop at the first double counting issue) ? ( 0 = No / All else = Yes )"
pOutput_CreateTextFile,"Create a text file that contains the double counting elements ? ( 1 = Double countings, 2 = Number of double countings, All else = No )"
pOutput_AddSubsetAndAttrToOriginalDim,"Add a subset and attribute to the dimension containing the double countings ? ( 0 = No, All else = Yes )"
pOutput_AddDimensionProperty,"Add a property to the cube }DimensionProperties that contains the number of double counting elements ? ( 0 = No, All else = Yes )"
pOutput_KeepTempCube,"Keep the temporary cube used to store the combinations ? ( 0 = No, All else = Yes )"
pOutput_DetermineWeights,"Determine the weights for double counted elements ? ( 0 = No, All else = Yes )"
pAddHelperAttributes,"Add helper attributes in the new cube ? ( 0 = No, All else = Yes )"
pHier,"Target Hierarchy (will use default if left blank) (does not accept wildcards)"
pConsol,"Target Consolidation (does not accept wildcards)"
pConsol_Exclude,"Consolidation to exclude from processing (does not accept wildcards)"
577,1
vElement
578,1
2
579,1
1
580,1
0
581,1
0
582,1
VarType=32ColType=827
603,0
572,1174
#****Begin: Generated Statements***
#****End: Generated Statements****
#Region IntroduceThisProcess
####################################################
# Wim Gielis
# January 2024
# https://www.wimgielis.com
####################################################
#
# This process checks dimensions for double countings.
# A double counting is defined as a case where 1 element (level 0 or consolidated) rolls up in more than 1 way in a certain consolidated element.
# This process supports alternative hierarchies (PA-speak).
#
# Element weights are ignored when tracing double countings, but the effect of each double counting can be expressed.
# For example, element A rolls up 3 times in element B, with cumulative weight of 1 ( +1, +1, -1 ). This can be shown in a cube.
#
# Only dimensions are checked for double countings. It could be that there are no data on these elements and hence no double countings,
# but as the potential to have data is present, we list them anyway.
# You can use other TI processes to check if an element has data in any of the cubes that use the said dimension.
#
# This main process will execute 'TECH_double counting II', unless no double countings are detected.
# In the absence of this helper process, the process will stop and error out.
#
# The parameter pMode determines to what extent dimensions will be inspected:
# If pMode = 1, you inspect 1 dimension. Specify the dimension name in pName. Wildcards * and ? are allowed.
# If pMode = 2, you inspect all dimensions of a cube. Specify the cube name in pName.
# If pMode = 3, you inspect all application dimensions and create a 'light' output. pName is ignored.
# If pMode = 4, you inspect all application dimensions and create a 'full' output. pName is ignored.
# If pMode = 5, you can insert a measure in the cube }DimensionProperties where you can skip dimensions from the treatment. pName is ignored.
#
# When pMode = 1:
# - a hierarchy (PA-speak) (pHier) can be used. For its name, wildcards are not accepted. Double countings are only searched within the elements of this hierarchy.
# If no pConsol is used, then the main hierarchy of the dimension is investigated. It does not mean that all hierarchies are investigated, unless you only have 1 hierarchy.
# - a consolidated element (pConsol) can be used. For its name, wildcards are not accepted. Double countings are only searched below this consolidated element.
# - another consolidated element (pConsol_Exclude) can be used. For its name, wildcards are not accepted. Double countings are not searched below this consolidated element.
#
# A good idea might be to have a chore running every few days or every week, traversing all important hierarchies / hierarchies that are prone to get double countings.
# You can choose for a full or light output.
#
# The reason for number 5 is that long dimensions with many levels can take some time to process, so you can skip them.
# In TM1 even clients with Admin privileges cannot manually insert an element in a control dimension like }DimensionProperties. Hence the TI approach.
#
# This process can provide output / change existing TM1 objects in the following way:
# - by creating a text file in the TM1 logging directory, containing the double countings per hierarchy ( pOutput_CreateTextFile )
# - by adding a subset to the dimension being investigated, containing the double countings ( pOutput_AddSubsetAndAttrToOriginalDim )
# - by adding a property to the cube }DimensionProperties, containing the number of double countings per hierarchy ( pOutput_AddDimensionProperty )
# - by creating and not deleting a new cube called '}TECH_Double_Countings' ( pOutput_KeepTempCube )
#
# When you execute the process with pMode = 2 or 3, then you have less options. The script does not do all the fancy stuff in these cases.
# The parameters that are turned off, are:
# - pOutput_CreateTextFile
# - pOutput_KeepTempCube
# - pOutput_DetermineWeights
# - pAddHelperAttributes
#
# pOutput_QuickCheck can be interesting when you just want to know, for 1 dimension/hierarchy, whether 1 or more double counting issue exists or not.
# At the first encounter of such an issue, the process finishes. A global string variable will be set. Detailed information is not available.
# For detailed information you need to use other process outputs.
#
# The main reasoning behind this, is that several objects would overwrite each other anyway. Hence there is limited benefit of keeping the options in.
# So the idea is to use pMode = 2 or 3 (to save time, you can do this in a loop instead of you firing off one after the other).
# Once you have identified the dimension(s) with double countings, you can run the same process again on this dimension with pMode = 1 and all options activated.
# That way, you have the best of both worlds: speed and functionality ;-)
#
# The process will also store other information in the }DimensionProperties cube:
# - number of levels
# - number of elements
# - run time of the process
#
# ### This has been turned off for now
# ### In case a dimension is too long and/or contains too many consolidations, this process can take a while (even though it's very efficient)
# ### Therefore, I estimate onbeforehand the number of combinations that someone might have to process through loops,
# ### given that every element can potentially roll up in every consolidated element (except level 1 consolidations).
# ### My loops are more efficient than this strategy and I limit the combinations to a great extent, but still this measure of the potential number of combinations
# ### indicates whether we should attempt it or not. That theoretical number of combinations is set at 50,000,000 for the moment. You can change this limit in the process if you want.
#
# After having applied the code to a number of TM1 models, here are my results:
# - usually the Period / Month dimension has double countings.
# For example, a 'YTD' consolidation groups 12 consolidated YTD elements for the periods (no double counting)
# but underneath the 12 YTD elements you have the level 0 periods. These roll up several times in the "YTD" element. This is okay and not a problem.
# - I have seen dimensions for Cost centers, Accounts, Products, Employees and many more suffering from double countings. This can be problematic and the exact reason why I wrote these processes.
# - my best advice to you use this tool is:
# 1. Run the tool once with "pMode = 5". The other parameters do not matter here. You will create a }DimensionProperties element.
# 2. Single out the large dimensions with a high LevelCount (DNLEV) and run the tool with "pMode = 1" for these dimensions only.
# Inspect the results in attributes, subsets and a text file - depending on your choices.
# 3. When you are done with these big dimensions, put a 1 for these dimensions in the }DimensionProperties cube on the measure "Skip dimension for double counting"
# 4. Run the tool with "pMode = 3" or "pMode = 4". 4 gives a richer output than 3 but it could take somewhat longer.
#
# A global numeric variable will be populated with the number of duplicates found.
#
# Technical note: this process can use recursion and execute itself a number of times (iteratively) using the correct parameter values.
# You will notice in the TM1 Server message log that the process is called a number of times.
#
####################################################
# Internet resources:
# http://www.tm1forum.com/viewtopic.php?f=3&t=12706
#####
# Add the following process(es) to this TM1 model:
# - TECH_double counting II
# - TECH_folder for output
#####
#EndRegion IntroduceThisProcess
#Region CallThisProcess
## call this custom process as, for instance:
If( 1 = 0 );
NumericGlobalVariable( 'Number_of_duplicates' );
NumericGlobalVariable( 'Double_counting_exists' );
ExecuteProcess( 'TECH_double counting I'
, 'pName', 'DIMENSION NAME / CUBE NAME / leave empty'
, 'pMode', 1 / 2 / 3 / 4 / 5
, 'pAction', 1
, 'pOutput_QuickCheck', 0
, 'pOutput_CreateTextFile', 1
, 'pOutput_AddSubsetAndAttrToOriginalDim', 1
, 'pOutput_AddDimensionProperty', 1
, 'pOutput_KeepTempCube', 1
, 'pOutput_DetermineWeights', 1
, 'pAddHelperAttributes', 1
, 'pHier', 'HIERARCHY NAME'
, 'pConsol', 'CONSOLIDATED ELEMENT NAME'
, 'pConsol_Exclude', 'ANOTHER CONSOLIDATED ELEMENT NAME'
);
TextOutput( 'Number of double countings.txt', NumberToString( Number_of_duplicates ));
TextOutput( 'Number of double countings.txt', NumberToString( Double_counting_exists ));
EndIf;
#EndRegion CallThisProcess
## Constants
cAPP_NAME_TM1 = 'TECH_Double_Countings';
cAPP_NAME_TM1_Control = '}' | cAPP_NAME_TM1;
# a cube for calculations
vCube = cAPP_NAME_TM1_Control;
vDim1 = cAPP_NAME_TM1_Control | '_All';
vDim2 = cAPP_NAME_TM1_Control | '_Conso';
vDim3 = cAPP_NAME_TM1_Control | '_Msr';
NumericGlobalVariable( 'Number_of_duplicates' );
NumericGlobalVariable( 'Double_counting_exists' );
vSkip_processing = 0;
# a text file for output
StringGlobalVariable( 'cDestination_Folder' );
ExecuteProcess( 'TECH_folder for output', 'pSubfolder', 'Double counting', 'pMainFolder', '1+' );
vFile = cDestination_Folder | cAPP_NAME_TM1 | '_' | TimSt( Now, '\Y\m\d_\h\i\s' ) | '_output.csv';
DataSourceASCIIDelimiter = Char( 9 );
DataSourceASCIIQuoteCharacter = '';
# a second process that can be executed
cProcess = 'TECH_double counting II';
# Constants to be used in this proces
c00 = 'Default';
c01 = 'Weight';
c02 = cAPP_NAME_TM1;
c03 = 'Count of instances';
c04 = 'Double counting issue';
c05 = 'Descendant';
c06 = 'Consolidation';
c07 = '# double counting';
c08 = 'Skip dimension for double counting';
c09 = 'Double counting: nr of levels';
c10 = 'Double counting: nr of elements';
c11 = 'Double counting: run time';
dp = '}DimensionProperties';
# A temporary string
cTemp = cAPP_NAME_TM1_Control | '_tmp';
# the maximum number of possible combinations (iterations) above which this process will not attempt to calculate all potential double counting issues
cMaxIterations = 50000000;
pAction = Int( pAction );
If( pAction < 1 % pAction > 2 );
ProcessQuit;
EndIf;
pMode = Int( pMode );
If( pMode < 1 % pMode > 5 );
ProcessQuit;
EndIf;
# Certain choices are better not to be used together
If( pAction > 1 );
pHier = '';
pConsol = '';
pConsol_Exclude = '';
EndIf;
If( Scan( '*', pName ) > 0 % Scan( '?', pName ) > 0 );
pOutput_QuickCheck = 0;
pHier = '';
pConsol = '';
pConsol_Exclude = '';
EndIf;
If( pOutput_QuickCheck <> 0 );
pOutput_CreateTextFile = 0;
pOutput_AddSubsetAndAttrToOriginalDim = 0;
pOutput_AddDimensionProperty = 0;
pOutput_KeepTempCube = 0;
pOutput_DetermineWeights = 0;
pAddHelperAttributes = 0;
EndIf;
If( pOutput_CreateTextFile <> 0 %
pOutput_AddSubsetAndAttrToOriginalDim <> 0 %
pOutput_AddDimensionProperty <> 0 %
pOutput_KeepTempCube <> 0 %
pOutput_DetermineWeights <> 0 %
pAddHelperAttributes <> 0 );
pOutput_QuickCheck = 0;
EndIf;
vStartTime = Now;
####################
# The main code starts here #
####################
If( pMode = 1 );
#############################
# Treat 1 dimension
#############################
If( DimensionExists( pName ) > 0 );
pDim = HierarchyElementPrincipalName( '}Dimensions', '}Dimensions', pName );
# vCheckDp = 0;
# If( Dimix( dp, c08 ) = 0 );
# vCheckDp = 1;
# ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
# vCheckDp = 1;
# EndIf;
# If( vCheckDp = 0 );
# LogOutput( 'INFO', 'Dimension ''' | pDim | ''' is skipped for treatment in the cube ''' | dp | '''.' );
# DataSourceType = 'NULL';
# EndIf;
# this is the standard case: execute the remainder of this process for 1 dimension
# just follow this script
# we will break out of the script if we need to loop over several dimensions
Else;
# allow for wildcards in the dimension name pName
vDims = '}Dimensions';
SubsetCreateByMDX( 'tmp_', '{TM1FilterByPattern( Except( TM1SubsetAll( [' | vDims | '].[' | vDims | '] ), TM1FilterByPattern( TM1SubsetAll( [' | vDims | '].[' | vDims | '] ), "}*") ), "' | pName | '")}', vDims, 1 );
# Loop through the matches, if any
mm = 1;
While( mm <= HierarchySubsetGetSize( vDims, vDims, 'tmp_' ));
pDim = HierarchySubsetGetElementName( vDims, vDims, 'tmp_', mm );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 0 );
LogOutput( 'INFO', 'The hierarchy ''' | pDim | ''' is skipped for treatment in the cube ''' | dp | '''.' );
DataSourceType = 'NULL';
Else;
ExecuteProcess( GetProcessName
, 'pName', pDim
, 'pMode', 1
, 'pAction', pAction
, 'pOutput_QuickCheck', pOutput_QuickCheck
, 'pOutput_CreateTextFile', 0
, 'pOutput_AddSubsetAndAttrToOriginalDim', pOutput_AddSubsetAndAttrToOriginalDim
, 'pOutput_AddDimensionProperty', pOutput_AddDimensionProperty
, 'pOutput_KeepTempCube', 0
, 'pOutput_DetermineWeights', 0
, 'pAddHelperAttributes', 0
, 'pHier', ''
, 'pConsol', pConsol
, 'pConsol_Exclude', pConsol_Exclude
);
NumericGlobalVariable( 'ProcessReturnCode' );
If( ProcessReturnCode = ProcessExitSeriousError );
ProcessError;
ElseIf( ProcessReturnCode = ProcessExitByQuit );
ProcessQuit;
EndIf;
EndIf;
mm = mm + 1;
End;
# a text file for output
If( pOutput_CreateTextFile <> 0 );
TextOutput( vFile, 'Dimension', 'Double counted element', 'Parents' );
mm = 1;
While( mm <= HierarchySubsetGetSize( vDims, vDims, 'tmp_' ));
pDim = HierarchySubsetGetElementName( vDims, vDims, 'tmp_', mm );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
s = 1;
While( s <= HierarchySubsetGetSize( pDim, pDim, c02 ));
vDC = HierarchySubsetGetElementName( pDim, pDim, c02, s );
vParents = ElementAttrS( pDim, pDim, vDC, c02 );
TextOutput( vFile, pDim, vDC, vParents );
s = s + 1;
End;
EndIf;
EndIf;
mm = mm + 1;
End;
EndIf;
# a numeric global variable
Number_of_duplicates = 0;
mm = 1;
While( mm <= HierarchySubsetGetSize( vDims, vDims, 'tmp_' ));
pDim = HierarchySubsetGetElementName( vDims, vDims, 'tmp_', mm );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
Number_of_duplicates = Number_of_duplicates + HierarchySubsetGetSize( pDim, pDim, c02 );
EndIf;
EndIf;
mm = mm + 1;
End;
DataSourceType = 'NULL';
EndIf;
# We could also look for attributes (aliases) on the dimension }Dimensions and test if the dimension pattern exists
# This is not done here, however. See other processes if wanted.
ElseIf( pMode = 2 );
#############################
# Treat the dimensions of 1 cube
#############################
pCube = Trim( pName );
If( CubeExists( pCube ) > 0 );
pCube = HierarchyElementPrincipalName( '}cubes', '}cubes', pCube );
# m loops over the dimensions in the cube
m = 1;
While( m <= CubeDimensionCountGet( pCube ));
pDim = Tabdim( pCube, m );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 0 );
LogOutput( 'INFO', 'Dimension ''' | pDim | ''' is skipped for treatment in the cube ''' | dp | '''.' );
DataSourceType = 'NULL';
Else;
ExecuteProcess( GetProcessName
, 'pName', pDim
, 'pMode', 1
, 'pAction', pAction
, 'pOutput_QuickCheck', pOutput_QuickCheck
, 'pOutput_CreateTextFile', 0
, 'pOutput_AddSubsetAndAttrToOriginalDim', pOutput_AddSubsetAndAttrToOriginalDim
, 'pOutput_AddDimensionProperty', pOutput_AddDimensionProperty
, 'pOutput_KeepTempCube', 0
, 'pOutput_DetermineWeights', 0
, 'pAddHelperAttributes', 0
, 'pHier', ''
, 'pConsol', pConsol
, 'pConsol_Exclude', pConsol_Exclude
);
NumericGlobalVariable( 'ProcessReturnCode' );
If( ProcessReturnCode = ProcessExitSeriousError );
ProcessError;
ElseIf( ProcessReturnCode = ProcessExitByQuit );
ProcessQuit;
EndIf;
EndIf;
m = m + 1;
End;
# a text file for output
If( pOutput_CreateTextFile <> 0 );
TextOutput( vFile, 'Dimension', 'Double counted element', 'Parents' );
m = 1;
While( m <= CubeDimensionCountGet( pCube ));
pDim = Tabdim( pCube, m );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
s = 1;
While( s <= HierarchySubsetGetSize( pDim, pDim, c02 ));
vDC = HierarchySubsetGetElementName( pDim, pDim, c02, s );
vParents = ElementAttrS( pDim, pDim, vDC, c02 );
TextOutput( vFile, pDim, vDC, vParents );
s = s + 1;
End;
EndIf;
EndIf;
m = m + 1;
End;
EndIf;
# a numeric global variable
Number_of_duplicates = 0;
m = 1;
While( m <= CubeDimensionCountGet( pCube ));
pDim = Tabdim( pCube, m );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
Number_of_duplicates = Number_of_duplicates + HierarchySubsetGetSize( pDim, pDim, c02 );
EndIf;
EndIf;
m = m + 1;
End;
Else;
LogOutput( 'ERROR', 'Cube ''' | pCube | ''' does not exist.' );
ProcessError;
EndIf;
DataSourceType = 'NULL';
ElseIf( pMode = 3 );
#############################
# Treat all application dimensions in the TM1 model and create a 'light' output
#############################
# d loops over the dimensions in the model
d = 1;
While( d <= ElementCount( '}Dimensions', '}Dimensions' ));
pDim = ElementName( '}Dimensions', '}Dimensions', d );
If( Subst( pDim, 1, 1 ) @<> '}' );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 0 );
LogOutput( 'INFO', 'Dimension ''' | pDim | ''' is skipped for treatment in the cube ''' | dp | '''.' );
DataSourceType = 'NULL';
Else;
ExecuteProcess( GetProcessName
, 'pName', pDim
, 'pMode', 1
, 'pAction', pAction
, 'pOutput_QuickCheck', pOutput_QuickCheck
, 'pOutput_CreateTextFile', 0
, 'pOutput_AddSubsetAndAttrToOriginalDim', pOutput_AddSubsetAndAttrToOriginalDim
, 'pOutput_AddDimensionProperty', pOutput_AddDimensionProperty
, 'pOutput_KeepTempCube', 0
, 'pOutput_DetermineWeights', 0
, 'pAddHelperAttributes', 0
, 'pHier', ''
, 'pConsol', pConsol
, 'pConsol_Exclude', pConsol_Exclude
);
NumericGlobalVariable( 'ProcessReturnCode' );
If( ProcessReturnCode = ProcessExitSeriousError );
ProcessError;
ElseIf( ProcessReturnCode = ProcessExitByQuit );
ProcessQuit;
EndIf;
EndIf;
EndIf;
d = d + 1;
End;
# a text file for output
If( pOutput_CreateTextFile <> 0 );
TextOutput( vFile, 'Dimension', 'Double counted element' );
d = 1;
While( d <= ElementCount( '}Dimensions', '}Dimensions' ));
pDim = ElementName( '}Dimensions', '}Dimensions', d );
If( Subst( pDim, 1, 1 ) @<> '}' );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
s = 1;
While( s <= HierarchySubsetGetSize( pDim, pDim, c02 ));
vDC = HierarchySubsetGetElementName( pDim, pDim, c02, s );
vParents = ElementAttrS( pDim, pDim, vDC, c02 );
TextOutput( vFile, pDim, vDC, vParents );
s = s + 1;
End;
EndIf;
EndIf;
EndIf;
d = d + 1;
End;
EndIf;
# a numeric global variable
Number_of_duplicates = 0;
d = 1;
While( d <= ElementCount( '}Dimensions', '}Dimensions' ));
pDim = ElementName( '}Dimensions', '}Dimensions', d );
If( Subst( pDim, 1, 1 ) @<> '}' );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
Number_of_duplicates = Number_of_duplicates + HierarchySubsetGetSize( pDim, pDim, c02 );
EndIf;
EndIf;
EndIf;
d = d + 1;
End;
DataSourceType = 'NULL';
ElseIf( pMode = 4 );
#############################
# Treat all application dimensions in the TM1 model and create a 'full' output
#############################
# d loops over the dimensions in the model
d = 1;
While( d <= ElementCount( '}Dimensions', '}Dimensions' ));
pDim = ElementName( '}Dimensions', '}Dimensions', d );
If( Subst( pDim, 1, 1 ) @<> '}' );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 0 );
LogOutput( 'INFO', 'Dimension ''' | pDim | ''' is skipped for treatment in the cube ''' | dp | '''.' );
DataSourceType = 'NULL';
Else;
ExecuteProcess( GetProcessName
, 'pName', pDim
, 'pMode', 1
, 'pAction', pAction
, 'pOutput_QuickCheck', pOutput_QuickCheck
, 'pOutput_CreateTextFile', 0
, 'pOutput_AddSubsetAndAttrToOriginalDim', 1
, 'pOutput_AddDimensionProperty', 1
, 'pOutput_KeepTempCube', 0
, 'pOutput_DetermineWeights', 1
, 'pAddHelperAttributes', 0
, 'pHier', ''
, 'pConsol_Exclude', pConsol_Exclude
);
NumericGlobalVariable( 'ProcessReturnCode' );
If( ProcessReturnCode = ProcessExitSeriousError );
ProcessError;
ElseIf( ProcessReturnCode = ProcessExitByQuit );
ProcessQuit;
EndIf;
EndIf;
EndIf;
d = d + 1;
End;
# a text file for output
If( pOutput_CreateTextFile <> 0 );
TextOutput( vFile, 'Dimension', 'Double counted element' );
d = 1;
While( d <= ElementCount( '}Dimensions', '}Dimensions' ));
pDim = ElementName( '}Dimensions', '}Dimensions', d );
If( Subst( pDim, 1, 1 ) @<> '}' );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
s = 1;
While( s <= HierarchySubsetGetSize( pDim, pDim, c02 ));
vDC = HierarchySubsetGetElementName( pDim, pDim, c02, s );
vParents = ElementAttrS( pDim, pDim, vDC, c02 );
TextOutput( vFile, pDim, vDC, vParents );
s = s + 1;
End;
EndIf;
EndIf;
EndIf;
d = d + 1;
End;
EndIf;
# a numeric global variable
Number_of_duplicates = 0;
d = 1;
While( d <= ElementCount( '}Dimensions', '}Dimensions' ));
pDim = ElementName( '}Dimensions', '}Dimensions', d );
If( Subst( pDim, 1, 1 ) @<> '}' );
vCheckDp = 0;
If( ElementIndex( dp, dp, c08 ) = 0 );
vCheckDp = 1;
ElseIf( CellGetN( dp, pDim, c08 ) = 0 );
vCheckDp = 1;
EndIf;
If( vCheckDp = 1 );
If( HierarchySubsetExists( pDim, pDim, c02 ) > 0 );
Number_of_duplicates = Number_of_duplicates + HierarchySubsetGetSize( pDim, pDim, c02 );
EndIf;
EndIf;
EndIf;
d = d + 1;
End;
DataSourceType = 'NULL';
ElseIf( pMode = 5 );
#############################
# Add an element to the dimension }DimensionProperties to skip certain dimensions
#############################
If( ElementIndex( dp, dp, c08 ) = 0 );
HierarchyElementInsert( dp, dp, '', c08, 'N' );
EndIf;
DataSourceType = 'NULL';
EndIf;
# Here begins the code to treat 1 dimension
# Notice the above:
# DataSourceType = 'NULL';
# ProcessBreak;
If( DataSourceType @= 'NULL' );
pAction = 0;
EndIf;
# destroy / clean up
#######################
# the }DimensionProperties cube
If( pMode = 3
% pMode = 4 );
ViewDestroy( dp, c02 );
HierarchySubsetDestroy( '}Dimensions', '}Dimensions', c02 );
HierarchySubsetDestroy( dp, dp, c02 );
EndIf;
If( ( pMode = 1 ) & ( DimensionExists( pName ) > 0 ) );
LogOutput( 'INFO', 'START Dimension: ''' | pName | '''.' );
AsciiDelete( vFile );
pDim = pName;
If( pHier @= '' );
pHier = pDim;
Else;
If( HierarchyExists( pDim, pHier ) = 0 );
LogOutput( 'ERROR', 'The hierarchy ''' | pHier | ''' could not be found in the dimension ''' | pDim | '''.' );
ProcessError;
ElseIf( pHier @= 'Leaves' );
LogOutput( 'ERROR', 'The Leaves hierarchy in the dimension ''' | pDim | ''' will not be investigated. By definition, no double counting to be expected.' );
ProcessQuit;
EndIf;
EndIf;
If( DimensionExists( pDim ) > 0 );
If( HierarchyExists( pDim, pHier ) > 0 );
HierarchySubsetDestroy( pDim, pHier, c02 );
ElementAttrDelete( pDim, pHier, c02 );
EndIf;
EndIf;
If( ElementIndex( dp, dp, c07 ) > 0 );
# HiearchyElementDelete( '}DimensionProperties', '}DimensionProperties', c07 );
CellPutN( 0, dp, pDim, c07 );
EndIf;
# the consolidated element - include elements below
pConsol = Trim( pConsol );
If( pConsol @<> '' );
If( Scan( '*', pConsol ) > 0 % Scan( '?', pConsol ) > 0 );
LogOutput( 'ERROR', 'Item "' | pConsol | '" contains wildcards. This is not allowed.' );
ElseIf( ElementIndex( pDim, pHier, pConsol ) = 0 );
LogOutput( 'ERROR', 'Item "' | pConsol | '" does not exist in the hierarchy ''' | pDim | ':' | pHier | '''. This is not allowed.' );
ElseIf( ElementType( pDim, pHier, pConsol ) @<> 'C' );
LogOutput( 'ERROR', 'Item "' | pConsol | '" is not a consolidated element in the hierarchy ''' | pDim | ':' | pHier | '''. This is not allowed.' );
EndIf;
EndIf;
# the consolidated element - exclude elements below
pConsol_Exclude = Trim( pConsol_Exclude );
If( pConsol_Exclude @<> '' );
If( Scan( '*', pConsol_Exclude ) > 0 % Scan( '?', pConsol_Exclude ) > 0 );
LogOutput( 'ERROR', 'Item "' | pConsol_Exclude | '" contains wildcards. This is not allowed.' );
ElseIf( ElementIndex( pDim, pHier, pConsol_Exclude ) = 0 );
LogOutput( 'ERROR', 'Item "' | pConsol_Exclude | '" does not exist in the hierarchy ''' | pDim | ':' | pHier | '''. This is not allowed.' );
ElseIf( ElementType( pDim, pHier, pConsol_Exclude ) @<> 'C' );
LogOutput( 'ERROR', 'Item "' | pConsol_Exclude | '" is not a consolidated element in the hierarchy ''' | pDim | ':' | pHier | '''. This is not allowed.' );
ElseIf( ( pConsol @<> '' ) & ( ElementIndex( pDim, pHier, pConsol ) = ElementIndex( pDim, pHier, pConsol_Exclude )));
LogOutput( 'ERROR', 'Item "' | pConsol_Exclude | '" is also used for the consolidation to be included (pConsol), in the hierarchy ''' | pDim | ':' | pHier | '''. This is not allowed.' );
EndIf;
EndIf;
CubeDestroy( vCube );
DimensionDestroy( vDim1 );
DimensionDestroy( vDim2 );
DimensionDestroy( vDim3 );
# cTemp will be a cube that is used to determine the weights of an element (when double counting) into a consolidation
CubeDestroy( cTemp );
DimensionDestroy( cTemp );
# set up the objects and prepare for the real work
If( pAction = 1 );
# sanity checks
If( DimensionExists( pDim ) = 0 );
LogOutput( 'ERROR', 'Dimension ''' | pDim | ''' does not exist. The process stops.' );
ProcessError;
Else;
vDim = DimensionElementPrincipalName( '}Dimensions', pDim );
EndIf;
### Uncomment this section if you want to check for control dimensions