Creating a Standard Cube

Consider the example of creating a standard cube with the use of the Fore language. To create a cube, the repository should contain the following objects:

The below specified example creates a new object - Standard Cube - in the repository root folder and sets up its parameters:

To execute the examples, add links to the Cubes, Db, Dimensions, and Metabase system assemblies.

Example

Sub CreateStdCube;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    StdCube: IStandardCube;
    StdCubeDest: IStandardCubeDestination;
    StdDims: IStandardCubeDimensions;
    StdDatasets: IStandardCubeDatasets;
    FactDim, CountryDim, CalendarDim: IStandardCubeDimension;
    StdDataset: IStandardCubeDataset;
    FactDimInst: IDimInstance;
    KeyAttribute: IDimAttributeInstance;
    FactBindings: IStandardCubeFactBindings;
    DimBinding: IStandardCubeDimensionBinding;
    DimIndex: IDimIndex;
    Relation: IStandardCubeRelation;
    DataSet_ID: String = "STD_DATA";
Begin
    MB := MetabaseClass.Active;
    //Information for creating a new repository object
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDCUBE;
    CrInfo.Id := "New_Std_Cube";
    CrInfo.Name := "New standard cube";
    CrInfo.Parent := MB.Root;
    //Create a cube
    MObj := MB.CreateObject(CrInfo).Edit;
    StdCube := MObj As IStandardCube;
    //Set up cube parameters
    StdCubeDest := StdCube.Destinations.Item(0);
    StdDims := StdCubeDest.Dimensions;
    StdDatasets := StdCubeDest.Datasets;
    //Specify existing repository dictionary as a fact dimension
    FactDim := StdDims.Add(MB.ItemById("FACTS").Bind As IDimensionModel);
    StdCube.ExternalFactDimension := True;
    FactDim.FactDimension := True;
    //Add a data source
    StdDataset := StdDatasets.Add(MB.ItemById(DataSet_ID).Bind As IDatasetModel);
    //Link cube fact
    FactDimInst := FactDim.OpenDimension;
    KeyAttribute := FactDimInst.Attributes.FindById("KEY");
    FactBindings := FactDim.FactBindings(StdDataset);
    FactBindings.Binding(KeyAttribute.Value(0)).Formula.AsString := DataSet_ID + ".VALUE";
    //Add dimensions
    CountryDim := StdDims.Add(MB.ItemById("COUNTRY").Bind As IDimensionModel);
    CalendarDim := StdDims.Add(MB.ItemById("CALENDAR").Bind As IDimensionModel);
    //Link dimensions
    //"Countries"
    DimIndex := CountryDim.Dimension.Indexes.PrimaryIndex;
    DimBinding := CountryDim.Binding(StdDataset);
    DimBinding.Index := DimIndex;
    DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".COUNTRY_KEY";
    //"Calendar"
    DimIndex := CalendarDim.Dimension.Blocks.Item("YEARS").Indexes.FindById("INDEX_BLOCK");
    DimBinding := CalendarDim.Binding(StdDataset);
    DimBinding.Index := DimIndex;
    DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".V_DATE";
    //Create and set up relations
    Relation := StdCube.Relations.Add;
    Relation.Name := "Shift for point";
    Relation.Id := "BEFORE";
    Relation.Relation(CalendarDim).AsString := "T.PREV";
    //Specify formula for calculated fact
    StdCube.CalcBindings.Binding(KeyAttribute.Value(1)).Formula.AsString := "@[" + KeyAttribute.Value(0) + "]-BEFORE[@[" + KeyAttribute.Value(0) + "]]";
    MObj.Save;
End Sub CreateStdCube;

See also:

Examples