Previous Topic: Performance ConsiderationsNext Topic: SQL Error Messages Related to Procedures and Triggers


Parameter Styles and Error Handling

The PARAMETER STYLE clause of the CREATE PROCEDURE statement defines how parameters are passed between an application program, or a trigger, and the procedure that is being called. How errors are handled also depends upon the parameter style chosen.

GENERAL

This parameter style specifies that the user parameter list is passed to the procedure devoid of null indicators (nulls are not allowed). Since no formal method is provided for passing error information back to the caller, the success or failure of the CALL procedure statement is determined by the contents of the SQL internal SQLCODE variable following the last SQL request made by the procedure. This also applies to parameter style GENERAL WITH NULLS.

GENERAL WITH NULLS

This parameter style differs from GENERAL only in that a null indicator is passed to the procedure for each user parameter.

DATACOM SQL

This parameter style passes nulls to the procedure as does GENERAL WITH NULLS and SQL, but it also passes some additional parameters. These parameters are modeled after those passed for the ANSI SQL3 parameter style SQL, but with this difference: instead of a SQLSTATE, DATACOM SQL passes an SQLCODE in the corresponding parameter.

Following are the additional parameters for parameter style DATACOM SQL (the first four are modeled after SQL3):

The logic inside SQL for parameter style DATACOM SQL is as follows:

When SQL gains control after a successful execution of the procedure, that is, after the procedure code loaded, ran, and did not abend, the internal SQL code and error message are reset to the values returned in the user's parameter list, regardless of whether it was triggered or called, even if this means a non-zero SQLCODE becomes zero or is replaced.

In order to minimize the confusion that a newly-defined trigger can cause for a pre-existing application that uses the navigational (record-at-a-time) API rather than SQL, we handle the DB return codes for DATACOM SQL style procedures as follows.

If the SQLCODE returned from the procedure is zero or positive, a non-blank CA Datacom/DB return code is ignored. If the procedure returned a negative SQLCODE and was explicitly called (as opposed to being triggered), the CA Datacom/DB external and internal return codes are reset to the values returned through the procedure's parameter list. If the procedure returned a negative SQLCODE and was triggered, we store the SQLCODE at offset 26 decimal (signed binary fullword) into the user's Request Area, force the CA Datacom/DB return code(s) to 94(100), then document the CA Datacom/DB return codes returned from the procedure at offsets 30 decimal (2 byte character) and 32 decimal (one byte unsigned binary) into the user's Request Area for the external and internal return codes, respectively. This is done to allow users of navigational programs to differentiate between failures inside procedures and those related to their specific CA Datacom/DB requests, because they generally do not have logic to interpret an SQLCODE.

You have complete control (and responsibility) in deciding whether what occurs constitutes a success. You must set the SQLCODE and error message parameters on exit in one of these three ways:

SQL

When a procedure is created using PARAMETER STYLE DATACOM SQL in the CREATE PROCEDURE statement, the SQLSTATE status indicator is returned in the SQLCA. For detailed information about the SQLSTATE status indicator, see SQL States.

Parameter style SQL passes nulls to the procedure as does GENERAL WITH NULLS and DATACOM SQL. It also passes these additional four parameters that are added to the end of the parameter/null indicator list:

Unlike style DATACOM SQL, the CA Datacom/DB external and internal return codes are not a part of this parameter list but are encoded in the generated SQLSTATE value. For example, the SQLSTATE that equates to SQL return code -117 is Seeii, and the SQLSTATE that equates to SQL return code -118 is Reeii, where ee represents the 2-byte external CA Datacom/DB return code, and ii is the CA Datacom/DB internal return code in hexadecimal characters.

As an aid in understanding error recovery for procedures, note the following: