UserData: ITsUserData;
The UserData property returns user data related with calculation algorithm.
Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier. The calculation algorithm should contain two calculation blocks and one control block. It is also assumed that there is an empty regular report with the REPORT identifier.
Add links to the Algo, Dimensions, Matrix, Metabase, Report and Transform system assemblies. Add links to the assemblies required for working with calculation algorithms.
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObjectDescriptor;
Algo: ICalcObject;
CalcList: ICalcObjectsList;
CalcAlgo: ICalcAlgorithm;
CalcDebug: IAlgorithmCalculationDebug;
Report, Report1: IPrxReport;
Result: IAlgorithmCalculationResult;
Load: IAlgorithmTimeResults;
TimeResult: IAlgorithmTimeResult;
Matrix, ValidationMatrix: IMatrixDataSource;
DimSS: IDimSelectionSet;
Matr, ValidationMatr: IMatrix;
Coord: IMatrixCoord;
pUserData: ITsUserData;
currentIteration, maxIterations, i: Integer;
Sec: Double;
Begin
MB := MetabaseClass.Active;
// Get calculation algorithm
MObj := MB.ItemById("ALGORITHM");
// Regular report for subtotals
Report := MB.ItemByID("REPORT").Edit As IPrxReport;
Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
CalcAlgo := Algo As ICalcAlgorithm;
// Create a list of algorithm objects
CalcList := CalcAlgo.Items.Clone;
// Start algorithm debugging
CalcDebug := CalcAlgo.Debug(CalcList);
// Go to the next
CalcDebug.NextStep;
// Write result to regular report
Report1 := CalcDebug.PrxReport(CalcAlgo, CalcAlgo.Items.Item(0));
Report.CopyFrom(Report1);
(Report As IMetabaseObject).Save;
// Go to the specified calculation algorithm object
// The given example displays selecting a calculation object in the list of debugging objects (the list decreases on calculation)
CalcDebug.StepToObject(CalcDebug.Objects.Item(0));
// Get user data, which is used to start cyclic calculation
pUserData := CalcDebug.UserData;
// Set the maximum number of iterations and the current iteration
pUserData.Data("MAX_ITERATION") := 3;
pUserData.Data("CURRENT_ITERATION") := 0;
// Calculate the selected calculation object cyclically N times
If pUserData.Contains("CURRENT_ITERATION") Then
currentIteration := pUserData.Data("CURRENT_ITERATION") As Integer;
maxIterations := pUserData.Data("MAX_ITERATION") As Integer;
While currentIteration < maxIterations Do
//View intermediate data
Matrix := CalcDebug.Matrix((CalcAlgo.Items.Item(1) As ICalcBlock).StubOut);
DimSS := Matrix.CreateDimSelectionSet;
Matr := Matrix.Execute(DimSS);
Coord := Matr.CreateCoord;
For i := 0 To Matr.DimensionCount - 1 Do
Coord.Item(i) := 0;
End For;
Debug.WriteLine(Matr.Item(Coord));
// Calculate calculation object again
CalcDebug.RecalcPrev;
currentIteration := currentIteration + 1;
End While;
End If;
// Go to the next calculation object
CalcDebug.NextStep;
// View intermediate data
ValidationMatrix := CalcDebug.ValidationMatrix((CalcAlgo.Items.Item(2) As ICalcValidationBlock).StubOut);
DimSS := ValidationMatrix.CreateDimSelectionSet;
For i := 0 To DimSS.Count - 1 Do
DimSS.Item(i).SelectAll;
End For;
ValidationMatr := ValidationMatrix.Execute(DimSS);
Coord := ValidationMatr.CreateCoord;
For i := 0 To ValidationMatr.DimensionCount - 1 Do
Coord.Item(i) := 0;
End For;
Debug.WriteLine(ValidationMatr.Item(Coord));
// Proceed to saving data to database.
CalcDebug.StepToSaveData;
// Check if calculation is finished and display information about data loading
If CalcDebug.IsFinished = True Then
Debug.WriteLine("Calculation is finished:");
// data about calculation results
Result := CalcDebug.Result;
Load := Result.Load;
Debug.WriteLine("Result of loading data sources:");
TimeResult := Load.Item(0);
Debug.WriteLine(" Name: " + TimeResult.Name);
Debug.WriteLine(" Identifier: " + TimeResult.Id);
Sec := TimeResult.ExecuteMilisecods / 1000;
Debug.WriteLine(" Loading time: " + Sec.ToString + " sec.");
Debug.WriteLine("");
End If;
End Sub UserProc;
After executing the example the algorithm calculation, in which the calculation blocks and the control block are to be executed, will be debugged. The result of the first calculation block will be saved to the regular report. The second block will be calculated cyclically four times. The calculation result will be obtained as a matrix, the first matrix value will be displayed in the development environment console. A matrix of intermediate results will be obtained for the control block, and one value will be displayed in the development environment console.
See also: