The Macro page is used to specify the macro, which should be used to create a dictionary, as well as a unit, which contains this macro.
To set a macro:
Select a unit in the Unit drop-down list with repository objects.
Select a macro contained in the selected unit in the Macro drop-down list.
After executing the operations, the specified macro is used to create a dictionary.
A custom macro should include a procedure with one of the following signatures:
Sub <Name>(UserDim: IUserDimension; Builder: IDimBuilder);
Sub <Name>(UserDim: IUserDimension; Builder: IDimBuilder; Param: IMetabaseObjectParamValues);
The first parameter of the UserDim procedure passes the structure of calculated dictionary, for which the element tree should be created. Using this structure, you can get the list of attributes by which you need to define element values.
The second parameter of the Builder procedure passes the object that is used to prepare a dictionary to data loading.
The third parameter of the Params procedure contains a collection of input parameter values if the dictionary is a parametric one. Values of parameters can be used to set up constraints in applied algorithm of filling a dictionary with data, or passed to the sources from which data is loaded.
General algorithm of data filling procedure should be as follows:
Using the IDimBuilder.CreateRootBlockLoader method available in the Builder parameter, loaders of the topmost root level elements are created for all dictionary blocks.
If one needs to create element hierarchy in a block, use the IDimBuilder.CreateBlockLoader method, a loader of lower level elements is also created for this block.
The newly created loader is a table. Table rows contain elements, and table columns contain element attributes. Using the IDimBlockLoader.AddRow method, one can create the necessary number of element rows. Using the IDimBlockLoader.Value property once can set values of element attributes. Loader table columns are arranged in the same order as dictionary attributes.
Create a hierarchy in calculated dictionary
To create a hierarchy in the custom macro using the IDimBuilder.CreateBlockLoader method, one should create a lower level element loader for the required block. The number of available columns in this loader is always one greater than the number of attributes created in the calculated dictionary. If you set a value by the last additional column, this value is not shown at the hierarchy creation. It will be regarded as a parent element identifier.
The LoadElements procedure can be used to create a multilevel calculated dictionary:
Sub LoadElements(UserDim: IUserDimension; Builder: IDimBuilder);
Var
DimBlock: IUserDimBlock;
BlockRoot, Block: IDimBlockLoader;
m, n, i, Element: integer;
Begin
{
Here can be connection code
to required data sources or any other code,
used for getting attribute values for elements
}
//Get first dictionary block parameters
DimBlock := UserDim.Blocks.Item(0);
//Create a root element loader
BlockRoot := Builder.CreateRootBlockLoader(DimBlock.Key);
//Create a lower level element loader
Block := Builder.CreateBlockLoader(DimBlock.Key, DimBlock.Key);
//Create root elements
//m - number of dictionary attributes
//n - number of created elements
m := 3;
n := 5;
For i := 1 To n Do
Element := BlockRoot.AddRow;
BlockRoot.Value(Element, 0) := //Value
BlockRoot.Value(Element, 1) := //Value
//...
BlockRoot.Value(Element, m - 1) := //Value
End For;
//Create a child element hierarchy
//m - number of dictionary attributes
//n - number of created elements
//The column with the index m will contain parent element identifiers
For i := 1 To n Do
Element := Block.AddRow;
Block.Value(Element, 0) := //Value
Block.Value(Element, 1) := //Value
//...
Block.Value(Element, m - 1) := //Value of the last attribute created in dictionary
Block.Value(Element, m) := //Value that will be considered as
//parent element identifier
End For;
End Sub LoadElements;
The LoadElementsWithParams procedure can be used to create a calculated dictionary, number of elements in which depends on values of input parameters (the dictionary structure is supposed to have two integer parameters):
Sub LoadElementsWithParams(UserDim: IUserDimension; Builder: IDimBuilder; Params: IMetabaseObjectParamValues);
Var
DimBlock: IUserDimBlock;
BlockRoot, Block: IDimBlockLoader;
m, i, Element, Start, End_: integer;
Begin
{
Here can be connection code
to required data sources or any other code
used for getting attribute values for elements
}
//Get parameter values
Start := Params.Item(0).Value As Integer;
End_ := Params.Item(1).Value As Integer;
//Get first dictionary block parameters
DimBlock := UserDim.Blocks.Item(0);
//Create a root element loader
BlockRoot := Builder.CreateRootBlockLoader(DimBlock.Key);
//Create a lower level element loader
Block := Builder.CreateBlockLoader(DimBlock.Key, DimBlock.Key);
//Create root elements
//m - number of dictionary attributes
m := 3;
For i := Start To End_ Do
Element := BlockRoot.AddRow;
BlockRoot.Value(Element, 0) := i.ToString; //Value
BlockRoot.Value(Element, 1) := i; //Value
//...
BlockRoot.Value(Element, m - 1) := i; //Value
End For;
End Sub LoadElementsWithParams;
See also: