Pagination of MDM search result in Java
SAP MDM is a repository which can hold a huge and complex data. So, searching the repository and retrieving data from the table is a heavy task. We have the SAP provided MDM APIs in place to carry out the search and return the result. But, when the result is huge, it is a risk to increase the page size according to the response result.
For example, if the search result is expected to return 10K values and for which we have increased the page size to 10k, then there is chance that the system goes down or the system will encounter an delayin response time. Thus to overcome this situation we will have the paging concept implemented here, while retrieving we just need to mention the below code snippet.
Before retrieving the data set the Page size.
Note: Choose wisely according to the requirement (Maximum Page Size = 1000).
RetrieveLimitedRecordsExCommand getDataCommad = new RetrieveLimitedRecordsExCommand(<UserSessionContext_instance>);
//Number of records the Search returned
int resultCount = getDataCommad.getSearchTableMatchCount();
//Size of the page
int pageSize = getDataCommad.getPageSize();
int totalPages = resultCount/pageSize;
// if there are 1030 records then totalPages = 1, while there are 2 pages
// when Page Size is 1000.
// Hence a Modulo would help us to know if there is an extra page
int hadExtraValues = resultCount%pageSize;
if(hadExtraValues != 0)
totalPages++; // if there is an extra page then the var:totalPages is increased by 1
Record tempRecord = null;
int arraySize = 0;
//int page Will start from 1 as the getDataCommad.execute(); will return the //records in page = 0.
for(int page=1; page<= totalPages; page++)
//TODO – Code to manipulate with the records in Page = page.
getDataCommad.setPageIndex(page)//Set the next page Index