CTBFETCH

Description

Fetches result data.

Syntax

COPY CTPUBLIC.
01 COMMAND             PIC S9(9) COMP SYNC.
01 RETCODE             PIC S9(9) COMP SYNC.
01 TYP                 PIC S9(9) COMP SYNC.
01 OFFSET              PIC S9(9) COMP SYNC.
01 OPTION              PIC S9(9) COMP SYNC.
01 ROWS-READ           PIC S9(9) COMP SYNC.
CALL 'CTBFETCH' USING COMMAND RETCODE TYP OFFSET OPTION ROWS-READ.

Parameters

COMMAND

(I) Handle for this client/server operation. This handle is defined in the associated CTBCMDALLOC call.

RETCODE

(O) Variable where the result from an executed function returns. Its value is one of the codes listed under “Return value,” in this section.

TYP

(I) This argument is currently unused and should be passed as CS-UNUSED in order to ensure compatibility with future versions of Client-Library.

OFFSET

(I) This argument is currently unused and should be passed as CS-UNUSED in order to ensure compatibility with future versions of Client-Library.

OPTION

(I) This argument is currently unused and should be passed as CS-UNUSED in order to ensure compatibility with future versions of Client-Library.

ROWS-READ

(I) Variable where the number of result rows is returned. This variable is of type integer. CTBFETCH sets ROWS-READ to the number of rows read by the CTBFETCH call. This argument is required.

Returns

CTBFETCH returns one of the following values listed in Table 3-12.

Table 3-12: CTBFETCH return values

Value

Meaning

CS-SUCCEED (-1)

The routine completed successfully.

CTBFETCH places the total number of rows read in ROWS-READ.

CS-FAIL (-2)

The routine failed.

CTBFETCH places the number of rows fetched before the failure occurred in ROWS-READ.

A common reason for a CTBFETCH failure is that a program variable specified through CTBBIND is too small to hold a fetched data item.

CS-CANCELLED (-202)

The operation was canceled.

CTBFETCH places the number of rows fetched before the cancel occurred in ROWS-READ.

CS-ROW-FAIL (-203)

A recoverable error occurred while fetching a row.

Recoverable errors include memory allocation failures and conversion errors that occur while copying row values to program variables.

An application can continue calling CTBFETCH to continue retrieving rows, or can call CTBCANCEL to cancel the remaining results.

CTBFETCH places the number of rows fetched before the error occurred in ROWS-READ, then continues by fetching the row after the error.

CS-END-DATA (-204)

