![]() |
Languages »
C# »
How To
Intermediate
License: The Code Project Open License (CPOL)
Merging SAP PS with MS ProjectBy PhiBThis article focuses on a key factor in translating an SAP PS (Project System) project to an MS Project .mpp file. Creating an MS Project Hierarchy from an SAP PS project takes an understanding of the SAP data provided and some fairly simple C# code. |
C#, Windows, .NET, SAP, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
This article reviews a subroutine for building the Microsoft Project hierarchy from an SAP PS project.
SAP PS is a part of the SAP ERP system used by most of the fortune 500 companies. The SAP PS module is highly integrated with other SAP modules including FI, Controlling, MM, HR, Capacity Planning, Plant Maintenance, etc. SAP PS is a highly detailed project control tool. MS Project is the tool of choice for working a project, with a team, at a task level (rough project planning).
Merging these two systems usually entails using very expensive third party software such as Impress or Pipeline software through a custom development process. A standard alternative is to use the free, SAP provided, OpenPS interface as the integration mechanism. Problematically, the OpenPS interface is non-configurable.
The code provided will integrate an SAP PS project into MS Project, in both directions, at a task level. You can create a new MS Project from SAP PS, insert new tasks in MS Project that are uploaded to SAP PS, create new tasks in MS Project that are not uploaded to SAP PS, or create new WBSs and Network-Activities in SAP PS that are transferred to the target MSP project.
The first step is to get the project data from SAP. This C# code uses the SAP Net Connector 2.0 with .NET 3.5 to make a call to SAP's “BAPI_PROJECT_GETINFO” function. It returns all the data we need. The Code Project website already has an excellent article outlining this method at http://www.codeproject.com/KB/dotnet/Connect_SAP_from_VS2008.aspx.

The subroutine GetTaskHierarchy accepts two arrays from the preceding data call, and populates our control structure arTaskHierarchy. We get the superior WBS Hierarchy by processing the array arWBSHRCY. Next, we get the Network-Activity Hierarchy by processing the provided arNtwkActy array and integrating the two.

public void GetTaskHierarchy(CSAPData.BAPI_WBS_HIERARCHIETable arWBSHRCY,
CSAPData.BAPI_NETWORK_ACTIVITY_EXPTable arNtwkActy)
{
CTaskHier buffTask = new CtaskHier();
int iCount = 0;
// Remove all values in the Task Hierarchy “List” collection
arTaskHierarchy.RemoveAll(Item => Item != null);
//Process WBS hierarchy
for (int I = 0; I < arWBSHRCY.Count; i++)
{
CtaskHier oWBStask = new CtaskHier();
// Start at the root
if (I == 0)
{
oWBStask.Level = 1;
}
else
{ // Check if the “Up” member is different
if (arWBSHRCY[i].Wbs_Element != arWBSHRCY[i].Up)
{
//Get the level of the “Up” ElementID
foreach (CtaskHier t in arTaskHierarchy)
{
if (t.ElementID == arWBSHRCY[i].Up)
{
oWBStask.Level = t.Level + 1;
break;
}
}
}
}
oWBStask.TaskID = I;
oWBStask.ArrayPtr = I;
oWBStask.TaskType = TaskType.WBS;
oWBStask.ElementID = arWBSHRCY[i].Wbs_Element;
oWBStask.SubID = “”;
arTaskHierarchy.Add(oWBStask);
oWBStask = null;
}
//Process Networks and Activities
// Note: Networks with no Activities are not processed
iCount = 1;
for (int I = 0; I < arNtwkActy.Count; i++)
{
// Get the level of the associated WBS
foreach (CtaskHier t in arTaskHierarchy)
{
if (t.ElementID == arNtwkActy[i].Wbs_Element)
{
buffTask = t;
break;
}
}
CtaskHier otask = new CtaskHier();
//We insert after the found WBS
otask.TaskID = buffTask.TaskID + iCount++;
otask.ArrayPtr = I;
otask.TaskType = TaskType.Activity;
otask.ElementID = arNtwkActy[i].Network;
otask.SubID = arNtwkActy[i].Activity;
otask.Level = buffTask.Level + 1;
otask.TaskDesc = arNtwkActy[i].Description;
arTaskHierarchy.Insert(otask.TaskID, otask);
otask = null;
}
The end result, loaded in a MS DataGrid, is shown below:

Interfacing with the MS Project application is done by creating a VS C# “Project 2007 Add-In” project. An article describing this can be found at: http://zo-d.com/blog/archives/programming/making-the-move-from-vba-to-vsto-in-microsoft-project.html.
The figure below shows our results. Note that task #6 is flagged as a non-SAP task, and hence will not be transferred into SAP.

It’s worth noting that our CTaskHierarchy array will be iterated over and searched extensively in our code. To facilitate this, this class is derived from the IEnumerable collection class. Searching in the array is enhanced through the addition of a C# “delegate” to the class. CodeProject has a good article describing this method, at: http://www.codeproject.com/KB/mcpp/csdeleg01.aspx?display=Print.
public CTaskHier Find(String sType, String sID, String sSubID)
{
return arTaskHierarchy.Find(delegate(CTaskHier obj)
{ return (obj.TaskType == sType && obj.ElementID == sID &&
obj.SubID == sSubID); });
}
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 4 Nov 2009 Editor: Smitha Vijayan |
Copyright 2009 by PhiB Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |