Query Chunking and the Chunking Class

Query chunking provides a valuable methodology for displaying query run results of queries with very large result sets.

Using application package class PT_CUBQUERYCHUNK:QueryChunker enables you to display query result sets as frames of rows. The number of rows in a frame can be configured to be between 10 and 1000. This chunking object maintains an internal buffer of 10 frames and it enables the user to navigate the query results frame by frame, not as it refreshes the internal buffer dynamically during navigation.

During navigation, the query is opened only as needed and is closed after the relevant rows are retrieved into the internal buffer area. No open cursors are on the query object during navigation.

To instantiate a chunking object, you would run the following code:

&NewQueryChunk = create PT_CUBQUERYCHUNK:QueryChunker(&myrecordname, &myseqnum,
 &qpromptrec, &COMP_FRAMESIZE, &fheading);

Instantiation requires a query name, a unique sequence number, the prompt record associated with the query (if any), the frame size desired, and a select column heading. This last parameter is used to uniquely identify a select column from the query definition. The query chunker application supports only a single column from the select clause of the query being chunked. The frame size must be between 10 and 1000. If higher or lower values of the frame size are passed in, the number is modified internally to meet this requirement.

Post instantiation, the validity of the instantiation must be checked as shown here:

If Not &NewQueryChunk.valid Then
 /*report an error here */

The class also contains two properties to report error conditions: errorcode and erroropencode. The second property can be checked for any query open error. It reports if the query does not exist or if the user does not have permission to access the query.

If the process is working fine, then this code can get a reference to the current frame:

&retarray = &NewQueryChunk.GetFrame();

The following table lists the error codes for the chunker.

Code

Error

-1

Missing query name.

-2

Missing field heading.

-3

Error opening the query. Check erroropencode for more information.

-4

Mismatch between the prompt record that was passed in and the current query definition prompt values.

-5

Unable to find the field heading that was passed in within the current query definition.

-6

Error reopening query for a new chunk.

This chunking capability can be used anywhere for any query. Page CUB_QUERYNAV_SEC can be added to any component to display chunking results.

These are the rules to use the CUB_QUERYNAV_SEC page:

  1. The following objects must be defined before you access the page:

    Component string &DYN_QUERYNAME;

    Component number &DYN_SEQNUM;

    Component PT_CUBQUERYCHUNK:QueryChunker &cChunker;

    These values hold the query name and the unique sequence number. Remember that the sequence number is used to uniquely identify the query.

    Some components could potentially be using the same query multiple times; the sequence number is used to uniquely identify a query instance. The page activate code makes sure that the current chunking object matches the current query and sequence number that were passed in.

  2. The rowset in the CUB_QUERYNAV_SEC page is populated with the current frame of the chunking object as the page is displayed.

    If this is the first time the chunking object is displayed, then the first frame is shown. This same rowset could be referenced in the calling component.

    &rs = GetLevel0().GetRow(1).GetRowset(Scroll.PSCUBCHUNKING);

    You can navigate back and forth within the chunking page. When the secondary page is dismissed, the rowset contains the current frame. You could also just get the current frame from the chunking object itself.

    &retarray = &cChunker.GetFrame(); /* Get the current frame. */
    &cframe = &cChunker.currentframe; /* Get the current frame number. */
    

    On the CUB_DIMENSION component, an array of chunking classes is instantiated upon component load. Each dynamic query results in a new entry in this array. When you use chunking, the array is traversed to find the correct chunking object to pass into the secondary page. Object &cChunker is set to the appropriate entry from the array and the secondary page then can navigate back and forth.