cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve Data using Java API

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Thanks for your reply.

I have used a similar knid of code to retrieve the fields for the selected table.

Now, I wanted to retrieve the Records, (i.e the data) present in the table.

To retrieve the records, I need the Record Id.

I am not able to retrieve the record id.

Thanks,

Priya.

Former Member
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Thanks for the code.

I am able to retrieve data now.

Thanks & Regards,

Priya.

nitin_mahajan2
Contributor
0 Kudos

The problem for Unknown source is generally from the version mismatch.