GetItemEx(StubKey: Integer; DimKey: Integer): Integer;
StubKey. Data source key.
DimKey. Dimension key.
The GetItemEx method returns element index by the specified data source and dimension
The method can be called within the model calculation context with multidimensional iterator. A data source dimension that is missing in iterator dimensions must be added into dimension links of this iterator.
Executing the example requires that the repository contains a modeling container with the MS_P identifier containing a modeling problem with the PROBLEM_GETITEMEX_ identifier. This problem must calculate a metamodel containing only multidimensional iterator. A data source for the modeling container is a time series database with the TSDB_PARAM identifier containing the Factors dimension based on the MDM_DICT_INDICATORS dictionary. This dimension must be added into dimension links of multidimensional iterator and must be missing in its dimensions. The MDM_DICT_INDICATORS dictionary is contained in an MDM repository with the MDM identifier.
The repository must also contains a module with the IMSFORMULATRANSFORMCOORD_GETITEMEX identifier containing the GetItemEx function described in this example.
Add links to the Cubes, Dimensions, Metabase, Ms, Transform system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsKey: Integer;
Ms: IMsModelSpace;
DS: IRubricator;
Problem: IMsProblem;
MM: IMsMetaModel;
Iterator: IMsCalculationChainMultiDimIterator;
model: IMsModel;
Trans: IMsFormulaTransform;
TransVar: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
Determ: IMsDeterministicTransform;
Expr: IExpression;
Calculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modelling container key
MsKey := mb.GetObjectKeyById("MS_P");
// Get modeling container
Ms := mb.Item(MsKey).Bind As IMsModelSpace;
// Get time series database
// which is a data source for modeling container
DS := Ms.DefaultObject.Bind As IRubricator;
// Get modeling problem
Problem := mb.ItemByIdNamespace("PROBLEM_GETITEMEX_", MsKey).Bind As IMsProblem;
// Get metamodel calculated by the problem
MM := Problem.EditMetaModel;
// Get multidimensional iterator
Iterator := MM.CalculationChain.Item(0) As IMsCalculationChainMultiDimIterator;
// Create a model inside multidimensional iterator
Iterator.Contents.Clear;
model := Iterator.Contents.AddExclusiveModel.Model;
// Set up model
Trans := model.Transform;
// Add output variable
TransVar := Trans.Outputs.Add(DS As IVariableStub);
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(1);
Selector := Trans.CreateSelector;
Selector.Slice := Slice;
// Set up model calculation method: determinate equation
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.Deterministic;
Determ := Formula.Method As IMsDeterministicTransform;
// Determine expression to calculate a model
Expr := Determ.Expression;
Expr.AsString := "IMSFORMULATRANSFORMCOORD_GETITEMEX.GetItemEx";
If Expr.ErrorInfo <> Null Then
debug.WriteLine(Expr.ErrorInfo.ErrorMessage);
Return;
End If;
// Save changes in the model
model.MetabaseObject.Save;
// Save changes of the metamodel
(MM As IMetabaseObject).Save;
// Create problem calculation parameters
CalcSettings := Problem.CreateCalculationSettings;
// Calculation problem
Calculation := Problem.Calculate(CalcSettings);
Calculation.Run;
End Sub UserProc;
// Function that is calculated by model within multidimensional iterator
Public Function GetItemEx: variant;
Var
mb: IMetabase;
i, j: integer;
StubKey, DimKey: Integer;
context: ITsCalculationContext;
Coord: IMsFormulaTransformCoord;
t: ITimeSeries;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get time series database key
StubKey := mb.GetObjectKeyById("TSDB_PARAM");
// Get dimension key
DimKey := mb.GetObjectKeyByIdNamespace("MDM_DICT_INDICATORS", mb.GetObjectKeyById("MDM"));
// Get calculation context
context := TsCalculation.Current;
// Create output data series
t := context.CreateTimeSeries(DimCalendarLevel.Year) As ITimeSeries;
// Get current coordinate
coord := t.Coord;
// If coordinate by the Factors dimension is zero, the values 22 are loaded,
// if coordinate is greater than 0, the values 11 are loaded
If Coord.GetItemEx(StubKey, DimKey) > 0 Then
i := 11;
Else
i := 22;
End If;
// Populate output series with data
For j := t.StartIndex To t.EndIndex Do
t.Item(j) := i;
End For;
// Return function execution result
Return t;
End Function GetItemEx;
After executing the example a model that calculates the custom function is added to the multidimensional iterator.
See also: