on 03-27-2008 12:12 PM
Hi,
I am trying to create a java program, to retrieve data using Java API.
I have done the following things.
Connect to the MDM Server
Connect to the repository
Create a user session.
Enter a Table Name.
Retrieve the Table ID
Retrieve all the field present under the table, and kept it in an array.
Now, If I want to display all the data present in the selected table, or display a set of records, with some condition in the selected table, then I have to first retrieve the record id, of all the records, and then display the corresponding data.
But, I am not able to retrieve this record id, and data.
Let me know someone can help in this.
Thanks in Advance.
Priya.
Hi priya
Just go through this code.
// retrieve the list of tables and pick the main table
GetTableListCommand tableListCommand = new GetTableListCommand(connections);
tableListCommand.setSession(sessionId);
try {
tableListCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
TableProperties mainTable = null;
TableProperties[] tables = tableListCommand.getTables();
for (int i = 0; i < tables.length; i++) {
if (tables<i>.getType() == TableProperties.MAIN)
mainTable = tables<i>;
}
// retrieve the list of fields from the main table
// this is useful for resolving conflicting field names the new field might create
GetFieldListCommand getFieldListCommand = new GetFieldListCommand(connections);
getFieldListCommand.setSession(sessionId);
getFieldListCommand.setTableId(mainTable.getId());
try {
getFieldListCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
I think it may help u.
Regards
Hari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hope this code gives you the solution:-
ResultDefinition objRD = new ResultDefinition(new TableId("T121"));
objRD.addSelectField(new FieldId("F639_149743"));
RetrieveLimitedRecordsCommand recordsCommand = new RetrieveLimitedRecordsCommand(objAtt.connections);
recordsCommand.setSession(objAtt.sessionId);
recordsCommand.setSearch(new Search(new TableId("T121")));
recordsCommand.setResultDefinition(objRD);
try {
recordsCommand.execute();
} catch (CommandException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Record[] taxoSubClassRecs= recordsCommand.getRecords().getRecords();
For i to taxoSubClassRecs.length
RecordId objrecId = taxoSubClassRecs<i>.getId();
Cheers
hi priya,
// authenticate the user session
String userName = "me";
String userPassword = "me";
AuthenticateUserSessionCommand authCommand = new AuthenticateUserSessionCommand(connections);
authCommand.setSession(sessionId);
authCommand.setUserName(userName);
authCommand.setUserPassword(userPassword);
try {
authCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// the main table, hard-coded
TableId mainTableId = new TableId(1);
// specify the result definition (what to retrieve); in this example, nothing
ResultDefinition rd = new ResultDefinition(mainTableId);
// select all records
Search search = new Search(mainTableId);
// retrieve the records
RetrieveLimitedRecordsCommand limitingCommand = new RetrieveLimitedRecordsCommand(connections);
limitingCommand.setSession(sessionId);
limitingCommand.setResultDefinition(rd);
limitingCommand.setSearch(search);
//limitingCommand.setPageSize(10);
try {
limitingCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
System.out.println("Record count is " + limitingCommand.getRecords().getCount());
Here is a code by using this u can retrive the main table records.
After creating UserSessionCommand you have to write the above code.
i think it help's you
thanks
vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have tried the code, that you have give me, but I got an error.
Exception in thread "main" java.lang.IllegalArgumentException: The array of table schemas must contain at least one table.
at com.sap.mdm.schema.RepositorySchema.<init>(RepositorySchema.java:63)
at com.sap.mdm.data.commands.RetrieveLimitedRecordsCommand.execute(Unknown Source)
at login.MainTableRecord.main(MainTableRecord.java:135)
Thanks,
Priya.
hi priya,
Exception in thread "main" java.lang.IllegalArgumentException: The array of table schemas must contain at least one table.
at com.sap.mdm.schema.RepositorySchema.<init>(RepositorySchema.java:63)
at com.sap.mdm.data.commands.RetrieveLimitedRecordsCommand.execute(Unknown Source)
at login.MainTableRecord.main(MainTableRecord.java:135)
for this see this thread.
it may be server version problem.
regards,
vijay
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.