CTBFETCH

Description

Fetches result data.

Syntax

%INCLUDE CTPUBLIC;
DCL
     01 COMMAND        FIXED BIN(31) INIT(0);
     01 RETCODE        FIXED BIN(31) INIT(0);
     01 TYP            FIXED BIN(31);
     01 OFFSET         FIXED BIN(31);
     01 OPTION         FIXED BIN(31);
     01 ROWS_READ      FIXED BIN(31);
 
 CALL CTBFETCH (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 SYCTSAA4 sample program in Appendix A, “Sample Language Application.”

	/*------------------------------------------------------------------*/
 	/*                                                                  */
 	/* Subroutine to fetch row processing                               */
 	/*                                                                  */
 	/*------------------------------------------------------------------*/
 		FETCH_ROW_PROCESSING: PROC ;
 
         CALL CTBFETCH( CSL_CMD_HANDLE,
                        CSL_RC,
                        CS_UNUSED,       /* type   */
                        CS_UNUSED,       /* offset */
                        CS_UNUSED,       /* option */
                        FF_ROWS_READ ) ;
 
         SELECT( CSL_RC ) ;
 
           WHEN( CS_SUCCEED )
           DO ;
             NO_MORE_ROWS         = FALSE ;
             CF_COL_FIRSTNME_CHAR = BLANK ;
             DF_DATATYPE          = CS_VARCHAR_TYPE;
             DF_MAXLENGTH         = LENGTH( CF_COL_FIRSTNME ) ;
             DF2_DATATYPE         = CS_CHAR_TYPE;
             DF2_MAXLENGTH        = STG(CF_COL_FIRSTNME_CHAR);
 
             CALL CSBCONVE( CSL_CTX_HANDLE,
                            CSL_RC,
                            DATAFMT,
                            CF_COL_FIRSTNME,
                            DATAFMT2,
                            CF_COL_FIRSTNME_CHAR,
                            CF_COL_LEN);
 
             IF CSL_RC ^= CS_SUCCEED THEN
             DO ;
               MSGSTR       = 'CSCONVERT CS_CHAR_TYPE failed' ;
               NO_ERRORS_SW = FALSE ;
               CALL ERROR_OUT;
               CALL ALL_DONE;
             END ;
 
             FF_ROW_NUM = FF_ROW_NUM + 1 ;
 
 /*------------------------------------------------------------*/
 /* save ROW RESULTS for later display                         */
 /*------------------------------------------------------------*/
 
             OR_COL_FIRSTNME_CHAR = CF_COL_FIRSTNME_CHAR;
             OR_COL_EDLEVEL       = CF_COL_EDLEVEL;
 
             IF FF_ROW_NUM > 10 THEN
             DO;
               MSG_TEXT_1 = 'Please press return to continue!' ;
               MSG_TEXT_2 = BLANK ;
               CALL DISP_DATA ;
               FF_ROW_NUM = 1;
               PAGE_CNT = PAGE_CNT + 1 ;
 
 /*------------------------------------------------------------*/
 /* Setup column headings                                      */
 /*------------------------------------------------------------*/
 
               RSLTNO(FF_ROW_NUM) = 'FirstName    EducLvl' ;
               FF_ROW_NUM         = FF_ROW_NUM + 1 ;
               RSLTNO(FF_ROW_NUM) = '===========  =======' ;
               FF_ROW_NUM         = FF_ROW_NUM + 1 ;
             END ;
 
             RSLTNO(FF_ROW_NUM) = OUTPUT_ROW_STR;
 
           END ; /* end of WHEN( CS_SUCCEED ) */
 
           WHEN( CS_END_DATA )
           DO ;
             NO_MORE_ROWS = TRUE ;
             MSG_TEXT_1   = 'All rows processing completed!' ;
             MSG_TEXT_2   = 'Press Clear To Exit';
             CALL DISP_DATA ;
           END ; /* end of WHEN( CS_END_DATA ) */
 
           WHEN( CS_FAIL )
           DO ;
             NO_MORE_ROWS = TRUE ;
             NO_ERRORS_SW = FALSE ;
             MSGSTR       =
                 'CTBFETCH returned CS_FAIL ret_code' ;
             CALL ERROR_OUT;
           END ; /* end of WHEN( CS_FAIL ) */
 
           WHEN( CS_ROW_FAIL )
           DO ;
             NO_MORE_ROWS = TRUE ;
             NO_ERRORS_SW = FALSE ;
             MSGSTR       =
                 'CTBFETCH returned CS_ROW_FAIL ret_code' ;
             CALL ERROR_OUT;
           END ; /* end of WHEN( CS_ROW_FAIL ) */
 
           WHEN( CS_CANCELLED )
           DO ;
             NO_MORE_ROWS = TRUE ;
             NO_ERRORS_SW = FALSE ;
             MSG1O     = 'CTBFETCH returned CS_CANCELLED ret_code' ;
             CALL ERROR_OUT;
           END ; /* end of WHEN( CS_CANCELLED ) */
		OTHERWISE
           DO ;
             NO_MORE_ROWS = TRUE ;
             NO_ERRORS_SW = FALSE ;
             MSGSTR       =
                 'CTBFETCH returned Unknown ret_code' ;
             CALL ERROR_OUT;
           END ; /* end of OTHERWISE */
END ; /* end of SELECT( CSL_RC ) */
END FETCH_ROW_PROCESSING ;

Usage


Fetching regular rows


Fetching return parameters


Fetching a return status

See also

Related functions: