IMDCalculationExpressionParser.Parse

Syntax

Parse;

Description

The Parse method parses a formula specified as the Text text string. Parsing results in the Expression formula expression.

Example

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. Instead of a term the specified data source element is substituted into the expression.

See also:

IMDCalculationExpressionParser