#****Begin: Generated Statements*** # This TI is designed to copy all data in a given cube # from one element to another, typically this would be within a # version dimension but could equally well be used to copy data # from one product to another or one week to another or on monthly basis. # Note: # - As this TI has a view as a data source it requires the implicit variables NValue, SValue and Value_is_String # - To edit this TI without VIZIER either a temp cube with 24 dims is needed as the preview data source or set the data # source to ASCII and manually edit the TI in notepad after saving to add back the required implicit view variables ### Constants ### cProcess = 'Finance Copy Process_Test'; cTimeStamp = TimSt( Now, '\Y\m\d\h\i\s' ); sRandomInt = NumberToString( INT( RAND( ) * 1000 )); cDebugFile = GetProcessErrorFileDirectory | cProcess | '.' | cTimeStamp | '.' | sRandomInt ; cDefaultView = 'Finance Copy Process_' | sRandomInt ; ### Create Target View for Target customer and Target version ### cViewTarget = pViewTarget; cTempViewTo = cViewTarget; cTempSubTo = cTempViewTo; If( ViewExists( pCube, cTempViewTo ) = 1 ); # It is highly unlikely that the view already exists as the view name contains # a random number. However it is included in case two seperate calls generate # the same random number. ViewDestroy( pCube, cTempViewTo ); EndIf; ViewCreate( pCube, cTempViewTo ); If( SubsetExists( pDimension, cTempSubTo ) = 1 ); # It is highly unlikely that the subset already exists as the subset name contains # a random number. However it is included in case two seperate calls generate # the same random number. SubsetDeleteAllElements( pDimension, cTempSubTo ); Else; SubsetCreate( pDimension, cTempSubTo ); EndIf; If( SubsetExists( pDimension1, cTempSubTo ) = 1 ); # It is highly unlikely that the subset already exists as the subset name contains # a random number. However it is included in case two seperate calls generate # the same random number. SubsetDeleteAllElements( pDimension1, cTempSubTo ); Else; SubsetCreate( pDimension1, cTempSubTo ); EndIf; ### Create Source View for source customer and source version ### cViewSource = pViewSource; cTempViewFrom = cViewSource; cTempSubFrom = cTempViewFrom; If( ViewExists( pCube, cTempViewFrom ) = 1 ); # It is highly unlikely that the view already exists as the view name contains # a random number. However it is included in case two seperate calls generate # the same random number. ViewDestroy( pCube, cTempViewFrom ); EndIf; ViewCreate( pCube, cTempViewFrom ); If( SubsetExists( pDimension, cTempSubFrom ) = 1 ); SubsetDeleteAllElements( pDimension, cTempSubFrom ); Else; SubsetCreate( pDimension, cTempSubFrom ); EndIf; If( SubsetExists( pDimension1, cTempSubFrom ) = 1 ); SubsetDeleteAllElements( pDimension1, cTempSubFrom ); Else; SubsetCreate( pDimension1, cTempSubFrom ); EndIf; ## INNER LOOP#### ### Determine Customer dimension Substitution ### i2= 1; AsciiOutput( 'Loop Log Prolog.txt', 'BEGIN INNER LOOP', pCube,NumberToString(i2),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); while (i2 <=50); pDim = 'p_Parameters'; Param1 = Dimnm(pDim, i2); pSourceCustomer = CellGetS('Customer Control Cube',Param1,'Source Customer'); pTargetCustomer = CellGetS('Customer Control Cube',Param1,'Target Customer'); ### Break the loop if any of the source or target customer not found ### ### Log Info of the inner loop parameters before the loop breaks## AsciiOutput( 'Loop Log Prolog.txt', 'BEFORE INNER LOOP BREAK', pCube, pSourceCustomer,pTargetCustomer,NumberToString(i2),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); If( pSourceCustomer @= '' % pTargetCustomer @= ''); Break; EndIf; ### Log Info of the inner loop parameters after the loop breaks## AsciiOutput( 'Loop Log Prolog.txt', 'AFTER INNER LOOP BREAK', pCube, pSourceCustomer,pTargetCustomer,NumberToString(i2),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); ## INNERMOST LOOP#### ### Determine version dimension Substitution ### i3 =1; AsciiOutput( 'Loop Log Prolog.txt', 'BEGIN INNERMOST LOOP', pCube,NumberToString(i3),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); while(i3<=10); pDim1 = 'p_Parameters_Version'; Param2 = Dimnm(pDim1,i3); pSourceVersion = CellGetS('Version Control Cube',Param2,'Source Version'); pTargetVersion = CellGetS('Version Control Cube',Param2,'Target Version'); ### Break the loop if any of the source or target version not found ### ### Log Info of the innermost loop parameters before the loop breaks## AsciiOutput( 'Loop Log Prolog.txt', 'BEFORE INNERMOST LOOP BREAK', pCube, pSourceCustomer,pTargetCustomer,pSourceVersion, pTargetVersion,NumberToString(i3),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); If( pSourceVersion @= '' % pTargetVersion @='' ); Break; EndIf; ### Log Info of the innermost loop parameters after the loop breaks## AsciiOutput( 'Loop Log Prolog.txt', 'AFTER INNERMOST LOOP BREAK', pCube, pSourceCustomer,pTargetCustomer,pSourceVersion, pTargetVersion,NumberToString(i3),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); ### Initialise Debug ### ### Set debug file name sDebugFile = cDebugFile | 'Prolog.debug'; If( pDebug >= 1 ); # Log start time AsciiOutput( sDebugFile, 'Process Started: ' | TimSt( Now, '\d-\m-\Y \h:\i:\s' ) ); # Log parameters AsciiOutput( sDebugFile, 'Parameters: pCube : ' | pCube ); AsciiOutput( sDebugFile, ' pViewSource : ' | pViewSource ); AsciiOutput( sDebugFile, ' pViewTarget : ' | pViewTarget ); AsciiOutput( sDebugFile, ' pDimension : ' | pDimension ); AsciiOutput( sDebugFile, ' pDimension1 : ' | pDimension1 ); AsciiOutput( sDebugFile, ' pSourceCustomer : ' | pSourceCustomer ); AsciiOutput( sDebugFile, ' pTargetCustomer : ' | pTargetCustomer ); AsciiOutput( sDebugFile, ' pSourceVersion : ' | pSourceVersion ); AsciiOutput( sDebugFile, ' pTargetVersion : ' | pTargetVersion ); AsciiOutput( sDebugFile, ' pSkipRules : ' | NumberToString( pSkipRules ) ); AsciiOutput( sDebugFile, ' pZeroTarget : ' | NumberToString( pZeroTarget ) ); AsciiOutput( sDebugFile, ' pZeroSource : ' | NumberToString( pZeroSource ) ); AsciiOutput( sDebugFile, ' Temp View Name : ' | cDefaultView ); EndIf; ### Validate Parameters ### nErrors = 0; # If a valid cube has not been specified then terminate process If( CubeExists( pCube ) = 0 ); nErrors = 1; sMessage = 'Invalid source cube specified: ' | pCube; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; ## Validate the View parameter If( TRIM(pViewSource) @<> '' & ( TRIM(pViewSource) @= TRIM(pViewTarget))); nErrors = 1; sMessage = 'Source and Target Views can not be the same: ' | pViewSource | ' ' | pViewTarget ; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; ## Validate the View parameter If( TRIM(pViewSource) @= '' ); If( pDebug >= 1 ); sMessage = 'Using default source view: ' | cDefaultView | 'S'; AsciiOutput( sDebugFile, sMessage ); EndIf; cViewSource = cDefaultView | 'S' ; Else ; If( pDebug >= 1 ); sMessage = 'Using source view: ' | pViewSource; AsciiOutput( sDebugFile, sMessage ); EndIf; cViewSource = pViewSource ; EndIf; ## Validate the View parameter If( TRIM(pViewTarget) @= '' ); If( pDebug >= 1 ); sMessage = 'Using default target view: ' | cDefaultView| 'T' ; AsciiOutput( sDebugFile, sMessage ); EndIf; cViewTarget = cDefaultView | 'T' ; Else ; If( pDebug >= 1 ); sMessage = 'Using target view: ' | pViewSource | 'T' ; AsciiOutput( sDebugFile, sMessage ); EndIf; cViewTarget = pViewTarget ; EndIf; # If a valid source dimenion has not been specified then terminate process If( DimensionExists( pDimension ) = 0 ); nErrors = 1; sMessage = 'Invalid dimension specified: ' | pDimension; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; # If a valid source dimenion has not been specified then terminate process If( DimensionExists( pDimension1 ) = 0 ); nErrors = 1; sMessage = 'Invalid dimension specified: ' | pDimension; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; # If a valid source dimenion element has not been specified then terminate process If( DimIx( pDimension, pSourceCustomer ) = 0 ); nErrors = 1; sMessage = 'Invalid source element specified: ' | pSourceCustomer; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; # If a valid source dimenion element has not been specified then terminate process If( DimIx( pDimension1, pSourceVersion ) = 0 ); nErrors = 1; sMessage = 'Invalid source element specified: ' | pSourceVersion; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; # If a valid target dimenion element has not been specified then terminate process If( DimIx( pDimension, pTargetCustomer ) = 0 ); nErrors = 1; sMessage = 'Invalid target element specified: ' | pTargetCustomer; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; # If a valid target dimenion element has not been specified then terminate process If( DimIx( pDimension1, pTargetVersion ) = 0 ); nErrors = 1; sMessage = 'Invalid target element specified: ' | pTargetVersion; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; ### Determine number of dims in source cube & check that specified dimension exists in cube ### nDimensionCount = 0; sDimension = TabDim( pCube, nDimensionCount + 1 ); nDimensionIndex = 0; While( sDimension @<> '' ); nDimensionCount = nDimensionCount + 1; If( sDimension @= pDimension ); nDimensionIndex = nDimensionCount; EndIf; sDimension = TabDim( pCube, nDimensionCount + 1 ); End; ### Log Info of the Dimension Count and Dimension Index of Customer Dimension## AsciiOutput( 'Loop Log Prolog.txt', 'Customer Dimension Index and Count', pCube,pDimension,NumberToString(nDimensionIndex),NumberToString(nDimensionCount),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); # If specified dim does not exist in cube then terminate process If( nDimensionIndex = 0 ); nErrors = 1; sMessage = 'Specified dimension: ' | pDimension | ' is not a component of the cube: ' | pCube; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; ### Determine number of dims in source cube & check that specified dimension exists in cube ### nDimensionCount1 = 0; sDimension1 = TabDim( pCube, nDimensionCount1 + 1 ); nDimensionIndex1 = 0; While( sDimension1 @<> '' ); nDimensionCount1 = nDimensionCount1 + 1; If( sDimension1 @= pDimension1 ); nDimensionIndex1 = nDimensionCount1; EndIf; sDimension1 = TabDim( pCube, nDimensionCount1 + 1 ); End; ### Log Info of the Dimension Count and Dimension Index of Version Dimension## AsciiOutput( 'Loop Log Prolog.txt', 'Version Dimension Index and Count', pCube,pDimension1,NumberToString(nDimensionIndex1),NumberToString(nDimensionCount1),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); # If specified dim does not exist in cube then terminate process If( nDimensionIndex1 = 0 ); nErrors = 1; sMessage = 'Specified dimension: ' | pDimension1 | ' is not a component of the cube: ' | pCube; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; # If dimension count exceeds the current maximum then terminate process If( nDimensionCount > 27 ); nErrors = 1; sMessage = 'Cube has too many dimensions: ' | pCube | '. Max 27 dims catered for, TI must be altered to accomodate.'; If( pDebug >= 1 ); AsciiOutput( sDebugFile, sMessage ); EndIf; DataSourceType = 'NULL'; ItemReject( sMessage ); EndIf; ### Debug ### If( pDebug >= 1 ); AsciiOutput( sDebugFile, 'Dimension "' | pDimension | '" index: ' | NumberToString( nDimensionIndex ) ); AsciiOutput( sDebugFile, 'Number of dimensions in ' | pCube | ' cube: ' | NumberToString( nDimensionCount ) ); AsciiOutput( sDebugFile, 'Source element: ' | pSourceCustomer ); AsciiOutput( sDebugFile, 'Target element: ' | pTargetCustomer ); EndIf; If( pDebug >= 1 ); AsciiOutput( sDebugFile, 'Dimension "' | pDimension1 | '" index: ' | NumberToString( nDimensionIndex1 ) ); AsciiOutput( sDebugFile, 'Number of dimensions in ' | pCube | ' cube: ' | NumberToString( nDimensionCount1 ) ); AsciiOutput( sDebugFile, 'Source element: ' | pSourceVersion ); AsciiOutput( sDebugFile, 'Target element: ' | pTargetVersion ); EndIf; ### Determine dimensions in source cube ### sDim1 = TabDim( pCube, 1 ); sDim2 = TabDim( pCube, 2 ); sDim3 = TabDim( pCube, 3 ); sDim4 = TabDim( pCube, 4 ); sDim5 = TabDim( pCube, 5 ); sDim6 = TabDim( pCube, 6 ); sDim7 = TabDim( pCube, 7 ); sDim8 = TabDim( pCube, 8 ); sDim9 = TabDim( pCube, 9 ); sDim10 = TabDim( pCube, 10 ); sDim11 = TabDim( pCube, 11 ); sDim12 = TabDim( pCube, 12 ); sDim13 = TabDim( pCube, 13 ); sDim14 = TabDim( pCube, 14 ); sDim15 = TabDim( pCube, 15 ); sDim16 = TabDim( pCube, 16 ); sDim17 = TabDim( pCube, 17 ); sDim18 = TabDim( pCube, 18 ); sDim19 = TabDim( pCube, 19 ); sDim20 = TabDim( pCube, 20 ); sDim21 = TabDim( pCube, 21 ); sDim22 = TabDim( pCube, 22 ); sDim23 = TabDim( pCube, 23 ); sDim24 = TabDim( pCube, 24 ); sDim25 = TabDim( pCube, 25 ); sDim26 = TabDim( pCube, 26 ); sDim27 = TabDim( pCube, 27 ); If( pDebug <= 1 ); ### Zero Out target version ### If( pZeroTarget = 1 ); ### Create Target View and assign subsets to Target version ### SubsetElementInsert( pDimension, cTempSubTo, pTargetCustomer, i2 ); ViewSubsetAssign( pCube, cTempViewTo, pDimension, cTempSubTo ); ### Log Info of the Customer Dimension Target View and Subset## AsciiOutput( 'Loop Log Prolog.txt', 'Customer Dimension Target View and Subset Names ', pCube,cTempViewTo, pDimension, cTempSubTo,pTargetCustomer,NumberToString(i2),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); SubsetElementInsert( pDimension1, cTempSubTo, pTargetVersion, i3 ); ViewSubsetAssign( pCube, cTempViewTo, pDimension1, cTempSubTo ); ### Log Info of the Version Dimension Target View and Subset## AsciiOutput( 'Loop Log Prolog.txt', 'Version Dimension Target View and Subset Names', pCube,cTempViewTo, pDimension1, cTempSubTo,pTargetVersion,NumberToString(i3),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); ViewExtractSkipCalcsSet( pCube, cTempViewTo, 1 ); ViewExtractSkipRuleValuesSet( pCube, cTempViewTo, 0 ); ViewExtractSkipZeroesSet( pCube, cTempViewTo, 1 ); ViewZeroOut( pCube, cTempViewTo ); EndIf; EndIf; ### Create Source View and assign subsets to source version ### SubsetElementInsert( pDimension, cTempSubFrom, pSourceCustomer, i2 ); ViewSubsetAssign( pCube, cTempViewFrom, pDimension, cTempSubFrom ); ### Log Info of the Customer Dimension Source View and Subset## AsciiOutput( 'Loop Log Prolog.txt', 'Customer Dimension Source View and Subset Names ', pCube,cTempViewFrom, pDimension, cTempSubFrom,pSourceCustomer,NumberToString(i2),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); SubsetElementInsert( pDimension1, cTempSubFrom, pSourceVersion, i3 ); ViewSubsetAssign( pCube, cTempViewFrom, pDimension1, cTempSubFrom ); ### Log Info of the Version Dimension Source View and Subset## AsciiOutput( 'Loop Log Prolog.txt', 'Version Dimension Source View and Subset Names', pCube,cTempViewFrom, pDimension1, cTempSubFrom,pSourceVersion,NumberToString(i3),TimSt( Now, '\d-\m-\Y \h:\i:\s' )); # If skip rules not 0 or 1 then set to 1 (skip) If( pSkipRules <> 0 & pSkipRules <> 1 ); pSkipRules = 1; EndIf; ViewExtractSkipCalcsSet( pCube, cTempViewFrom, 1 ); ViewExtractSkipRuleValuesSet( pCube, cTempViewFrom, pSkipRules ); ViewExtractSkipZeroesSet( pCube, cTempViewFrom,1 ); ### Assign Datasource ### DataSourceType = 'VIEW'; DatasourceNameForServer = pCube; DatasourceNameForClient = pCube; DatasourceCubeView = cTempViewFrom; i3 =i3+1; AsciiOutput( 'Loop Log Prolog.txt', ' INNERMOST LOOP INCREMENT', pCube, NumberToString(i3), TimSt( Now, '\d-\m-\Y \h:\i:\s' )); end; AsciiOutput( 'Loop Log Prolog.txt', ' INNERMOST LOOP END', pCube, NumberToString(i3), TimSt( Now, '\d-\m-\Y \h:\i:\s' )); ## END OF INNERMOST LOOP#### i2 =i2+1; AsciiOutput( 'Loop Log Prolog.txt', ' INNER LOOP INCREMENT', pCube, NumberToString(i2), TimSt( Now, '\d-\m-\Y \h:\i:\s' )); end; AsciiOutput( 'Loop Log Prolog.txt', ' INNER LOOP END', pCube, NumberToString(i2), TimSt( Now, '\d-\m-\Y \h:\i:\s' )); ## END OF INNER LOOP#### ### End Prolog ###