CTBPARAM

Description

Defines a command parameter.

Syntax

%INCLUDE CTPUBLIC; 
 
 DCL 
     01 COMMAND              FIXED BIN(31) INIT(0); 
     01 RETCODE               FIXED BIN(31) INIT(0); 
     01 DATAFMT, 
         05 FMT_NAME         CHAR(132), 
         05 FMT_NAMELEN  FIXED BIN(31), 
         05 FMT_TYPE          FIXED BIN(31), 
         05 FMT_FORMAT     FIXED BIN(31), 
         05 FMT_MAXLEN     FIXED BIN(31), 
         05 FMT_SCALE        FIXED BIN(31), 
         05 FMT_PRECIS      FIXED BIN(31), 
         05 FMT_STATUS      FIXED BIN(31), 
         05 FMT_COUNT       FIXED BIN(31), 
         05 FMT_UTYPE        FIXED BIN(31), 
         05 FMT_LOCALE      FIXED BIN(31); 
     01 DATA           type; 
     01 DATALEN                 FIXED BIN(31); 
     01 INDICATOR              FIXED BIN(15) INIT(0); 
 
CALL CTBBIND (COMMAND, RETCODE, DATAFMT, DATA, DATALEN, INDICATOR);

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.

DATAFMT

(I) A structure that contains a description of the parameter. This structure is also used by CTBBIND, CTBDESCRIBE and CSBCONVERT and is explained in “DATAFMT structure”.

Table 3-13 lists the fields in the DATAFMT structure, indicates whether or when they are used by CTBPARAM, and contains general information about the fields.

NoteThe programmer is responsible for adhering to these rules. Client-Library does not enforce them.

Table 3-13: Fields in the DATAFMT structure for CTBPARAM

When this field

Is used in this condition

Set the field to

FMT_NAME

When defining parameters for all supported commands.

The name of the parameter being defined.

If FMT_NAMELEN is 0, the parameter is considered to be unnamed. Unnamed parameters are interpreted positionally. It is an error to mix named and unnamed parameters in a single command.

NoteWhen sending parameters to an Adaptive Server, FMT_NAME must begin with the “@” symbol, which prefixes all Adaptive Server stored procedure parameter names.

When sending parameters with language requests, this must be the variable name as it appears in the language string. Transact-SQL names begin with the colon (:) symbol.

FMT_NAMELEN

When defining parameters for all supported commands.

The length, in bytes, of FMT_NAME.

If FMT_NAMELEN is 0, the parameter is considered to be unnamed.

FMT_TYPE

When defining parameters for all supported commands.

The datatype of the parameter value. All datatypes listed under “Datatypes” are valid.

FMT_FORMAT

Not used (CS_FMT_UNUSED).

Not applicable.

FMT_MAXLEN

When defining non-fixed-length return parameters for RPCs; otherwise CS_UNUSED.

The maximum length, in bytes, of the data returned in this parameter.

For character or binary data, FMT_MAXLEN must represent the total length of the return parameter, including any space required for special terminating bytes, with this exception: when the parameter is a VARYCHAR datatype such as the DB2 VARCHAR, FMT_MAXLEN does not include the length of the “LL” length specification.

For Sybase-decimal and Sybase-numeric, set FMT_MAXLEN to 35.

If the parameter is non-return, if FMT_TYPE is fixed-length, or if the application does not need to restrict the length of return parameters, set FMT_MAXLEN to CS_UNUSED.

FMT_SCALE

Used for packed decimal, Sybase-decimal, and Sybase-numeric datatypes.

The number of digits after the decimal point.

FMT_PRECIS

Used for packed decimal, Sybase-decimal, and Sybase-numeric datatypes.

The total number of digits before and after the decimal point.

FMT_STATUS

When defining parameters for all types of commands except message commands.

The type of parameter being defined. One of the following values:

  • CS_INPUTVALUE - The parameter is an input parameter value for a non-return RPC parameter or a language request parameter.

  • CS_RETURN - The parameter is a return parameter.

FMT_COUNT

Not used (CS_FMT_UNUSED).

Not applicable.

FMT_UTYPE

Only when defining a parameter that has an Adaptive Server user-defined datatype; otherwise CS_UNUSED.

The user-defined datatype of the parameter, if any. FMT_UTYPE is set in addition to (not instead of) DATATYPE.

NoteThis field is used for datatypes defined at the server, not for Open Client user-defined datatypes.

FMT_LOCALE

Not used (CS_FMT_UNUSED).

Zeroes.

DATA

Variable that contains the parameter data.

To indicate a null parameter (zeroes), assign INDICATOR a value of -1.

If INDICATOR is -1, DATA and DATA_LEN are ignored. For example, an application might pass empty parameters to a stored procedure or transaction that assigns default values to empty input parameters.

DATA_LEN

The length, in bytes, of the parameter data. For Sybase-numeric and Sybase-decimal, set DATA_LEN to 35.

