Need a simple example for OpenEdge Dataset

Posted by atuldalvi123 on 26-Jan-2016 04:10

Hi

Looking for simple example for Dataset with set-callback-procedure and batch-size.

All Replies

Posted by Elsworth Burmeister on 26-Jan-2016 07:36

Hi

This should help you.

{tt.i}.

DEFINE DATASET ds FOR tt.

DEFINE QUERY q FOR dbtable SCROLLING.

DEFINE DATA-SOURCE src FOR QUERY q.

DATASET ds:GET-BUFFER-HANDLE(1):SET-CALLBACK-PROCEDURE("AFTER-ROW-FILL","AfterRowFill",THIS-PROCEDURE).

QUERY q:QUERY-PREPARE ("for each dbtable").

BUFFER tt:FILL-MODE = "EMPTY".

BUFFER tt:BATCH-SIZE = piBatchSize.

BUFFER  tt:ATTACH-DATA-SOURCE(DATA-SOURCE src:HANDLE).

DATASET ds:FILL().

BUFFER  tt:DETACH-DATA-SOURCE().

PROCEDURE AfterRowFill:

   DEFINE INPUT PARAMETER DATASET-HANDLE pdsDataset.

   pdsDataset:GET-BUFFER-HANDLE(1)::tt-name = "test".

END.

Posted by Peter Judge on 26-Jan-2016 07:38
Posted by atuldalvi123 on 26-Jan-2016 09:20

I gone through the link

documentation.progress.com/.../batching-data-with-prodatasets.html

but the off-end example is very confusing. Without define BATCH-SIZE in the example, it will return all the records in 1st attempt. Then what is the use of  LEAVE trigger of defined browser ?  How OFF-END query will work in this case ?

Posted by Elaine Rosenberg on 26-Jan-2016 10:14

Here are code snippets from the Advanced ABL course that also shows batching on the server side. The dataset, dsDealer has a ttDealer parent and ttCar child.

client side:

method public void FetchBatchCarData(input piBatchSize as integer):

    define variable NextRow as integer no-undo initial 1.

    define variable Done as logical no-undo initial no.

    dataset dsDealer:empty-dataset().

    do while not Done:

        dsAdapter:FetchBatchCarData(piBatchSize, NextRow ,

                                      output Done, output dataset dsDealer by-reference).

        NextRow = NextRow + piBatchSize.

    end.

    OpenQuery().

 end method.

server side business entity:

 method public void FetchBatchCarData(

       input piBatchSize as integer,

       input piNextRow as integer,

       output pDone as logical,

       output hdsDealer as handle):  

       /* we will only batch cars as we have a lot of cars */

       DA:BatchFillCars(input piBatchSize,

                        input piNextRow,

                        output pDone,

                        output dataset dsDealer by-reference).

       hdsDealer = dataset dsDealer:handle.

       return.

    end method.

server side data access class:

method public void BatchFillCars (input piBatchSize as integer,

                                       input piNextRow as integer,

                                       output pDone as logical,

                                       output dataset dsDealer):  

       CarDS:Attach(buffer ttCar:handle).

       DealerDS:Attach(buffer ttDealer:handle).

       buffer ttCar:batch-size=piBatchSize.

       CarDS:SetNextRow(piNextRow).

       /* get a batch of records from the ttCar table */

       dataset dsDealer:fill().

       find first ttCar no-error.

       if not available ttCar    

       then

         pDone = true.

       else

         pDone = false.

       CarDS:Detach(buffer ttCar:handle).

       DealerDS:Detach(buffer ttDealer:handle).

       /* remove ttDealer records if this is the second or later batch

           we do not want to send ttDealer records again */

       if piNextRow > piBatchSize

       then for each ttDealer:

           delete ttDealer.

       end.

   end method.

This thread is closed