cancel
Showing results for 
Search instead for 
Did you mean: 

Iterate through all the records in a table using Java API

Former Member
0 Kudos

Hi All,

What is the easiest way to iterate through all the records in a given table using Java API? I cannot find any methods that will return all records in a table and the only way I can use is to perform a free form search with a condition that is always true. The code works but is pretty ugly. Is there an alternative to this approach?

Thanks!

Kenny

Accepted Solutions (1)

Accepted Solutions (1)

former_member496675
Participant
0 Kudos

Try this

RetrieveLimitedRecordsCommand retrieveRecordsCmd = new RetrieveLimitedRecordsCommand(ConnectionPoolFactory.getInstance(<pass your parameter>));

retrieveRecordsCmd.setSearch(new Search(new TableId(<pass your table code>)));

ResultDefinition resultDefinition = new ResultDefinition(<define your resultsetdefinition>);

retrieveRecordsCmd.setResultDefinition(resultDefinition);
retrieveRecordsCmd.setSession(<set user session>);
retrieveRecordsCmd.execute();

now get your resultset and iterate through all the records...

-Y

Former Member
0 Kudos

Thanks for your reply. I am using MDM4J. Your codes are using another set of APIs. Is MDM4J obsoleted?

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

I have same problem. I have 1 million products table and need to get information for all.

Currently, I can get only 1000 records with RetrieveLimitedRecordsCommand.

In the second iteration of this loop, metaData has null value. Is this normal? Metadata is returned only on first iteration?

I haven't tested what value records array will have in the second iteration.

for (int pageIndex = 0; pageIndex < MAX_PAGE_SIZE; pageIndex++) {

retrieve.setPageIndex(pageIndex);

RecordResultSet resultSet = retrieve.getRecords();

MetadataItem metaData = resultSet.getMetadata();

//here metaData has null value in the second iteration of above for loop

Record[] records = resultSet.getRecords();

}

Thanks

Erol Akarsu

Former Member
0 Kudos

Hello all,

I'm using the new JavaAPI on SP04 and did a "search" on a lookup table to retrieve all records.

...

retrieveLimitedRecordsCommand.execute();

result = retrieveLimitedRecordsCommand.getRecords();

But it turns out, that just exactly 1000 out of the almost 5000 records are returned as a result..! Everything works fine, so there is no error message or something like that. I also did not limit the search and connect with the Admin user (no limitations).

Anybody worked with "mass data"...!? Any help is appreciated!

Thanks,

Andreas

Former Member
0 Kudos

Please take a look at the Javadoc for the command RetrieveLimitedRecordsCommand. It has two methods setPageSize and setPageIndex.

In general, you should page through your 5000 records, perhaps 1000 records at a time. Depending on the data you are retrieving, you will need to have enough memory to hold the data. This is why paging is the way to go.

KlausDavid
Advisor
Advisor
0 Kudos

Under http://service.sap.com/installMDM you can find the current documentation for MDM. In the "Operations"-section there's a link to the JAVA API documentation and as well a tutorial.

Additional coding samples come in the package com.sap.mdm.examples in the online documentation.

Regards Klaus

Former Member
0 Kudos

Hi David,

Will the new MDM Java API released with SP05 be able to access Image and PDF data stored in the repository?

Best Regards,

Mark

Former Member
0 Kudos

Hi Kenny,

You can construct a new Search object with your table's code name, a new ResultSetDefinition object for your table and just execute this search using the GetResultSet method of CatalogData.

Please look at the following code:

Search search = new Search(<code name of your table>);
ResultSetDefinition rsd = new ResultSetDefinition(<code name of your table>);
rsd.AddField<code name of a field>);
rsd.AddField(<code name of a field>);
.
.
.
String sortField = <code name of your sort field>;
boolean sortAscending = true;
int page = 0; //page number
A2iResultSet rs = <your CatalogData object>.GetResultSet(search, rsd, sortField, sortAscending, page);

for (int i = 0; i < rs.GetRecordCount(); i++)
{
    Value fieldValue = rs.GetValueAt(i, <code name of a field>);
    .
    .
    .
}

Hope this helps,

Nir

PS - I really recommend you to start using the new API, as it is much more efficient and straight-forward.

KlausDavid
Advisor
Advisor
0 Kudos

MDM4J is deprecated with SP05, no further development will be provided for MDM4J.

It's replaced by the MDM JAVA API, introduced with SP03.

Regards Klaus

Former Member
0 Kudos

So where can I find the latest documentations and examples on the new Java APIs? A lot of existing documentations are only for MDM4J.

Thanks again!

Kenny