on 05-16-2007 9:18 PM
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
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
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 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.