No more rows are available in this result set. (Note that this is also a successful completion.

TDS-INVALID-PARAMETER (-4)

One of the CTBFETCH arguments contains an illegal value.

The most likely cause of this code is assigning a value other than CS-UNUSED to one of more of the reserved arguments, TYP, OFFSET, and OPTION.

TDS-WRONG-STATE (-6)

Program is in the wrong communication state to issue this call. It is in Send state instead of Receive state.

Examples

Example 1

The following example shows a typical use of CTBFETCH. It is taken from the sample program SYCTSAA5 in Appendix A, “Sample Language Requests.”

     *========================================================
	 *==                                                    ==
	 *== Subroutine to fetch row processing                 ==
	 *==                                                    ==
	 *========================================================
	FETCH-ROW-PROCESSING.
            CALL 'CTBFETCH' USING CSL-CMD-HANDLE,
                                  CSL-RC,
                                  CS-UNUSED,
                                  CS-UNUSED,
                                  CS-UNUSED,
                                  FF-ROWS-READ.
            EVALUATE CSL-RC
                WHEN CS-SUCCEED
                     MOVE 'Y'             TO SW-FETCH
                     MOVE CS-VARCHAR-TYPE TO DF-DATATYPE
                     MOVE LENGTH OF CF-COL-FIRSTNME-TXT
                                          TO DF-MAXLENGTH
                     MOVE CS-CHAR-TYPE    TO DF2-DATATYPE
                     MOVE LENGTH OF CF-COL-FIRSTNME-CHAR
                                          TO DF2-MAXLENGTH
                     CALL 'CSBCONVE' USING CSL-CTX-HANDLE,
                                           CSL-RC,
                                           DATAFMT,
                                           CF-COL-FIRSTNME,
                                           DATAFMT2,
                                           CF-COL-FIRSTNME-CHAR,
                                           CF-COL-LEN
                     IF CSL-RC NOT EQUAL CS-SUCCEED
                       THEN
                          MOVE SPACES TO MSGSTR
                          STRING 'CSBCONVERT CS-VARCHAR-TYPE failed'
                                      DELIMITED BY SIZE INTO MSGSTR
                          PERFORM PRINT-MSG
                          PERFORM ALL-DONE
                     END-IF
                     COMPUTE FF-ROW-NUM = FF-ROW-NUM + 1
       **************************************
       * save ROW RESULTS for later display *
       **************************************
                     MOVE CF-COL-FIRSTNME-CHAR TO
                          OR-COL-FIRSTNME-CHAR
                     MOVE DATA-SMALLINT TO
                          OR-COL-EDUCLVL
                     IF FF-ROW-NUM > MAX-SCREEN-ROWS
                       THEN
                         STRING 'Please press return to continue.'
                                DELIMITED BY SIZE INTO MSG1O
                         MOVE SPACES TO MSG-TEXT-2
                         PERFORM DISP-DATA
                         PERFORM CLEAR-SCREEN-DATA
                                 VARYING FF-ROW-NUM FROM 1 BY 1
                                 UNTIL FF-ROW-NUM > MAX-SCREEN-ROWS
                         MOVE LOW-VALUES TO A5PANELO
                         COMPUTE PAGE-CNT = PAGE-CNT + 1
                         MOVE 1 TO FF-ROW-NUM
       **------------------------------------------------------------
       **   Setup column headings
       **------------------------------------------------------------
                         MOVE 'FirstName    EducLvl' TO
                                          RSLTNO(FF-ROW-NUM)
                         COMPUTE FF-ROW-NUM = FF-ROW-NUM + 1
                         MOVE '===========  =======' TO
                                          RSLTNO(FF-ROW-NUM)
                         COMPUTE FF-ROW-NUM = FF-ROW-NUM + 1
                     END-IF
                     MOVE OUTPUT-ROW-STR TO RSLTNO(FF-ROW-NUM)
                     MOVE SPACES         TO CF-COL-FIRSTNME-TXT
                WHEN CS-END-DATA
                     MOVE SPACES     TO MSG1O
                     MOVE 'N'        TO SW-FETCH
                     MOVE 'Press Clear To Exit'
                                     TO MSG-TEXT-2
                     STRING 'All rows processing completed!'
                            DELIMITED BY SIZE INTO MSG1O
                     PERFORM DISP-DATA
                WHEN CS-FAIL
                     MOVE 'N'    TO SW-FETCH
                     MOVE SPACES TO MSGSTR
                     STRING 'CTBFETCH returned CS-FAIL ret-code'
                            DELIMITED BY SIZE INTO MSGSTR
                     PERFORM PRINT-MSG
                WHEN CS-ROW-FAIL
                     MOVE 'N'    TO SW-FETCH
                     MOVE SPACES TO MSGSTR
                     STRING 'CTBFETCH returned CS-ROW-FAIL ret-code'
                                     DELIMITED BY SIZE INTO MSGSTR
                     PERFORM PRINT-MSG
                WHEN CS-CANCELLED
                     MOVE 'N'         TO SW-FETCH
                     MOVE MF-CANCELED TO MSG1O
                     PERFORM PRINT-MSG
                WHEN OTHER
                     MOVE 'N'    TO SW-FETCH
                     MOVE SPACES TO MSGSTR
                     STRING 'CTBFETCH returned UNKNOWN ret-code'
                                     DELIMITED BY SIZE INTO MSGSTR
                     PERFORM PRINT-MSG
            END-EVALUATE.
        FETCH-ROW-PROCESSING-EXIT.
            EXIT.

Usage


Fetching regular rows

Regular rows can be fetched from the server one row at a time, or several rows at once.


Fetching return parameters

A return parameter result set contains either stored procedure return parameters or message parameters.


Fetching a return status

A stored procedure return status result set consists of a single row with a single column, containing the status.

See also

Related functions

Related documentation