601,100 602,"Sys.FeedersCheck" 562,"NULL" 586, 585, 564, 565,"x`\a2ZxJvP@wCZV\K^fwdcQ2aA4yCVZGO5UP>Rn2G[FaExAqYOgd[;g@gLHdLk`?:miVY`MkB1Fm<;Me8Lgsn4BF`[G7kttPzJ5Fg?3fc>;toq2eVS^fDBKjSHGRf7SlE66SdIRods3rx2IVKdokx\w36WtT40" 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,5 pCube pMeasuresDim pValue pOverrideEls pUndo 561,5 2 2 2 1 1 590,5 pCube,"" pMeasuresDim,"" pValue,"" pOverrideEls,1 pUndo,0 637,5 pCube,"Cube" pMeasuresDim,"OPTIONAL: The last cube dimension is used if omitted" pValue,"Value in the Measures dimension to be checked" pOverrideEls,"Re-creation of the elements for feeding analysis if they exist" pUndo,"Revert all metadata to its original state" 577,0 578,0 579,0 580,0 581,0 582,0 603,0 572,298 #****Begin: Generated Statements*** #****End: Generated Statements**** ################################################################################################# ## Cube over-/under- feed analysis ## Version: 1.0.1 ## Author: Alexey Zaitsev ################################################################################################# ### Variables ### sTempDim = '###FeederElements'; sFeedersView = '###View_Feeders'; sFeedersSub = '###Sub_Feeders'; ### Constants ### # >>> set the correct values without slashes cDirDataFiles = 'datafiles'; cLogFiles = 'logfiles'; cThisProcName = GetProcessName(); cMsgErrorContent = 'ErrorMsg: %sMessage%'; cTimeStamp = TimSt( Now, '\Y\m\d\h\i\s' ); cRandomInt = NumberToString( INT( RAND( ) * 1000 )); cTempName = cThisProcName |'-'| cTimeStamp |'-'| cRandomInt; сDirModelPath = DELET (GetProcessErrorFileDirectory, LONG(GetProcessErrorFileDirectory) - LONG(cLogFiles) - 1, LONG(cLogFiles) + 1); If (cDirDataFiles @= ''); cDirDataFiles = cDirDataFiles | ''; Else; cDirDataFiles = cDirDataFiles | '\'; Endif; сDirDataPath = сDirModelPath | cDirDataFiles; cRuleFile = сDirDataPath | pCube | '.RUX'; cRuleFileOriginal = сDirDataPath | pCube | ' - copy.RUX'; cLogFile = GetProcessErrorFileDirectory | cThisProcName | '.' | cTimeStamp | '.log'; cDebugFile = GetProcessErrorFileDirectory | cThisProcName | '.' | cTimeStamp | '.debug'; ### Service measures to be added ### sFeederCheck = 'FeederCheck'; sIsFed = 'IsFed'; sUnderfed = 'Underfed'; sOverfed = 'Overfed'; sOverfedRatio = 'OverfedRatio'; sFeederFlag = 'FeederFlag'; ### Validate Parameters ### nErrors = 0; # Validate cube If( Trim( pCube ) @= '' ); sMessage = 'No cube specified.'; nErrors = nErrors + 1; ASCIIOutput( cLogFile, Expand( cMsgErrorContent ) ); ElseIf( CubeExists( pCube ) = 0 ); sMessage = Expand( 'Cube ''%pCube%'' does not exist.' ); nErrors = nErrors + 1; ASCIIOutput( cLogFile, Expand( cMsgErrorContent ) ); EndIf; # Validate measure dimension If( Trim( pMeasuresDim ) @<> '' & DimensionExists( pMeasuresDim ) = 0 ); nErrors = nErrors + 1; sMessage = 'Wrong dimension specified.'; ASCIIOutput( cLogFile, Expand( cMsgErrorContent ) ); EndIf; ### Determine cube measure dimension and setting up the measure dimension ### If( Trim( pMeasuresDim ) @= '' ); sMeasuresDim = TabDim( pCube, CubeDimensionCountGet( pCube ) ); Else; sMeasuresDim = pMeasuresDim; EndIf; # Validate target measure element If( Trim( pValue ) @= ''); sMessage = 'No measure element specified.'; nErrors = nErrors + 1; ASCIIOutput( cLogFile, Expand( cMsgErrorContent ) ); ElseIf( Dimix ( sMeasuresDim, pValue ) = 0); sMessage = Expand( 'Element ''%pValue%'' does not exist.' ); nErrors = nErrors + 1; ASCIIOutput( cLogFile, Expand( cMsgErrorContent ) ); EndIf; # Create a temporary dimension with service measures for loops and validations (necessary regardless of pUndo flag value) If( DimensionExists ( sTempDim ) <> 0 ); DimensionDestroy ( sTempDim ); Endif; DimensionCreate( sTempDim ); sElName = sFeederCheck; sElType = 'C'; DimensionElementInsertDirect (sTempDim, '', sElName, sElType); sElName = sIsFed; sElType = 'C'; DimensionElementInsertDirect (sTempDim, '', sElName, sElType); sElName = sUnderfed; sElType = 'N'; DimensionElementInsertDirect (sTempDim, '', sElName, sElType); sElName = sOverfed; sElType = 'N'; DimensionElementInsertDirect (sTempDim, '', sElName, sElType); sElName = sOverfedRatio; sElType = 'C'; DimensionElementInsertDirect (sTempDim, '', sElName, sElType); sElName = sFeederFlag; sElType = 'N'; DimensionElementInsertDirect (sTempDim, '', sElName, sElType); DimensionElementComponentAddDirect (sTempDim, sFeederCheck, sIsFed, 1); DimensionElementComponentAddDirect (sTempDim, sFeederCheck, sUnderfed, 1); DimensionElementComponentAddDirect (sTempDim, sFeederCheck, sOverfed, 1); DimensionElementComponentAddDirect (sTempDim, sFeederCheck, sOverfedRatio, 1); DimensionElementComponentAddDirect (sTempDim, sIsFed, sFeederFlag, 1); DimensionElementComponentAddDirect (sTempDim, sOverfedRatio, sOverfed, 1); DimensionElementComponentAddDirect (sTempDim, sOverfedRatio, sIsFed, 1); # Validate if service measures exist in the target dimension nTempDimSize = DimSiz( sTempDim ); nCount = 1; While (nCount <= nTempDimSize); sElName = DimNm(sTempDim, nCount); If ( pOverrideEls <> 1 & pUndo <> 1 ); If (Dimix (sMeasuresDim, sElName) <> 0); sMessage = Expand( 'Element ''%sElName%'' already exists in the measure dimension.' ); nErrors = nErrors + 1; ASCIIOutput( cLogFile, Expand( cMsgErrorContent ) ); Endif; Else; If (Dimix (sMeasuresDim, sElName) <> 0); DimensionElementDelete (sMeasuresDim, sElName); Endif; Endif; nCount = nCount + 1; End; ### Check for errors before continuing ### If( nErrors <> 0 ); DimensionDestroy ( sTempDim ); ProcessQuit; EndIf; ### Clone service measures to the Measures dimension ### If( pUndo <> 1 ); nTempDimSize = DimSiz( sTempDim ); nCount = 1; While (nCount <= nTempDimSize); sElName = DimNm ( sTempDim, nCount ); sElType = DType ( sTempDim, sElName); DimensionElementInsertDirect ( sMeasuresDim, '', sElName, sElType ); If (sElType @= 'C' & ElCompN( sTempDim, sElName ) > 0); nChildren = ElCompN( sTempDim, sElName ); nChildrenCount = 1; While( nChildrenCount <= nChildren ); sChildEl = ElComp( sTempDim, sElName, nChildrenCount ); DimensionElementComponentAddDirect ( sMeasuresDim, sElName, sChildEl, 1 ); nChildrenCount = nChildrenCount + 1; End; Endif; nCount = nCount + 1; End; Endif; ### Prepare rules ### If (FileExists ( cRuleFileOriginal ) = 1); # Revert rules to the original state RuleLoadFromFile ( pCube, cRuleFileOriginal ); If ( pUndo = 1 ); # Remove a copy of original rules sCommandLine = 'cmd /C del /Q "' | cRuleFileOriginal | '"'; # AsciiOutput( cDebugFile, sCommandLine ); ExecuteCommand (sCommandLine, 0); Endif; ElseIf ( pUndo <> 1 ); # Making a copy of original rules sCommandLine = 'cmd /C copy /A /Y "' | cRuleFile | '" "' | cRuleFileOriginal | '"'; # AsciiOutput( cDebugFile, sCommandLine ); ExecuteCommand (sCommandLine, 0); Endif; ### Append extra rules ### If( pUndo <> 1 ); # Create rule dims enumerations nCount = 1; While( TabDim( pCube, nCount ) @<> '' ); sDim = TabDim( pCube, nCount ); If (nCount = 1); sTempEnum01 = '''' | sDim | ''''; sTempEnum02 = '!' | sDim; Else; sTempEnum01 = sTempEnum01 | ', ''' | sDim | ''''; sTempEnum02 = sTempEnum02 | ', !' | sDim; Endif; nCount = nCount + 1; End; # Create rules and append extra rules sRuleText000 = Expand('#Region FeedersCheck ++++++++++++++++#'); sRuleText010 = Expand('[''%sMeasuresDim%'':''%sFeederFlag%''] = N: 1;'); sRuleText020 = Expand('[''%sMeasuresDim%'':''%sUnderfed%''] = N: If ([''%sMeasuresDim%'':''%sIsFed%''] = 0 & [''%sMeasuresDim%'':''%pValue%''] <> 0, 1, 0);'); sRuleText030 = Expand('[''%sMeasuresDim%'':''%sUnderfed%''] = C: ConsolidateChildren(%sTempEnum01%);'); sRuleText040 = Expand('[''%sMeasuresDim%'':''%sOverfed%''] = N: If ([''%sMeasuresDim%'':''%sIsFed%''] > 0 & [''%sMeasuresDim%'':''%pValue%''] = 0, 1, 0);'); sRuleText050 = Expand('[''%sMeasuresDim%'':''%sOverfed%''] = C: ConsolidatedCount(2, '''', %sTempEnum02%);'); sRuleText060 = Expand('[''%sMeasuresDim%'':''%sOverfedRatio%''] = C: [''%sMeasuresDim%'':''%sOverfed%''] \ [''%sMeasuresDim%'':''%sIsFed%''];'); sRuleText070 = Expand('[''%sMeasuresDim%'':''%sFeederCheck%''] = C: If ([''%sMeasuresDim%'':''%sUnderfed%''] <> 0, -1 * ABS([''%sMeasuresDim%'':''%sUnderfed%'']), If ([''%sMeasuresDim%'':''%sOverfed%''] <> 0, 1 * [''%sMeasuresDim%'':''%sOverfed%''], 0));'); sRuleText990 = Expand('#EndRegion +++++++++++++++++++++++++++#'); sFeederText000 = Expand('#Region FeedersCheck ++++++++++++++++#'); sFeederText010 = Expand('[''%sMeasuresDim%'':''%pValue%''] => [''%sMeasuresDim%'':''%sFeederFlag%''], [''%sMeasuresDim%'':''%sOverfed%''];'); sFeederText990 = Expand('#EndRegion +++++++++++++++++++++++++++#'); sRuleText = sRuleText000 | CHAR(13) | sRuleText010 | sRuleText020 | sRuleText030 | sRuleText040 | sRuleText050 | sRuleText060 | sRuleText070 | CHAR(13) | sRuleText990; sFeederText = sFeederText000 | CHAR(13) | sFeederText010 | CHAR(13) | sFeederText990; # AsciiOutput( cDebugFile, 'sRuleText: ' | sRuleText ); # AsciiOutput( cDebugFile, 'sFeederText: ' | sFeederText ); CubeRuleAppend(pCube, sRuleText, 1); CubeRuleAppend(pCube, sFeederText, 0); Endif; ### Create over-/under- feed analysis view ### If (ViewExists ( pCube, sFeedersView ) = 1); ViewDestroy ( pCube, sFeedersView ); Endif; If (SubsetExists (sMeasuresDim, sFeedersSub) = 1); SubsetDestroy (sMeasuresDim, sFeedersSub); Endif; # Create measures subset If( pUndo <> 1 ); sMDX = '{ [' | sMeasuresDim | '].[' | pValue | '], DESCENDANTS([' | sMeasuresDim | '].[' | sFeederCheck | ']) }'; SubsetCreateByMDX (sFeedersSub, sMDX, sMeasuresDim, 0); Endif; # Create target view If( pUndo <> 1 ); ViewCreate ( pCube, sFeedersView, 0 ); ViewRowSuppressZeroesSet( pCube, sFeedersView, 1); nCount = 1; sFirstNonMeasuresDim = ''; While( TabDim( pCube, nCount ) @<> '' ); sDim = TabDim( pCube, nCount ); If (sDim @= sMeasuresDim); ViewSubsetAssign ( pCube, sFeedersView, sDim, sFeedersSub); ViewColumnDimensionSet ( pCube, sFeedersView, sDim, 1); Else; If ( sFirstNonMeasuresDim @= '' ); sFirstNonMeasuresDim = sDim; ViewRowDimensionSet ( pCube, sFeedersView, sFirstNonMeasuresDim, 1); Else; ViewTitleDimensionSet ( pCube, sFeedersView, sDim ); Endif; #get first-index element sTitleEl = DimNm ( sDim, 1 ); While ( ElPar ( sDim, sTitleEl, 1 ) @<> ''); sTitleEl = ElPar ( sDim, sTitleEl, 1 ); ViewTitleElementSet ( pCube, sFeedersView, sDim, Dimix( sDim, sTitleEl) ); End; Endif; nCount = nCount + 1; End; EndIf; # Format the service measures If( pUndo <> 1 ); If ( Dimix( '}ElementAttributes_'| sMeasuresDim, 'Format' ) = 0 ); AttrInsert( sTempDim, '', 'Format', 'S' ); Endif; sElName = sFeederCheck; sElFormat = 'b:#,##0" Over";#,##0" Under";"Ok "'; AttrPutS( sElFormat, sMeasuresDim, sElName, 'Format' ); sElName = sIsFed; sElFormat = 'b:#,##0" Yes";-;"No "'; AttrPutS( sElFormat, sMeasuresDim, sElName, 'Format' ); sElName = sUnderfed; sElFormat = 'b:#,##0" Yes";#,##0" Yes";-'; AttrPutS( sElFormat, sMeasuresDim, sElName, 'Format' ); sElName = sOverfed; sElFormat = 'b:#,##0" Yes";-;-'; AttrPutS( sElFormat, sMeasuresDim, sElName, 'Format' ); sElName = sOverfedRatio; sElFormat = 'b:0.00%;-0.00%'; AttrPutS( sElFormat, sMeasuresDim, sElName, 'Format' ); sElName = sFeederFlag; sElFormat = 'b:"+";"+";-'; AttrPutS( sElFormat, sMeasuresDim, sElName, 'Format' ); Endif; 573,3 #****Begin: Generated Statements*** #****End: Generated Statements**** 574,3 #****Begin: Generated Statements*** #****End: Generated Statements**** 575,10 #****Begin: Generated Statements*** #****End: Generated Statements**** # Remove temporary object If( DimensionExists ( sTempDim ) <> 0 ); DimensionDestroy ( sTempDim ); Endif; 576,CubeAction=1511 DataAction=1503 CubeLogChanges=0 930,0 638,1 804,0 1217,0 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,""