Handling SQL error codes in REXX applications

REXX applications can request more information about SQL error codes by using the DSNTIAR subroutine or issuing a GET DIAGNOSTICS statement.

Procedure

Db2 does not support the SQL WHENEVER statement in a REXX program. To handle SQL errors and warnings, use the following methods:

  • To test for SQL errors or warnings, test the SQLCODE or SQLSTATE value and the SQLWARN. values after each EXECSQL call. This method does not detect errors in the REXX interface to Db2.
  • To test for SQL errors or warnings or errors or warnings from the REXX interface to Db2, test the REXX RC variable after each EXECSQL call.
    The following table lists the values of the RC variable.
    Table 1. REXX return codes after SQL statements
    Return code Meaning
    0 No SQL warning or error occurred.
    +1 An SQL warning occurred.
    -1 An SQL error occurred.
    -3 The first token after ADDRESS DSNREXX is in error. For a description of the tokens allowed, see Accessing the Db2 REXX language support application programming interfaces.

    You can also use the REXX SIGNAL ON ERROR and SIGNAL ON FAILURE keyword instructions to detect negative values of the RC variable and transfer control to an error routine.