Ms > Examples > Creating a Modeling Variable: Filling the Data from Source
Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier containing a cube with the CUBE_1 identifier. This cube is based on the CALEN_1 dictionary and any other dictionaries. The cube contains data by the Half-Years level.
Add links to the Cubes, Dimensions, Matrix, Metabase, Ms system assemblies.
Sub UserProc;
Var
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
MsVar: IMsVariable;
Sampling: IMsVariableSampling;
Cube: IAutoCube;
CubeSource: IAutoCubeSource;
//To set up aggregation by calendar
AggrManager: MatrixAggregatorManager;
IAggrManager: IMatrixAggregatorManager;
AggrModel: IMatrixAggregatorModel;
BasicAggregator: IBasicMatrixAggregator;
LevelBasicAggregator: IBasicMatrixLevelAggregator;
Dim: IAutoCubeDimension;
DimModel: IDimensionModel;
DimLvl: IDimLevels;
//To load data
CubeInst: ICubeInstance;
Dest: ICubeInstanceDestination;
DimSS: IDimSelectionSet;
DimS: IDimSelection;
Elem: IDimElementArray;
FixInfo: IAutoCubeSourceFixInfo;
DimFix: IAutoCubeSourceDimensionFix;
i: Integer;
Begin
MB := MetabaseClass.Active;
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_MSVARIABLE;
CrInfo.Id := "VAR_3";
CrInfo.Name := "Variable No. 3";
CrInfo.Parent := MB.ItemById("KONT_MODEL");
MObj := MB.CreateObject(CrInfo).Edit;
MsVar := MObj As IMsVariable;
//Data population method
MsVar.DataFillType := MsVariableDataFillType.DataSource;
Sampling := MsVar.Sampling;
//Calculation step for 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 by calendar dimension
AggrModel.Dimension := DimModel;
BasicAggregator := AggrModel As IBasicMatrixAggregator;
//Level, for which aggregation is set up - Years
LevelBasicAggregator := BasicAggregator.LevelAggregation(DimLvl.Item(0));
//Level, which values are used on aggregation - Half-years
LevelBasicAggregator.Include(DimLvl.Item(1)) := True;
//Aggregation method - Sum
LevelBasicAggregator.Operation := BasicAggregatorOperation.Sum;
Dim.Aggregator(Cube.Destinations.Item(0)) := AggrModel;
//Add a source cube to variable
CubeSource := Cube.Source;
CubeSource.Cube := (MB.ItemById("CUBE_1").Bind As ICubeModel).Destinations.DefaultDestination;
//Specify calendar;
CubeSource.Calendar := CubeSource.Cube.Dimensions.FindById("CALEN_1");
FixInfo := CubeSource.FixInfo;
//Fix dimensions
For Each DimFix In FixInfo Do
DimFix.Operation := BasicAggregatorOperation.Sum;
DimFix.Selection.SelectAll;
End For;
//Get variable cube instance
CubeInst := (Cube As IMetabaseObject).Open(Null) As ICubeInstance;
Dest := CubeInst.Destinations.DefaultDestination;
//Create SelectionSet for cube
DimSS := Dest.CreateDimSelectionSet;
//Select the whole level - Half-years
DimS := DimSS.Item(0);
Elem := DimS.Dimension.Levels.Item(1).Elements;
For Each i In Elem Do
DimS.SelectElement(i, False);
End For;
//Select all in fact dimension
DimSS.Item(1).SelectAll;
//Load data;
((Cube As IMetabaseObject).Open(Null) As IAutoCubeInstance).UpdateFromSource(DimSS);
MObj.Save;
End Sub UserProc;
After executing the example a modeling variable is created in the modeling container. The method of filling with data is From Source. 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 the variable is built, is obtained, and data from the source cube is loaded into it.
See also: