cancel
Showing results for 
Search instead for 
Did you mean: 

MDM Java API

Former Member
0 Kudos

Hi All,

I am trying to use MDM Java API in a stand alone java application I have MDM API jar files can any one give me template code to retrieve the data from the repository of MDM

Thanks

Ninad

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ninad,

You have not mentioned clearly what(normal text fields, qualifiers, non-qualifiers etc.,) to be retrieved.

But you can go through the code once to get a basic idea of how to retrieve the data.

public ArrayList retrieveCustomer(int id) {

int recordID = -1;

ArrayList service_request = new ArrayList();

// initiliaze class

connectionInfo connClass = new connectionInfo();

// get connection

IConnection connection = connClass.getMdmConn();

// get catalog object

CatalogData catalog = connClass.getCatalog();

ArrayList customer = new ArrayList();

String[] strCustomerFields =

{

"Name 1",

"SCDB_Name",

"Name 2",

"Name 3",

"Name 4",

"Street",

"SinglePayment",

"SAP_ID"

"Facility_Id",

"Facility_Type",

"Facility_Effective_Date",

"Facility_Cancel_Date",

"MLOC",

"Heritage_EPOS_Ind"

};

String[] custQualiferFields =

{

"Sales Data",

"Facility_Own_Status",

"Facility_Reporting_Methods",

"Sales_Stock_Facility",

"ISP_CCDM",

"Cust_Status_Class",

"Cust_Terr_Dist",

"Bank_Details",

"Customer_Contacts",

"Service_Request",

"Partner_Function" };

String[] sales = { salesTN, "Sales_Orgs" };

String[] bankdetails = { "Bank_Details", "Bank_Acct_Number", "Bank_Key", "Country" };

ArrayList nonQualNames = new ArrayList();

nonQualNames.add(sales);

nonQualNames.add(bankdetails);

try {

customer = getRecord("MDM_CUSTOMERS", "ID", id, strCustomerFields, custQualiferFields, nonQualNames);

}

catch (StringException e) {

loc.fatalT(e.toString());

// customer.add(e.getMessage());

}

catch (Exception e) {

loc.fatalT(e.toString());

}

// close connection

connClass.closeConnection(connection);

connClass = null;

return customer;

}

private ArrayList getRecord(String searchTableName,String searchFieldName,int searchIntValue,String[] strFields,String[] strQFields,ArrayList nonQualNames) throws StringException {

int recordID = -1;

ArrayList recordSet = new ArrayList();

// initialize class

connectionInfo connClass = new connectionInfo();

// get connection

IConnection connection = connClass.getMdmConn();

// get connection

CatalogData catalog = connClass.getCatalog();

// set search parameters

Search search = new Search(searchTableName);

ResultSetDefinition rsd = new ResultSetDefinition(searchTableName);

rsd.AddField(searchFieldName);

// Query MDM

A2iResultSet rs = catalog.GetResultSet(search, rsd, null, true, 0);

// Get Record ID of the needed record

for (int i = 0; i < rs.GetRecordCount(); i++) {

if (searchIntValue == rs.GetValueAt(i, searchFieldName).GetIntValue()) {

recordID = rs.GetIDs().GetAt(i);

break;

}

}

// if record is found

if (recordID != -1) {

recordSet = getTableFields(recordSet, catalog, searchTableName, strFields, recordID, strQFields, nonQualNames);

}

else {

for (int y = 0; y < strFields.length; y++) {

recordSet.add(y, "");

}

for (int y = 0; y < strQFields.length; y++) {

recordSet.add(y, "");

}

}

// close connection

connClass.closeConnection(connection);

connClass = null;

//return values

return recordSet;

}

Thanks & Regards,

Suvarna.

    • Award points if helpful.

Former Member
0 Kudos

Hi suvarna,

Thanks a lot for ur help but I am facing problem in connecting to MDM server it self so can you please tell me where can I get the code to get connected with server.

I got one pdf from market place but that guide is not working there are some problems and I get CommandException in that.

Thanks

Ninad

Former Member
0 Kudos

Make sure your API version is the same as the server version. Also, I don't recommend to use MDM4J. Use Java API 2 instead. It's a little easier to work with. At least it follows Java naming convention rules.

Former Member
0 Kudos

Hi Kenny,

I am new to MDM I have downloaded the jar files from service.sap.com how do I check the version of that because I can't uderstand the version from manifest.mf bellow are the content of the file.

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.6.5

Created-By: 1.4.2_12-b03 (Sun Microsystems Inc.)

Class-Path: mdm-core.jar mdm-protocol.jar mdm-common.jar

Thanks

Ninad

Former Member
0 Kudos

The version is listed in the download page. Also, you can click on the info link. It should show you the exact build number. The build number has to match to the server's build number.

Former Member
0 Kudos

Hi kenny,

My java api build number is 5.5.40.83 and my server is 5.5.40.97 so this exception is because of that? or is there any other reason.

bellow I am posting my code

		 String repName = "REPOSITOR_NAME";
		    String dbName = "DB_NAME”;
		    DBMSType dbType = DBMSType.IBM_DB2;

		repId = new RepositoryIdentifier(repName, dbName, dbType);

		RegionProperties dataRegion;

		GetRepositoryRegionListCommand getRepositoryRegionListCommand = new GetRepositoryRegionListCommand(conn);
		getRepositoryRegionListCommand.setRepositoryIdentifier(repId);
		try
		{
			getRepositoryRegionListCommand.execute();
		} catch (CommandException e1)
		{

			e1.printStackTrace();
		}

In above code I get the CommandException @ line getRepositoryRegionListCommand.execute(); and conn object used in previous lines is properly connected and I tried to print the server version and its working so there is some problem in posted code only, for sure.

One more question: what is DB_Name in the parameters and what value I need to give there. I am doubtful about it.

Can you please help me in this regards?

Thanks

Ninad

Former Member
0 Kudos

You can also get the version from the MDM Java API by executing:

java -jar "C:\Program Files\SAP MDM 5.5\mdm-core.jar"

Former Member
0 Kudos

The dbmsName can be the host name in the case of a MSSQL. For a Oracle DBMS, the dbmsName is the Oracle instance name. I am not sure what DB2 use but your "DB_NAME" is more likely the cause of the exception.