Fetch with Pages (SAP IS Adapter)

To fetch a larger data set, a loop is required to fetch all records if the number of records is larger than the page size. The immediate results from each iteration are stored to the data store and the full set of results can be retrieved from it after the loop is completed.

You can either increment the page number or add a criterion “business key is larger than business key of the last record”.

In this example, a custom Groovy script is used to increment the page number property in each loop.

import com.sap.gateway.ip.core.customdev.util.Message; import groovy.json.* def processData(Message message) { def pageNumberProp = message.getProperty("pageNumber") def pageNumber = 1 if (pageNumberProp){ pageNumber = (pageNumberProp as int) + 1 } message.setProperty("pageNumber", pageNumber as String) return message }

After the page number property is updated to the current page, call the fetch operation with the same fetch request message. See Fetch (SAP IS Adapter) for the configuration of the fetch operation.

Count the number of records returned with a custom Groovy script and compare this property with the page size in the looping process call condition. If the number of records returned is smaller than the page size, no further fetch request is required as it is already the last page.

import com.sap.gateway.ip.core.customdev.util.Message; import groovy.json.* def processData(Message message) { //Body def body = message.getBody(String.class) def jsonSlurper = new JsonSlurper() def json = jsonSlurper.parseText(body) message.setProperty("recordCount", json.size()?:0) return message }