Copying data between cubes with different dimensionality
The
OLAPCopyDataArea function can be used to copy data between cubes with different numbers of dimensions. For example, you can copy data from a 2D cube to a 3D cube or from a 3D cube to a 5D cube.
To copy data to a target cube that has more dimensions than the source cube, you must provide one coordinate for every extra dimension in the target cube. This coordinate must be in the correct position in the target element list. The correct position is given by the order of dimensions in the target dimension list.
The overload of OLAPCopyDataArea takes these parameters lists:
sourceDimensionssourceElementstargetDimensionstargetElements
You must also ensure that the source dimension list and target dimension list have the same number and order of dimensions. This requires you to specify an empty string in the appropriate position in the source dimension list.
The subsequent code example shows how to use this function:
#define EngineVersion 5.0
#define RuntimeVersion 5.0
void CopyDataAreaFrom2DCubeTo3DCube()
@Description: "Example of copy data area from 2D cube to 3D cube.";
@Category: "Test";
@Returns: "void";
{
/////////////////////////////////////////////////////////////////////////////////////////
// Mapping of sourceCube dimensions onto targetCube dimensions in this example
//
// SOURCE CUBE DIMENSIONS --> TARGET CUBE DIMENSIONS
// sourceCubeDimension1 --> targetCubeDimension1
// <empty> --> targetCubeDimension2
// sourceCubeDimension2 --> targetCubeDimension3
//
// SOURCE CUBE ELEMENTS --> TARGET CUBE ELEMENTS
// A21, A22 --> C21, C22
// <empty> --> D23
// B21, B22 --> E21, E22
//
/////////////////////////////////////////////////////////////////////////////////////////
string sourceCubeDimension1 = "SCDimension1";
string sourceCubeDimension2 = "SCDimension2";
string targetCubeDimension1 = "TCDimension1";
string targetCubeDimension2 = "TCDimension2";
string targetCubeDimension3 = "TCDimension3";
string hierarchyName = "Hierarchy";
string sourceCubeName = "SourceCube";
string targetCubeName = "TargetCube";
OLAPConnection connection = OLAPCreateNamedConnection("");
// 1. Definition of source data area
StringListList sourceArea = CreateStringListList();
StringList da_sl1 = CreateStringList();
Append(da_sl1, "");
Append(da_sl1, OLAPCreateCompositeName(hierarchyName, "A21"));
Append(da_sl1, OLAPCreateCompositeName(hierarchyName, "A22"));
Append(sourceArea, da_sl1);
StringList da_sl2 = CreateStringList();
Append(da_sl2, "");
Append(da_sl2, OLAPCreateCompositeName(hierarchyName, "B21"));
Append(da_sl2, OLAPCreateCompositeName(hierarchyName, "B22"));
Append(sourceArea, da_sl2);
// 2. Definition of source dimensions for copy data area
StringList sourceDimensions = CreateStringList();
Append(sourceDimensions, sourceCubeDimension1);
Append(sourceDimensions, ""); // Empty string for missing dimension in source cube
Append(sourceDimensions, sourceCubeDimension2);
// 3. Definition of source elements for copy data area
StringListList sourceElements = CreateStringListList();
StringList sl1 = CreateStringList();
Append(sl1, "");
Append(sl1, OLAPCreateCompositeName(hierarchyName, "A21"));
Append(sl1, OLAPCreateCompositeName(hierarchyName, "A22"));
Append(sourceElements, sl1);
Append(sourceElements, CreateStringList()); // Empty string list for missing dimension in source cube
StringList sl2 = CreateStringList();
Append(sl2, "");
Append(sl2, OLAPCreateCompositeName(hierarchyName, "B21"));
Append(sl2, OLAPCreateCompositeName(hierarchyName, "B22"));
Append(sourceElements, sl2);
// 4. Definition of target dimension for copy data area
StringList targetDimensions = CreateStringList();
Append(targetDimensions, targetCubeDimension1);
Append(targetDimensions, targetCubeDimension2);
Append(targetDimensions, targetCubeDimension3);
// 5. Definition of target elements for copy data area
StringListList targetElements = CreateStringListList();
StringList sl3 = CreateStringList();
Append(sl3, "");
Append(sl3, OLAPCreateCompositeName(hierarchyName, "C21"));
Append(sl3, OLAPCreateCompositeName(hierarchyName, "C22"));
Append(targetElements, sl3);
StringList sl4 = CreateStringList();
Append(sl4, "");
Append(sl4, OLAPCreateCompositeName(hierarchyName, "D23")); // TargetCube dimension which is not mapped to any source one must have some element selected
Append(targetElements, sl4);
StringList sl5 = CreateStringList();
Append(sl5, "");
Append(sl5, OLAPCreateCompositeName(hierarchyName, "E21"));
Append(sl5, OLAPCreateCompositeName(hierarchyName, "E22"));
Append(targetElements, sl5);
// 6. Create data area to copy
OLAPDataArea area = OLAPCreateDataArea(connection, sourceCubeName, OlapDataAreaSuppressNull, OlapDataAreaOperatorNone, 0, OlapDataAreaOperatorNone, 0, sourceArea);
// 7. Copy data area with specified mapping of source dimensions to target dimensions
OLAPCopyDataArea(area, targetCubeName, "Relative", 2, targetDimensions, targetElements, sourceDimensions, sourceElements, false, false);
OLAPDisconnect(connection);
}