Setting Fixed Binding of Calendar Dimension

A time series database can be imported using fixed binding of calendar dimension.

Executing the example requires a time series database with the OBJ_RUBRICATOR identifier and the C:\Doc.xlsx file. Also, add links to the Cubes, Db, Dimensions, Dt, Metabase system assemblies. Fixed binding of the calendar is set by the following method:

Sub Main;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    Obj: IMetabaseObject;
    ObjDesc: IMetabaseObjectDescriptor;
    Binding: ICubeMetaLoaderBinding;
    Provider: IDatasetDataProvider;
    RubDesc: IMetabaseObjectDescriptor;
    ImportRequestDef: IImportRequestDefinition;
    ImportRequestProviderParams: IImportRequestProviderParams;
    ValueBinding: ICubeMetaLoaderBinding;
    Parser: ICubeMetaLoaderBindingParser;
    Excel: IDtExcelProvider;
Begin
    MB := MetabaseClass.Active;
   
// Data sources for import from Excel format
    Excel := New DtExcelProvider.Create;
    Excel.ImexMode := DtExcelImexMode.Import;
    Excel.File := 
"C:\Doc.xlsx";
    Excel.Query := 
"SELECT * FROM [Sheet1$]";
    Excel.HasHeader := 
True;
    Excel.CheckFieldName := 
True;
   
// Time series database
    RubDesc := Mb.ItemById("OBJ_RUBRICATOR");
    Provider := (Excel 
As IDatasetDataProvider);
   
// Create an import object
    CrInfo := Mb.CreateCreateInfo;
    CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_IMPORTREQUEST;
    CrInfo.Id := 
"OBJ_IMPORTREQUEST";
    CrInfo.Name := 
"Import object";
    CrInfo.Permanent := 
True;
    CrInfo.Parent := RubDesc.Bind;
    ObjDesc := Mb.CreateObject(CrInfo);
    Obj := ObjDesc.Edit;
   
// Set up source
    ImportRequestDef := Obj As IImportRequestDefinition;
    ImportRequestDef.SourceType := ImportRequestSourceType.Provider;
    ImportRequestDef.DestinationRubricator := RubDesc.Bind 
As IRubricator;
   
// Import parameters
    ImportRequestProviderParams := ImportRequestDef.ProviderParams;
    ImportRequestProviderParams.Provider := Provider;
    ImportRequestProviderParams.NewRevisionName := 
"Factors import";
    ImportRequestProviderParams.ImportObjectKey := Obj.Key;
    ImportRequestProviderParams.LoadType := CubeMetaLoaderLoadType.CreateAndUpdate;
    Binding := ImportRequestProviderParams.Bindings.Add;
    // Fixed binding of calendar dimension
    Binding.FieldType := CubeMetaLoaderFieldType.ConstValue;
    Binding.BindingType := CubeMetaLoaderBindingType.Calendar;
    Binding.FieldValue := DateTime.Today;
    Binding.CalendarOptions.Levels := DimCalendarLevelSet.Year;
    ValueBinding := ImportRequestProviderParams.Bindings.Add;
    ValueBinding.BindingType := CubeMetaLoaderBindingType.Value;
    ValueBinding.Field := "Value";
    ValueBinding.FieldType := CubeMetaLoaderFieldType.Name;
    Parser := ValueBinding.Parser;
    Parser.ParserType := CubeMetaLoaderParserType.FixedPosition;
    Parser.StringPositionStart := 0;
    Parser.StringPositionEnd := -1;
    Obj.Save;
End Sub Main;

After executing the example the object of the import from Excel file C:\Doc.xlsx will be created. In this object the fixed binding of the calendar dimension will be set up.

See also:

Examples