AdditionalHierarchy: IDimHierarchiesInstance;
The AdditionalHierarchy property returns an object for working with an alternative hierarchy.
Alternative hierarchy is a hierarchy of any other dictionary linked to the hierarchy of the main dictionary in order to match elements or a custom hierarchy created on dimensions editing or adding a new calculated element.
Executing the example requires that the repository contains table dictionaries with the DIC_RF_AH and FACTS_AH identifiers. The DIC_RF_AH dictionary is considered as the main one, and the FACTS_AH dictionary is considered as the dictionary for alternative hierarchy.
Add links to the Dimensions, Metabase system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
OriginalModelObj: IMetabaseObject;
OriginalModel, AlternateModel: IDimensionModel;
Hierarchies: IDimHierarchies;
Alt_Hierarchy: IDimHierarchy;
Origin_Attributes, Alt_Attributes: IDimAttributes;
Origin_Attr, Alt_Attr: IDimAttribute;
dimInstance: IDimInstance;
dimSel: IDimSelection;
i: Integer;
Begin
// Get repository
Mb := MetabaseClass.Active;
// Get table dictionary
OriginalModelObj := Mb.ItemById("DIC_RF_AH").Edit;
OriginalModel := OriginalModelObj As IDimensionModel;
// Get alternative hierarchy source
AlternateModel := Mb.ItemById("FACTS_AH").Bind As IDimensionModel;
Hierarchies := OriginalModel.Hierarchies;
// Determine index, containing keys of elements for alternative hierarchy
Hierarchies.OriginalIndex := OriginalModel.Indexes.PrimaryIndex;
// Add source alternative hierarchy
Alt_Hierarchy := Hierarchies.Add(AlternateModel);
// Determine index containing keys for comparing elements of main and alternative dictionary
Alt_Hierarchy.SourceIndex := AlternateModel.Indexes.PrimaryIndex;
Origin_Attributes := OriginalModel.Attributes;
Alt_Attributes := AlternateModel.Attributes;
// Link source dimension attributes with attributes from alternative hierarchy source by identifier
For i := 0 To Origin_Attributes.Count - 1 Do
Origin_Attr := Origin_Attributes.FindById("NAME");
Alt_Attr := Alt_Attributes.FindById("NAME");
Alt_Hierarchy.SourceAttribute(Origin_Attr) := Alt_Attr;
End For;
OriginalModelObj.Save;
// Replace main hierarchy with alternative one
dimInstance := OriginalModelObj.Open(Null) As IDimInstance;
dimSel := dimInstance.CreateSelection;
dimSel.InitAdditionalHierarchy(Alt_Hierarchy);
dimSel.Hierarchy := dimSel.AdditionalHierarchy;
// Save dictionary
OriginalModelObj.Save;
End Sub UserProc;
After executing the example an alternative hierarchy is added to the main dictionary.
See also: