CreateParser: IMDCalculationExpressionParser;
The CreateParser method creates an object that parses expression of the formula specified as a character string.
Executing the example requires that the repository contains multidimensional calculation on DB server with the MDCalc_1 identifier.
Sub Main;
Var
MB: IMetabase;
MDInst: IMDCalculationInstance;
Source: IMDCalculationSourceInstance;
Parser: IMDCalculationExpressionParser;
SourceCoord, DestCoord: IMatrixCoord;
SourceKey, DestKey: IMDCalculationFormulaElementKey;
Dest: IMDCalculationDestinationInstance;
Formulas: IMDCalculationFormulas;
Formula: IMDCalculationFormula;
i: Integer;
Begin
MB := MetabaseClass.Active;
MDInst := MB.ItemById("MDCalc_1").Open(Null) As IMDCalculationInstance;
Source := MDInst.Sources.Item(0);
Parser := MDInst.CreateParser;
SourceCoord := Source.NewCoord;
For i := 0 To SourceCoord.Count - 1 Do
SourceCoord.Item(i) := 0;
End For;
SourceKey := Source.CoordToKey(SourceCoord);
Parser.TermKey("Term") := SourceKey;
Parser.Text := "Shift(Term, Year, 1)*3.14";
Parser.Parse;
Dest := MDInst.Destination;
DestCoord := Dest.NewCoord;
For i := 0 To SourceCoord.Count - 1 Do
DestCoord.Item(i) := 0;
End For;
DestKey := Dest.CoordToKey(DestCoord);
Formulas := MDInst.CreateFormulas;
Formula := Formulas.Add;
Parser.Expression.CopyTo(Formula.Expression);
MDInst.WriteFormulas(DestKey, Formulas);
End Sub Main;
After executing the example a new formula is created for the specified data consumer element. The formula is obtained through text string parse. The specified data source element is substituted in the expression instead of a term.
See also: