Your application initiates an RPC command by calling ct_command with type as CS_RPC_CMD, *buffer as the procedure name, and option as CS_NO_RECOMPILE, CS_RECOMPILE, or CS_UNUSED. For example:
ct_command(cmd, CS_RPC_CMD, rpc_name, CS_NULLTERM, CS_NO_RECOMPILE)
The option value indicates whether the server should recompile the procedure. When invoking an Adaptive Server Enterprise stored procedure, CS_RECOMPILE is equivalent to specifying the with recompile clause in an equivalent execute statement. See the Adaptive Server Enterprise documentation for an explanation of when recompilation is useful.
Parameter values for an RPC command are passed with calls to ct_param or ct_setparam. These routines are identical, except that ct_param copies a data value, while ct_setparam copies pointers to data values. Both routines require a CS_DATAFMT structure, an indicator variable, and the address of a data value. See the reference pages for ct_param and ct_setparam in the Open Client Client-Library/C Reference Manual.
For RPC commands, code your ct_param or ct_setparam calls according to the following rules:
Pass parameter values in a datatype that matches the declaration of the parameter in the stored procedure.
Client-Library does not convert outgoing parameter values. If necessary, use cs_convert to convert the parameter value into the matching datatype.
Pass all parameters by name or all parameters by position.
To pass a parameter by name, copy its name into the name field of ct_param’s or ct_setparam’s datafmt parameter, and set datafmt.length to match. Parameters for which you do not call ct_param or ct_setparam are effectively passed as NULL.
To pass parameters by position, set datafmt.length to 0 and call ct_param or ct_setparam in the order in which the parameters appear in the procedure’s definition. To pass a parameter as NULL, set the associated indicator variable to -1.
All parameters must be passed using the same method. RPC commands that pass parameters by position usually perform better than those that pass parameters by name.
Set datafmt.status to indicate whether the parameter is a return parameter.
CS_RETURN indicates a return parameter; use CS_INPUTVALUE for non-return parameters.
Return parameters are similar to the “pass by reference” facility offered by some programming languages. The value of the parameter, with any changes made by the procedure code, is available to the client application after the procedure completes execution. See “Return parameter values”.
Use ct_setparam rather than ct_param when the command will be sent multiple times with varying parameter values.
ct_setparam binds a parameter source variable to the initiated command, allowing the application to change the parameter’s value between calls to ct_send.
For an example that illustrates how to define an RPC command with parameters, see the reference page for ct_param in the Open Client Client-Library/C Reference Manual.