Tuesday, July 17, 2007

SAP MDM COM API

For more than a year I’ve been using the SAP MDM (Master Data Management) COM API with .NET 1.1. Getting started was frustrating. There isn’t a lot of code samples out there.
Here is a simple function to get the product record by product ID.

public static XCATCOMLib.ResultSet GetResultSet(int productID, XCATCOMLib.Catalog catalog)
{
XCATCOMLib.Search search = new XCATCOMLib.SearchClass();
XCATCOMLib.ResultSetDefinition productsRsDef = null;

// get references to tables
XCATCOMLib.Tables tables = catalog.Tables;
XCATCOMLib.Table prodTable = tables.Item(PRODUCT_TABLE);

// products
productsRsDef = new XCATCOMLib.ResultSetDefinitionClass();
productsRsDef.Table = prodTable.Name;

//get the column names of the product table
for (int j = 0; j < prodTable.Fields.Count; j++)
{
productsRsDef.Fields.Add(prodTable.Fields.Item(j));
}

XCATCOMLib.TableParameter lp = search.Parameters.NewTableParameter(PRODUCT_TABLE);
lp.RecordIDs.Add(productID);

ResultSet rs = catalog.GetResultSet(search, productsRsDef, prodTable.Fields.Item(0).Name, true, 0);

return rs;
}