project BLF > class BGenericReportAdapter > method getTableData

Description

Return the contents of a table in the report resultset of the report that was last run with method openReport.


Parameters


icComponentNameinputcharacter
icReportNameinputcharacter
icTableNameinputcharacter
iiBatchSizeinputinteger
ohTableoutputhandle
olMoreTableDataAvailableoutputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method TGenericReportAdapter.CreateSession


program code (program8/bgenericreportadapter.p)

olMoreTableDataAvailable = FALSE.

/* Retrieve the correct tDatasetInfo record */
FIND FIRST tDatasetInfo WHERE tDatasetInfo.tcComponentName = icComponentName
                          AND tDatasetInfo.tcReportName = icReportName
                          AND tDatasetInfo.tcTableName = icTableName NO-LOCK NO-ERROR.
IF NOT AVAILABLE tDatasetInfo THEN
DO:
    <M-1 run SetMessage
       (input  #T-1'The specified component, report, table combination is not available':100(5122)T-1# (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'E' (icType), 
        input  2 (iiSeverity), 
        input  '' (icRowid), 
        input  'BLF-108':U (icFcMsgNumber), 
        input  #T-2'There was no dataset record found for the specified component, report and table':150(5123)T-2# (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output oiReturnStatus (oiReturnStatus)) in BGenericReportAdapter>
        
    oiReturnStatus = -1.
    RETURN.
END.

/* Prepare the output table */                         
CREATE TEMP-TABLE ohTable in widget-pool "non-persistent".
ohTable:CLEAR().
ohTable:CREATE-LIKE(tDatasetInfo.thDatasetRef:GET-BUFFER-HANDLE(icTableName):TABLE-HANDLE).
ohTable:TEMP-TABLE-PREPARE(icTableName).
    
IF tDatasetInfo.tlTableAvailable = TRUE THEN
DO:    
    /* If there is not already a query open for this table create one */
    IF NOT VALID-HANDLE(tDatasetInfo.thQuery) THEN
    DO:
        CREATE QUERY tDatasetInfo.thQuery in widget-pool "non-persistent".
        tDatasetInfo.thQuery:SET-BUFFERS(tDatasetInfo.thDatasetRef:GET-BUFFER-HANDLE(icTableName)).
        tDatasetInfo.thQuery:QUERY-PREPARE("FOR EACH ":U + icTableName).
        tDatasetInfo.thQuery:QUERY-OPEN().
    END.
    
    /* Initialize the number of rows retrieved = 0 */
    viNumRows = 0.
    
    do while true:
        /* Get the next record from the result dataset */
        tDatasetInfo.thQuery:GET-NEXT().
    
        /* If there is not more data then close the query and set the tableAvailable flag and the output
           flag to FALSE */
        IF tDatasetInfo.thQuery:QUERY-OFF-END THEN
        DO:
            tDatasetInfo.tlTableAvailable = FALSE.
            tDatasetInfo.thQuery:QUERY-CLOSE().
            DELETE OBJECT tDatasetInfo.thQuery NO-ERROR.
            olMoreTableDataAvailable = FALSE.
            LEAVE.
        END.
    
        /* Add the retrieved row to the output table */
        ohTable:DEFAULT-BUFFER-HANDLE:BUFFER-CREATE().
        ohTable:DEFAULT-BUFFER-HANDLE:BUFFER-COPY(tDatasetInfo.thQuery:GET-BUFFER-HANDLE(1)).
    
        viNumRows = viNumRows + 1.
    
        /* If the batchsize number of rows is > 0 (a batch size of 0 indicates that all rows should be 
           retrieved) and the correct number of rows have now been retrieved then set the output flag to 
           TRUE and leave */
        IF iiBatchSize > 0 AND (viNumRows = iiBatchSize) THEN
        DO:
            /* Check is there anymore data to retrieve */
            tDatasetInfo.thQuery:GET-NEXT().
            
            /* If there is not more data then close the query and set the tableAvailable flag and the output
               flag to FALSE */
            IF tDatasetInfo.thQuery:QUERY-OFF-END THEN
            DO:
                tDatasetInfo.tlTableAvailable = FALSE.
                tDatasetInfo.thQuery:QUERY-CLOSE().
                DELETE OBJECT tDatasetInfo.thQuery NO-ERROR.
                olMoreTableDataAvailable = FALSE.
                LEAVE.
            END.
            ELSE
            DO:
                /* Put the cursor back to where it was and set the 
                   olMoreTableDataAvailable flag to TRUE */
                tDatasetInfo.thQuery:GET-PREV().
                olMoreTableDataAvailable = TRUE.
                LEAVE.
            END.
        END.
    END.
END.