cancel
Showing results for 
Search instead for 
Did you mean: 

Creating / updating record from Java API 2

Former Member
0 Kudos

Hi All,

I am trying to create / update record through java API but not able to do so can any one give me the sample code for the same.

Thanks

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hello Ninad,

I am a little late but maybe my code helps to understand a little!

I am Writing into a Record that i retrieved by a search at an earlier point.

Then I define the FieldId that should be changed and the Value that it should be. the Value must be a MdmValue Type.

The Code works fine for me.

Greetz

Tobi


	/**
	 * Method to write record to MDM
	 * @param ProductRecord - the Record the value should be written to
	 * @param FieldToBeWritten - the FieldId that the value should be written to
	 * @param ValueToBeWritten - MDMValue that should be written
	 * @return Boolean that indicates if writing was successfully 
	 **/
	public boolean writeRecord(Record ProductRecord, FieldId FieldToBeWritten, MdmValue ValueToBeWritten){
		// Change Data
		try {
			ProductRecord.setFieldValue(FieldToBeWritten, ValueToBeWritten);
		} catch (IllegalArgumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		} catch (MdmValueTypeException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		// Create the command to commit record
		ModifyRecordCommand mrcTest = new ModifyRecordCommand(mdmcon.getCpConnectionPool());
		mrcTest.setRecord(ProductRecord);
		mrcTest.setSession(mdmcon.getSession());
		mrcTest.setModifyAnyway(false);
		try {
			mrcTest.execute();
		} catch (CommandException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		return true;
	}

Former Member
0 Kudos

Hi Ninad,

For create:

Please try CreateEmptyRecordCommand. Set the table ID before executing the command.

Here, you just specify TableID. It will create a new Record into that table.

If you provide RecordID for CreateEmptyRecordCommand, it will give you reference of existing record.

For Update:

First you will have to use CreateEmptyRecordCommand with the existing recordID.

You will get "Record" as output of this.

Then, you can use ModifyRecordCommand where Record is a mandatory parameter.

Thanks,

Mausam

Former Member
0 Kudos

Hi,

Michal: In examples creating / updating record is not present and I am not able to open the pdf you mentioned it gives me error pdf is damaged is there any other place where I can find the pdf ?

Mausam: I am using Java API 2 and not able to find the class CreateEmptyRecordCommand but there is one class called CreateRecordCommand can I use the same or is there any other way for that?

Is possible for you to paste the code here so that I can get better idea.

Thanks

Ninad

Message was edited by:

Ninad

Former Member
0 Kudos

Hi Ninad,

Sorry to misguide you on that.

Please check class<a href="http://help.sap.com/javadocs/MDM/current/com/sap/mdm/data/RecordFactory.html">RecordFactory</a> and try the function CreateEmptyRecord.

Hope this helps.

Regards,

Mausam

Former Member
0 Kudos

Hi Mausam,

Thanks a lot for your prompt reply but now I am not able to create the instance of the class RecordFactory I think we can't create it I am confused can you please help me?

Thanks

Ninad

Former Member
0 Kudos

Hi Ninad,

You dont have create RecordFactory class instance. The methods in the class are Static. Just type in the class name and call the method.

Thanks,

Mausam

Former Member
0 Kudos

Hi Mausam,

Thanks a lot for your help I could able to add a empty record in it but now I want to have values in it. and I think we can do it by setFieldValue method of record but for that I need a MdmValue type value for this method and I could not able to create new Mdm value can you please help me in this case?

Thanks

Ninad

namrata_d
Active Participant
0 Kudos

Hi Ninad,

You need to StringValue(for text value) LookUpValue(for Look up value) and similarly other classes.

all these classes implement MDMValue .

Former Member
0 Kudos

HI Ninad,

Even i am trying to insert values into a record.

I am trying to insert value into a Look Up Table, i understood that by using setFieldValue.

i have created an Empty Record by using Create Empty Record command,then i need to insert values into it.

If u have any idea please share with me,any peice of code?

With Thanks,

Mary Joseph

MichalKrawczyk
Active Contributor
0 Kudos

hi,

did you have a look at those two:

this one contains many examples in ZIP file:

MDM 5.5 SP05 - Java API Examples (ZIP File) - changed: 06/26/2006

https://websmp101.sap-ag.de/~sapidb/011000358700000535912007E

this is an overall example:

How to Identify Identical Master Data Records Using SAP MDM 5.5 Java APIs

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a06478f5-b28d-2910-e083-c28eb96b...

is that what you need?

Regards,

michal