IBM DB2 Computer Accessories User Manual


 
Chapter 5. Deploying pre-configured databases 225
exit 8;;
esac
Example A:
In this example we check explicitly for return code 4, which corresponds to a
DB2 error or an SQL error. Remember that the return code from the
command line processor is a logical or of the return codes from each
statement in the file. This means that the return code other than 4, such as
warning 6, will not be caught.
Example B:
This example checks for a return code greater than or equal to 4. In this case
we will capture the DB2 error or SQL error along with any warnings. However,
we are not able to distinguish between a DB2/SQL error and a system error
identified by a return code of 8.
Example C:
In this example we distinguishes between system errors and DB2/SQL errors,
and consider any return code less than 4 as a success. This example also
sets the exit code for the script.
For simplicity purposes, we use example B in the examples throughout this
chapter. That is, we will not distinguish between a system error and a DB2/SQL
error.
Windows script
On Windows, before invoking the command line processor, the DB2 environment
must be initialized. On way to initialize the DB2 environment is by invoking the
script from a DB2 command window. From DB2 version 9, you can initialize the
environment by setting the DB2CLP environment variable to **$$**. You can
either do it before you call the script or you can set the environment variable in
the script before any calls to DB2.
The return code from the command line processor is stored in the environment
variable errorlevel. You can check the value of this environment variable after the
call to the command line processor using an if statement as shown in
Example 5-8.
Note: Setting the environment variable DB2CLP=**$$** is only supported in
DB2 version 9 and later. For earlier versions, you have to use the DB2
command window.