CTBRESULTS

Description

Sets up result data to be processed.

Syntax

%INCLUDE CTPUBLIC;
DCL
     01 COMMAND        FIXED BIN(31) INIT(0);
     01 RETCODE         FIXED BIN(31) INIT(0);
     01 RESULT_TYP    FIXED BIN(31);
 CALL CTBRESUL (COMMAND, RETCODE, RESULT_TYP);

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 “Returns,” in this section.

RESULT_TYP

(O) Variable containing the result type. CTBRESULTS returns to this variable a symbolic value that indicates the type of result returned by the current request. The result type can be any of the following symbolic values listed in Table 3-18.

Table 3-18: Values for RESULT_TYP (for CTBRESULTS)

Value

Meaning

Result produced

CS_ROW_RESULT (4040)

Regular row results arrived.

One or more rows of tabular data.

CS_PARAM_RESULT (4042)

Return parameter results arrived.

A single row of return parameters.

CS_STATUS_RESULT (4043)

Stored procedure return status results arrived.

A single row containing a single status.

CS_CMD_DONE (4046)

The results of the request processed completely.

Not applicable.

CS_CMD_SUCCEED (4047)

A request that returns no data, such as a language request containing an insert statement, processed successfully.

No results.

CS_CMD_FAIL (4048)

The server encountered an error while executing the request. This value can indicate that the connection failed or was terminated.

No results.

Returns

CTBRESULTS returns one of the following values:

Value

Meaning

CS_SUCCEED (-1)

A result set is available for processing.

CS_END_RESULTS (-205)

No more result sets are available for processing.

CS_FAIL (-2)

The routine failed.

CS_CANCELLED (-202)

Results were cancelled.

Examples

Example 1

The following code fragment demonstrates how CTBRESULTS is used to describe a result row for a language request. It is taken from the sample program SYCTSAA4 in Appendix A, “Sample Language Application.”

 /*------------------------------------------------------------------*/
 /*                                                                  */
 /* Subroutine to process the result                                 */
 /*                                                                  */
 /*------------------------------------------------------------------*/
 PROCESS_RESULTS: PROC ;
 
 /*------------------------------------------------------------*/
 /* set up the results data                                    */
 /*------------------------------------------------------------*/
 
         CALL CTBRESUL( CSL_CMD_HANDLE,
                        CSL_RC,
                        RF_TYPE ) ;
 
 /*------------------------------------------------------------*/
 /* determine the outcome of the comand execution              */
 /*------------------------------------------------------------*/
 
         SELECT( CSL_RC ) ;
 
           WHEN( CS_SUCCEED )
           DO ;
 
 /*--------------------------------------------------------------*/
 /* determine the type of result returned by the current request */
 /*--------------------------------------------------------------*/
 
             SELECT( RF_TYPE ) ;
 
 /*------------------------------------------------------------*/
 /* process row results                                        */
 /*------------------------------------------------------------*/
 
               WHEN( CS_ROW_RESULT )
               DO ;
                 CALL RESULT_ROW_PROCESSING ;
                 DO WHILE( ^NO_MORE_ROWS ) ;
                   CALL FETCH_ROW_PROCESSING ;
                 END ;
               END ;
 
 /*------------------------------------------------------------*/
 /* process parameter results --- there should be no parameter */
 /* to process                                                 */
 /*------------------------------------------------------------*/
 
               WHEN( CS_PARAM_RESULT )
               DO ;
                 NO_MORE_ROWS = FALSE ;
               END ;
 
 /*------------------------------------------------------------*/
 /* process status results --- the stored procedure status     */
 /* result will not be processed in this example               */
 /*------------------------------------------------------------*/
 
               WHEN( CS_STATUS_RESULT )
               DO ;
                 NO_MORE_ROWS = FALSE ;
               END ;
 
 /*------------------------------------------------------------*/
 /* print an error message if the server encountered an error  */
 /* while executing the request                                */
 /*------------------------------------------------------------*/
 
               WHEN( CS_CMD_FAIL )
               DO ;
                 NO_ERRORS_SW = FALSE ;
                 MSGSTR       =
                   'CTBRESUL returned CS_CMD-FAIL restype' ;
                 CALL ERROR_OUT ;
               END ;
 
 /*------------------------------------------------------------*/
 /* print a message for successful commands that returned no   */
 /* data( optional )                                           */
 /*------------------------------------------------------------*/
 
               WHEN( CS_CMD_SUCCEED )
               DO ;
                 MSGSTR = 'CTBRESUL returned CS_CMD_SUCCEED restype' ;
               END ;

/*------------------------------------------------------------*/
/* print a message for requests that have been processed      */
/* successfully( optional )                                   */
/*------------------------------------------------------------*/
 
               WHEN( CS_CMD_DONE )
               DO ;
                 MSGSTR = 'CTBRESUL returned CS_CMD_DONE restype' ;
               END ;
 
               OTHERWISE
               DO ;
                 NO_MORE_RESULTS = TRUE ;
                 NO_ERRORS_SW    = FALSE ;
                 MSGSTR          = 'CTBRESUL returned UNKNOWN restype' ;
                 CALL ERROR_OUT ;
 
               END ;
             END ; /* end of SELECT( RF_TYPE ) */
           END ;
 
 /*------------------------------------------------------------*/
 /* print an error message if the CTBRESULTS call failed       */
 /*------------------------------------------------------------*/
 
           WHEN( CS_FAIL )
           DO ;
             NO_MORE_RESULTS = TRUE ;
             NO_ERRORS_SW    = FALSE ;
             MSGSTR          = 'CTBRESUL returned CS_FAIL ret_code' ;
             CALL ERROR_OUT ;
           END ;
 
 /*------------------------------------------------------------*/
 /* drop out of the results loop if no more result sets are    */
 /* available for processing or if the results were cancelled  */
 /*------------------------------------------------------------*/
 
           WHEN( CS_END_RESULTS )
           DO ;
             NO_MORE_RESULTS = TRUE ;
           END ;
 
           WHEN( CS_CANCELLED )
           DO ;
             NO_MORE_RESULTS = TRUE ;
           END ;
 
           OTHERWISE
           DO ;
             NO_MORE_RESULTS = TRUE ;
             NO_ERRORS_SW    = FALSE ;
             MSGSTR          =
                'CTBRESUL returned unknown ret_code' ;
             CALL ERROR_OUT ;
           END ;
         END ; /* end of SELECT( CSL_RC ) */
 
         RF_TYPE = 0 ;
 
 END PROCESS_RESULTS ;

Usage


The CTBRESULTS loop


When are the results of a command completely processed?


Canceling results


CTBRESULTS and stored procedures

See also

Related functions:

Related topics: