Wednesday, June 17, 2009

(Tutorial : SQL) SQLCODE Error Handling

SQLCODE (SQLCOD) contains return code
- = 0 Successful statement execution
- > 0 Successful, with warning condition
- < 0 Unsuccessful - statement failed

SQLCODE value indicates exact error or condition
- e.g.. 100 = Row not found (or end of file)
- e.g.. -552 = Not authorized to object

SQLCODE values have corresponding messages
- e.g.. SQL0100 = Row not found
-e.g.. SQL0552 = Not authorized to &1.

Sample:

C/EXEC SQL
C+ SELECT name INTO :nam
C+ WHERE emp = :number
C/END-EXEC
C If SQLCod < 0
C ExSr Error
C EndIf
C If SQLCod = 100
C ExSr NotFound
C EndIf

WHENEVER Error Handling

WHENEVER statement checks SQLCA
- can branch to a location based on condition
Three conditions:
a. SQLWARNING (SQLCODE > 0 except 100)
- OR (SQLWARN0 = 'W')
b. SQLERROR (SQLCODE < 0)
c. NOT FOUND (SQLCODE = 100)
Two possible actions - neither very good!
a. CONTINUE
b. GO TO label

Sample:

C/EXEC SQL
C+
C+ WHENEVER SQLERROR GO TO err
C+
C/END-EXEC


You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial


No comments:

Post a Comment