Problem:

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.

Solution:

Before retrieving the data set the Page size.

Note: Choose wisely according to the requirement (Maximum Page Size = 1000).

//Retrieve data

RetrieveLimitedRecordsExCommand getDataCommad = new RetrieveLimitedRecordsExCommand(<UserSessionContext_instance>);

getDataCommad.setResultDefinition(<ResultDefinition_instance>);

getDataCommad.setPageSize(<PageSize_int>)

getDataCommad.execute();

//Number of records the Search returned

int resultCount = getDataCommad.getSearchTableMatchCount();

//Size of the page

int pageSize = getDataCommad.getPageSize();

//Total pages

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

      getDataCommad.execute();

}

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

    1. Arjun Nair Post author

      There is an example stated in the post… was that not useful?

      The code written there needs to be executed to get each pages result. .

      Or is that you want a real time scenario?

      (0) 
      1. Jun Wu

        tell me how you use it to paginate

        let’s say you displayed first 1000 in the screen, how you get the next 1000?

        if you really did it, tell me exactly what you have done. showing us an api call is nothing.

        (0) 
        1. Arjun Nair Post author

          I will try to explain little more simply,


          Here the whole idea of the pagination is on the MDM search result.


          For every search to the MDM, you can set the size of the PAGE using the (command: .setPageSize(<PageSize_int>)}.

          Page Size is the number of records that the search result should return in each page.

          So, taking your case into consideration, if we have 10000 records as the result of our search and we have adjusted the Page size to 1000(default).

          In this case, after the first execution {command : getDataCommad.execute()} you can get the values{command : objExCommand_allData.getRecords()[returns the list of records which satisfies the search criteria]} which are stored in the PAGE = 0.

          //Number of records the Search returned

          int resultCount = getDataCommad.getSearchTableMatchCount();

          //Size of the page

          int pageSize = getDataCommad.getPageSize();

          //Total pages

          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;

          These variables helps us in iterating through the pages(Explanation provided in green)

          Now that we have retrieved the data from Page = 0, to retrieve the data from the next page,

          Set the PageIndex of the next page and {command: getDataCommad.setPageIndex(page)} and then execute { command: getDataCommad.execute();}  the search ones again.

          This way, you can iterate through the different pages and retrieve the entire data.

          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

          getDataCommad.execute();

          }

          Hope this answers your question.

          Thanks and Regards

          (0) 

Leave a Reply