Using OLAPCopyDataArea

The purpose of the OLAPCopyDataArea function is to copy data from a defined data area to a target cube. The function uses the OLAP DataareaCopy functionality.

This is the declaration of the OLAPCopyDataArea function:

void OLAPCopyDataArea (OlapDataArea dataArea, string targetCube, string type, double factor, StringListList targetElements, StringListList sourceElements,
bool nonExistentCellSupression, bool useOnlyBasicElements)

These are the parameters of the OLAPCopyDataArea function:

Parameters Description
dataArea Data area used as a data source.
targetCube Name of the target cube that will receive the data copy.
type Relative change: values from the source cells are multiplied by the factor before they are copied.
factor Absolute change: the factor is added to the source values before they are copied.
targetElements A StringListList instance that contains a StringList for each dimension of the target cube. Each of the StringLists contains names of target elements that define the cells of the target cube.
sourceElements A StringListList instance that contains a StringList for each dimension of the source cube. Each of the StringLists contains names of elements that define the cells of the source cube.
nonExistentCellSupression Bool that indicates whether the non existing cells should be suppressed.
useOnlyBasicElements Bool that indicates whether only base elements should be used.

The OLAPCopyDataArea function does not return a value.

The OLAPCopyDataArea function throws an exception in these cases:

  • The source data area is not valid or is not active.
  • The target cube does not exist.
  • The type parameter contains invalid value.
  • The target element list does not match the source element list.
  • The size of the targetElements or sourceElements does not match the dimension count of the target cube.
  • One of the elements in the targetElements or sourceElements does not exist.
  • An error occurs on the side of OLAP because the data area could not be copied for some reason (the exception message contains the error number).
The subsequent code example shows how to use this function:
Note: The example requires input parameters, which are set with an Application Studio report. This example references the database of the Samples application, which can be enabled only in on-premises environments. If you do not have access to Samples, a summary description of the structure of the database is given for your reference.
#define EngineVersion 5.0
#define RuntimeVersion 5.0

void MyCopyDataAreaProcess(string sourcePeriod, string sourceMeasure, string sourceValueType, string targetPeriod, string targetMeasure, string targetValueType)
@Description: "Example how to use OLAPCopyDataArea function within the ANALYSIS cube on the Samples database";
@Category: "Demo";
@Returns: "No value returned";
@Parameter[sourcePeriod]: "The period to copy values from";
@Parameter[sourceMeasure]: "The measure to copy values from";
@Parameter[sourceValueType]: "The source value type copy values from";
@Parameter[targetPeriod]: "Target period to write to";
@Parameter[targetMeasure]: "Target measure to write to";
@Parameter[targetValueType]: "Target value type to write to";
{
	string cube = "Analysis";

	// 1. Create a connection to the OLAP server.
	OLAPConnection olapconnection=OLAPCreateNamedConnection("BestPracticesOLAP");
	
	// 2. Create string list for target data area
	StringListList targetElements = CreateStringListList();
	StringList slPeriods = ConvertToStringList(targetPeriod);
	StringList slPOS = ConvertToStringList(OlapDataAreaBCells);
	StringList slProducts = ConvertToStringList(OlapDataAreaBCells);
	StringList slRegions = ConvertToStringList(OlapDataAreaBCells);
	StringList slChannels = ConvertToStringList(OlapDataAreaBCells);
	StringList slMeasure = ConvertToStringList(targetMeasure);
	StringList slValueType = ConvertToStringList(targetValueType);
	Append(targetElements, slPeriods);
	Append(targetElements, slPOS);
	Append(targetElements, slProducts);
	Append(targetElements, slRegions);
	Append(targetElements, slChannels);
	Append(targetElements, slMeasure);
	Append(targetElements, slValueType);
	
	// 3. Create string list for source data area
	StringListList sourceElements = CreateStringListList();
	StringList src_slPeriods = ConvertToStringList(sourcePeriod);
	StringList src_slMeasure = ConvertToStringList(sourceMeasure);
	StringList src_slValueType = ConvertToStringList(sourceValueType);
	Append(sourceElements, src_slPeriods);
	Append(sourceElements, slPOS);
	Append(sourceElements, slProducts);
	Append(sourceElements, slRegions);
	Append(sourceElements, slChannels);
	Append(sourceElements, src_slMeasure);
	Append(sourceElements, src_slValueType);

	// 4. Delete all existing values in the target area.
	// Filter data area to values that are not null (suppress null values). Use base elements only
	OLAPDataArea deleteValues = OLAPCreateDataArea(olapconnection, cube,
	                                               OlapDataAreaIncludeB | OlapDataAreaSuppressNull, OlapDataAreaOperatorNone,
	                                               0.0, OlapDataAreaOperatorNone, 0, targetElements);
	OLAPDeleteDataArea(deleteValues);
	

	// 5. Filter data area to values that are not null (suppress null values). Use the base elements only
	OLAPDataArea localValues = OLAPCreateDataArea(olapconnection, cube,
	                                              OlapDataAreaIncludeB | OlapDataAreaSuppressNull, OlapDataAreaOperatorNone,
	                                              0.0, OlapDataAreaOperatorNone, 0, sourceElements);
	

	// 6. Copy Data area
	OLAPCopyDataArea(localValues, cube, "Relative", 1.0, targetElements, sourceElements, false, false);
	
	// 7. Close OLAP connection
	OLAPDisconnect(olapconnection);
	
}