INDICATOR

An integer variable used to indicate an empty parameter. To indicate that a parameter is empty, assign INDICATOR a value of -1. If INDICATOR is -1, DATA and DATA_LEN are ignored.

Returns

CTBPARAM returns one of the following values:

Value

Meaning

CS_SUCCEED (-1)

The routine completed successfully.

CS_FAIL (-2)

The routine failed.

Examples

Example 1

The following code fragment illustrates the use of CTBPARAM. It is taken from the sample program SYCTSAR4 in Appendix B, “Sample RPC Application.”

 /*------------------------------------------------------------*/
 /* prepare the command (an RPC request)                       */
 /*------------------------------------------------------------*/
         PF_STRLEN = STG(CF_CMD);
 
         CALL CTBCOMMA( CSL_CMD_HANDLE,
                        CSL_RC,
                        CS_RPC_CMD,
                        CF_CMD,
                        PF_STRLEN,
                        CS_UNUSED );
 
         IF CSL_RC ^= CS_SUCCEED THEN
         DO ;
           NO_ERRORS_SW = FALSE ;
           MSGSTR       = 'CTBCOMMAND failed' ;
           CALL ERROR_OUT;
           CALL ALL_DONE ;
         END ;

/*------------------------------------------------------------*/
/*                                                            */
/* setup a return parameter for NUM_OF_ROWS                   */
/*                                                            */
/* describe the first parameter (NUM_OF_ROWS)                 */
/*                                                            */
/*------------------------------------------------------------*/
 
         DF_NAME         = '@parm1';
         DF_NAMELEN      = 6;
         DF_DATATYPE     = CS_INT_TYPE;
         DF_FORMAT       = CS_FMT_UNUSED;
         DF_MAXLENGTH    = CS_UNUSED;
         DF_STATUS       = CS_RETURN;
         DF_USERTYPE     = CS_UNUSED;
 
         PM_LEN          = STG(PM_PARAM1);
         PM_PARAM1       = 0;                   /* NUM_OF_ROWS */
         PM_NULLIND      = 0;
 
         CALL CTBPARAM( CSL_CMD_HANDLE,
                        CSL_RC,
                        DATAFMT,
                        PM_PARAM1,
                        PM_LEN,
                        PM_NULLIND );
 
         IF CSL_RC ^= CS_SUCCEED THEN
         DO ;
           NO_ERRORS_SW = FALSE ;
           MSGSTR       =
             'CTBPARAM CS_INT_TYPE parm1 failed' ;
           CALL ERROR_OUT;
           CALL ALL_DONE ;
         END ;
 
 /*------------------------------------------------------------*/
 /*                                                            */
 /* describe the second parameter (DEPTNO)                     */
 /*                                                            */
 /*------------------------------------------------------------*/
 
         DF_NAME         = '@parm2';
         DF_NAMELEN      = 6;
         DF_DATATYPE     = CS_VARCHAR_TYPE;
         DF_FORMAT       = CS_FMT_UNUSED;
         DF_MAXLENGTH    = CS_UNUSED;
         DF_STATUS       = CS_INPUTVALUE;
         DF_USERTYPE     = CS_UNUSED;
 
         PM_PARAM2       = PF_DEPT;                  /* DEPTNO */
         PM_LEN          = PF_DEPT_SIZE ;
         PM_NULLIND      = 0;
 
         CALL CTBPARAM( CSL_CMD_HANDLE,
                        CSL_RC,
                        DATAFMT,
                        PM_PARAM2,
                        PM_LEN,
                        PM_NULLIND );
 
         IF CSL_RC ^= CS_SUCCEED THEN
         DO ;
           NO_ERRORS_SW = FALSE ;
           MSGSTR       =
             'CTBPARAM CS_VARCHAR_TYPE parm2 failed' ;
           CALL ERROR_OUT;
           CALL ALL_DONE ;
         END ;
 
 /*------------------------------------------------------------*/
 /* send the command                                           */
 /*------------------------------------------------------------*/
 
         CALL CTBSEND( CSL_CMD_HANDLE,
                       CSL_RC ) ;
 
         IF CSL_RC ^= CS_SUCCEED THEN
         DO ;
           MSGSTR       = 'CTBSEND failed' ;
           NO_ERRORS_SW = FALSE ;
           CALL ERROR_OUT;
           CALL ALL_DONE ;
         END ;
 
 END SEND_PARAM ;

Usage


Defining arguments for language requests


Defining arguments for RPCs

Table 3-16 lists a summary of CTBPARAM arguments.

Table 3-16: Summary of arguments (CTBPARAM)

Command

FMT_STATUS value

DATA, DATA_LEN value

Language request

CS_INPUTVALUE

The parameter value and length.

RPC (return parameters)

CS_RETURN

The parameter value and length.

RPC (non-return parameters)

CS_INPUTVALUE

The parameter value and length.

See also

Related functions:

Related topics: