Managing the parent-child relationship between dimension elements

You can use the functions OLAPRemoveParentChildRelationship, OLAPChangeParentElement, and OLAPAddParentElement to remove, change, and add parent-child relationships between dimension elements. The functions support batch calls and also direct calls to OLAP.

These are the declarations of the OLAPRemoveParentChildRelationship function:

public void OLAPRemoveParentChildRelationship(OlapEditDimensionRequest request, string childElementName, string parentElementName)
public bool OLAPRemoveParentChildRelationship(OlapConnection connection, string dimension, string elementName, string parentElementName)

These are the declarations of the OLAPChangeParentElement function:

public void OLAPChangeParentElement(OlapEditDimensionRequest request, string element, string oldParent, string newParent)
public bool OLAPChangeParentElement(OlapConnection connection, string dimension, string element, string oldParent, string newParent)

These are the declarations of the OLAPAddParentElement function:

public void OLAPAddParentElement(OlapEditDimensionRequest request, string element, string newParent)
public bool OLAPAddParentElement(OlapConnection connection, string dimension, string element, string newParent)

The subsequent code example demonstrates how to add an element to a new parent:

#define EngineVersion 5.0
#define RuntimeVersion 5.0

void MyOLAPAddParentElement(string element, string newParent)
@Description: "Demonstrates how to add an element to a new parent";
@Category: "Demo";
@Parameter[element]: "Specify element";
@Parameter[newParent]: "Specify new parent";
{
	string dimension = "Product";

	// 1. Create a connection to the OLAP server.
	OLAPConnection olapconnection=OLAPCreateNamedConnection("Training");

	// 2. Add new parent
	OLAPAddParentElement(olapconnection, dimension, element, newParent);

	// 3. Close OLAP connection
	OLAPDisconnect(olapconnection);
}

The subsequent code example demonstrates how to change the parent assignment:

#define EngineVersion 5.0
#define RuntimeVersion 5.0

void MyOLAPChangeParentElement (string element, string oldParent, string newParent)
@Description: "Demonstrates how to change the parent assignment";
@Category: "Demo";
@Parameter[element]: "Specify element";
@Parameter[oldParent]: "Specify old parent";
@Parameter[newParent]: "Specify new parent";
{
	string dimension = "Product";

	// 1. Create a connection to the OLAP server.
	OLAPConnection olapconnection=OLAPCreateNamedConnection("Training");
	
	// 2. Change parent element
	OLAPChangeParentElement(olapconnection, dimension, element, oldParent, newParent);
	
	// 3. Close OLAP connection
	OLAPDisconnect(olapconnection);
}

The subsequent code example demonstrates how to remove an element from a parent:

#define EngineVersion 5.0
#define RuntimeVersion 5.0

void MyOLAPRemoveParentChildRelationship (string element, string parentElement)
@Description: "Demonstrates how to remove an element from a parent";
@Category: "Demo";
@Parameter[element]: "Specify element";
@Parameter[parentElement]: "Specify parent element";

{
	string dimension = "Product";
	
	// 1. Create a connection to the OLAP server.
	OLAPConnection olapconnection=OLAPCreateNamedConnection("Training");

	// 2. Remove the parent-child relationship
	OLAPRemoveParentChildRelationship(olapconnection, dimension, element, parentElement);

	// 3. Close OLAP connection
	OLAPDisconnect(olapconnection);
}