cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve the table from MDM Server using MDM JAVA API?

Former Member
0 Kudos

hi friends,

How to retrieve the table from MDM Server using MDM JAVA API?

send me the sample code

thanks

ramu.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Ram,

You must have got the answer how to retrieve table from MDM Java API. I agreed with Nitin-the changes he has suggested and Nitin Thanks for appreciation but i am just 8 months old in MDM

Update us if need any further help in this regard.

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi Jitesh

Need a small help

How to call a MDM webservice from the java standalone program, like calling the MDM api from java standalone program.

since one of my coleque told ur expert in MDM and java

Can u please help me if u have any idea

Awaiting for ur response

Regards

Satish

Former Member
0 Kudos

Hi Satish,

Honestly speaking i never tried this thing and I dont want to give any wrong inputs just to prove my self. But will update this thread for sure if i get some thing.

Regards,

Jitesh Talreja

Former Member
0 Kudos

Hi Ram,

Check the bellow code. It wil display all the records of main table but only display fields of the repository will appear in the output.

/*

  • Created on Jan 31, 2008

*

  • To change the template for this generated file go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

//package Test_Package;

import java.util.Locale;

import com.sap.mdm.commands.AuthenticateUserSessionCommand;

import com.sap.mdm.commands.CommandException;

import com.sap.mdm.commands.CreateUserSessionCommand;

import com.sap.mdm.data.Record;

import com.sap.mdm.data.RecordFactory;

import com.sap.mdm.data.RecordResultSet;

import com.sap.mdm.data.RegionProperties;

import com.sap.mdm.data.ResultDefinition;

import com.sap.mdm.data.commands.CreateRecordCommand;

import com.sap.mdm.data.commands.RetrieveLimitedRecordsCommand;

import com.sap.mdm.ids.FieldId;

import com.sap.mdm.ids.TableId;

import com.sap.mdm.internal.protocol.resultset.ResultSet;

import com.sap.mdm.net.ConnectionAccessor;

import com.sap.mdm.net.ConnectionException;

import com.sap.mdm.net.SimpleConnectionFactory;

import com.sap.mdm.schema.FieldProperties;

import com.sap.mdm.schema.RepositorySchema;

import com.sap.mdm.schema.commands.GetFieldListCommand;

import com.sap.mdm.schema.commands.GetRepositorySchemaCommand;

import com.sap.mdm.schema.commands.GetTableListCommand;

import com.sap.mdm.search.Search;

import com.sap.mdm.server.DBMSType;

import com.sap.mdm.server.RepositoryIdentifier;

import com.sap.mdm.valuetypes.StringValue;

public class resultsetiView

{

public static ConnectionAccessor simpleConnection;

public static String connection = "TEST_MDM";

public static String repository = "TEST_REPO";

public static RepositorySchema repSchema;

public static RepositoryIdentifier repIdentifier;

public static DBMSType dbmsType = DBMSType.MS_SQL;

public static String session;

public static void main (String args[])throws CommandException, ConnectionException

{

simpleConnection = SimpleConnectionFactory.getInstance(connection);

repIdentifier = new RepositoryIdentifier(repository, connection, dbmsType);

RegionProperties dataRegion = getRegion();

CreateUserSessionCommand createUSesCmd = new CreateUserSessionCommand(simpleConnection);

createUSesCmd.setDataRegion(dataRegion);

createUSesCmd.setRepositoryIdentifier(repIdentifier);

createUSesCmd.execute();

session = createUSesCmd.getUserSession();

AuthenticateUserSessionCommand authUSesCmd = new AuthenticateUserSessionCommand(simpleConnection);

authUSesCmd.setSession(session);

authUSesCmd.setUserName("Admin");

authUSesCmd.setUserPassword("Pass123");

authUSesCmd.execute();

GetRepositorySchemaCommand getRepSchCmd = new GetRepositorySchemaCommand(simpleConnection);

getRepSchCmd.setSession(session);

getRepSchCmd.execute();

repSchema = getRepSchCmd.getRepositorySchema();

TableId mainTableId = repSchema.getTableId("Title");

GetFieldListCommand getFieldListCommand = new GetFieldListCommand(simpleConnection);

getFieldListCommand.setSession(session);

getFieldListCommand.setTableId(mainTableId);

try

{

getFieldListCommand.execute();

}

catch (Exception e)

{

System.out.println(e);

}

FieldProperties[] fields = getFieldListCommand.getFields();

FieldId[] fid=new FieldId[69];

Search s=new Search(mainTableId);

ResultDefinition rd=new ResultDefinition(mainTableId);

System.out.println(fields.length);

for(int i=0;i<fields.length;i++)

{

fid<i>=fields<i>.getId();

}

rd.setSelectFields(fid);

RetrieveLimitedRecordsCommand ret=new RetrieveLimitedRecordsCommand(simpleConnection);

ret.setSession(session);

ret.setResultDefinition(rd);

try{

ret.execute();

}

catch(Exception e)

{

}

RecordResultSet rs=ret.getRecords();

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

{

Record r=rs.getRecord(i);

System.out.println(r.getDisplayValue());

}

}

public static RegionProperties getRegion()throws CommandException{

RegionProperties regionProperties = new RegionProperties();

regionProperties.setLocale(Locale.ENGLISH);

regionProperties.setName("English [US]");

regionProperties.setRegionCode("engUSA");

return regionProperties;

}

Kindly reward if found useful

Regards,

Jitesh Talreja

}

nitin_mahajan2
Contributor
0 Kudos

Correctiions in above code, though quite generic

Seems like jitesh you have written a webservice over it:-) Great, Though i would suggest you one change when u get the field Ids array from the field properties, the declartion that you have used for fieldIds array can get into trouble if you do not know the number of fields, instead you can use

FieldProperties[] fields = getFieldListCommand.getFields();

FieldId[] fid = new FieldId[ fields.length ];

fid[1] = fields[1].getid(); //can do it in a loop or something where ever required.

one more correction

for(int i=0;i<fields.length;i++)

{

fid<i>=fields<i>.getId();

}

I would also suggest you to segregate the code written in the above snippet, so as to avoid redundancy in your webdynpro code.

anyways, for you to know, Jitesh is the GOD of MDM/Portal stuff...i call for him whenever i need help.

Regards,

Nitin