Creating a Modeling Variable: Filling the Data Manually

Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier.

Sub Main;

Var

MB: IMetabase;

CrInfo: IMetabaseObjectCreateInfo;

MObj: IMetabaseObject;

MsVar: IMsVariable;

Sampling: IMsVariableSampling;

//Cube with data of modeling variable

Cube: IAutoCube;

//For aggregation setup by the calendar

AggrManager: MatrixAggregatorManager;

IAggrManager: IMatrixAggregatorManager;

AggrModel: IMatrixAggregatorModel;

BasicAggregator: IBasicMatrixAggregator;

LevelBasicAggregator: IBasicMatrixLevelAggregator;

Dim: IAutoCubeDimension;

DimModel: IDimensionModel;

DimLvl: IDimLevels;

//For filling with data

CubeInst: ICubeInstance;

Des: ICubeInstanceDestination;

DimSS: IDimSelectionSet;

DimS: IDimSelection;

Elem: IDimElementArray;

Mat: IMatrix;

Coord: IMatrixCoord;

Sto: ICubeInstanceStorage;

i: Integer;

Begin

MB := MetabaseClass.Active;

CrInfo := MB.CreateCreateInfo;

CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_MSVARIABLE;

CrInfo.Id := "Var_1";

CrInfo.Name := Variable #1;

CrInfo.Parent := MB.ItemById("Kont_Model");

MObj := MB.CreateObject(CrInfo).Edit;

MsVar := MObj As IMsVariable;

//Method of filling with data

MsVar.DataFillType := MsVariableDataFillType.Manual;

Sampling := MsVar.Sampling;

//Calculation step for the variable: Years and half-years

Sampling.Level(DimCalendarLevel.Year) := True;

Sampling.Level(DimCalendarLevel.HalfYear) := True;

Cube := MsVar.Cube;

//Parameters of aggregation by calendar levels

AggrManager := New MatrixAggregatorManager.Create;

IAggrManager := AggrManager As IMatrixAggregatorManager;

AggrModel := IAggrManager.CreateAggregator("BasicMatrixAggregator");

Dim := Cube.Dimensions.Calendar;

DimModel := Dim.Dimension;

DimLvl := DimModel.Levels;

//Aggregation for calendar dimension

AggrModel.Dimension := DimModel;

BasicAggregator := AggrModel As IBasicMatrixAggregator;

//The level for which aggregation is adjusted is Years level

LevelBasicAggregator := BasicAggregator.LevelAggregation(DimLvl.Item(0));

//Level, which values are used at aggregation is Half-years

LevelBasicAggregator.Include(DimLvl.Item(1)) := True;

//Aggregation method is Sum

LevelBasicAggregator.Operation := BasicAggregatorOperation.Sum;

Dim.Aggregator(Cube.Destinations.Item(0)) := AggrModel;

//Filling with data

CubeInst := (Cube As IMetabaseObject).Open(Null) As ICubeInstance;

Des := CubeInst.Destinations.DefaultDestination;

DimSS := Des.CreateDimSelectionSet;

//Select Half-years level

DimS := DimSS.Item(0);

Elem := DimS.Dimension.Levels.Item(1).Elements;

For Each i In Elem Do

DimS.SelectElement(i, False);

End For;

//Select fact

DimSS.Item(1).SelectAll;

//Data matrix

Mat := Des.Execute(DimSS);

Mat.ValueFlag := Mat.ValueFlag + 1;

Coord := Mat.CreateCoord;

Coord.Item(1) := 0;

//Filling the matrix with data

For Each i In Elem Do

Coord.Item(0) := i;

Mat.Item(Coord) := Math.RandBetween(0, 100);

End For;

Sto := Des.CreateStorage;

//Save data to the cube

Sto.SaveMatrix(Mat, Mat.ValueFlag);

MObj.Save;

End Sub Main;

After executing the example a modeling variable is created in the modeling container. The way of filling with data is Manually. Two levels are presented in the variable frequency. They are Years and Half-years. For the Years level of calendar the aggregation is set: Half-year level data is summed. After this the cube, on which variable is built, is obtained, and the cube data matrix is obtained. Elements located at the Half-years level are filled with random data.

See also:

Examples