Consider the example of creating a calculated cube using the Fore and Fore.NET language. To create a cube, the following objects must be in the repository:
A cube with the CUBE_SOURCE identifier, which is used as a data source for created calculated cube.
This cube must contain a calendar dimension with the CALENDAR identifier in its structure.
The following example creates a new object that is Calculated Cube in the repository root and sets up its parameters:
The data source is set.
All dimensions from the source are moved to the calculated cube structure. The calendar dimension is fixed.
To execute the example, add links to the Cubes, Dimensions and Metabase system assemblies. Write the corresponding Imports strings for the Fore.NET example.
Sub CreateCalculatedCube;
Var
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
CalcCube: ICalculatedCube;
CubeModel: ICubeModel;
CubeDest: ICubeModelDestination;
CalcSource: ICalculatedCubeSource;
SourceDim, CalcDim: ICalculatedCubeDimension;
Begin
MB := MetabaseClass.Active;
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_CALCCUBE;
CrInfo.Id := "New_Calc_Cube";
CrInfo.Name := "New calculated cube";
CrInfo.Parent := MB.Root;
MObj := MB.CreateObject(CrInfo).Edit;
CalcCube := MObj As ICalculatedCube;
//Add the source, which values are used to execute calculations by formulas
CubeModel := Mb.ItemById("CUBE_SOURCE").Bind As ICubeModel;
CubeDest := CubeModel.Destinations.DefaultDestination;
CalcSource := CalcCube.Sources.Add(CubeDest);
//Add source cube dimensions to calculated cube structure
For Each SourceDim In CalcSource.Dimensions Do
CalcDim := CalcCube.Dimensions.Add(SourceDim.Dimension);
If (SourceDim.Dimension As IMetabaseObject).Id = "CALENDAR" Then
SourceDim.Fixed := True;
CalcDim.Fixed := True;
End If;
End For;
MObj.Save;
End Sub CreateCalculatedCube;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Metabase;
Sub CreateCalculatedCube(MB: IMetabase);
Var
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
CalcCube: ICalculatedCube;
CubeModel: ICubeModel;
CubeDest: ICubeModelDestination;
CalcSource: ICalculatedCubeSource;
SourceDim, CalcDim: ICalculatedCubeDimension;
Begin
CrInfo := MB.CreateCreateInfo();
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_CALCCUBE As Integer;
CrInfo.Id := "New_Calc_Cube";
CrInfo.Name := "New calculated cube";
CrInfo.Parent := MB.Root;
MObj := MB.CreateObject(CrInfo).Edit();
CalcCube := MObj As ICalculatedCube;
//Add the source, which values are used to execute calculations by formulas
CubeModel := Mb.ItemById["CUBE_SOURCE"].Bind() As ICubeModel;
CubeDest := CubeModel.Destinations.DefaultDestination;
CalcSource := CalcCube.Sources.Add(CubeDest);
//Add source cube dimensions to calculated cube structure
For Each SourceDim In CalcSource.Dimensions Do
CalcDim := CalcCube.Dimensions.Add(SourceDim.Dimension);
If (SourceDim.Dimension As IMetabaseObject).Id = "CALENDAR" Then
SourceDim.Fixed := True;
CalcDim.Fixed := True;
End If;
End For;
MObj.Save();
End Sub;
See also: