In this example, the client defines variables to hold the ROWID that specify where the last batch ended and an integer to specify the size of the batch to be retrieved from the server. The server-side procedure, fetchOrders(), is called to retrieve 10 order records that are added to the dsOrder dataset’s temp-table, ttOrder. The first time this procedure is called, rowRestart is unknown. The server-side code uses this value to begin the FILL operation starting with the first record in the database table. The fetchOrders() procedure returns the ROWID of the next record to retrieve (where the batch ended). Note this code does not yet show the event handling in the client that is used to handle the QUERY-OFF-END condition that triggers another retrieval from the server.

/* client-side code */
{include/dsOrder.i}

DEFINE QUERY qryOrder FOR ttOrder.
DEFINE VARIABLE rowRestart AS ROWID NO-UNDO.
DEFINE VARIABLE batchSize AS INTEGER NO-UNDO INITIAL 10.

/* Fetch the first batch of data, passing the rowid from which to
start fetching data. This comes from the NEXT-ROWID of the DATASOURCE 
on the server after the previous fetch. Pass in ? and the
server-side code always start reading from the beginning of the
record-set which matches the query's criteria. */

rowRestart = ?.
RUN fetchOrders ON hServer (batchSize,INPUT-OUTPUT rowRestart,OUTPUT DATASET dsOrder).
OPEN QUERY qryOrder FOR EACH ttOrder BY ttOrder.OrderNum.
QUERY qryOrder:GET-NEXT().
DO WHILE NOT QUERY qryOrder:QUERY-OFF-END:
  MESSAGE "OrderNum:" ttOrder.OrderNum " Status: "
    ttOrder.OrderStatus.
 QUERY qryOrder:GET-NEXT().
END.