Agenda.
- Introduction.
 - What is SQLCA?
 - What are the SQLCODE and SQLSTATE fields?
 - How to include SQLCA in COBOL-DB2 program?
 - SQLCA fields description.
 - Important DB2 SQLCODE.
 - Conclusion.
 
Introduction.
What is SQLCA (i.e. SQL Communication Area)?
What are the SQLCODE and SQLSTATE fields?
- If SQLCODE = 0, execution was successful.
 - If SQLCODE > 0, the execution was successful with a warning.
 - If SQLCODE < 0, execution was not successful.
 - If SQLCODE = 100, no data was found.
 
How to include SQLCA in COBOL+DB2 program?
IDENTIFICATION DIVISION.... . .WORKING-STORAGE SECTION....EXEC SQLINCLUDE SQLCAEND-EXEC.EXEC SQL TABLEINCLUDE EMPLYEND-EXEC....
You should declare SQLCODE, SQLSTATE, and SQLCA variables in the WORKING-STORAGE SECTION and in the LINKAGE SECTION of your program. The COBOL precompiler includes the following SQLCA copybook when you use the INCLUDE statement:
DB2 SQLCA Copybook Structure.
01 SQLCA.
   05 SQLCAID          PIC X(8).
   05 SQLCABC          PIC S9(9) COMP-4.
   05 SQLCODE          PIC S9(9) COMP-4.
   05 SQLERRM.
      49 SQLERRML      PIC S9(4) COMP-4.
      49 SQLERRMC      PIC X(70).
   05 SQLERRP          PIC X(8).
   05 SQLERRD    OCCURS 6 TIMES PIC S9(9) COMP-4.
   05 SQLWARN.
      10 SQLWARN0      PIC X(1).
      10 SQLWARN1      PIC X(1).
      10 SQLWARN2      PIC X(1).
      10 SQLWARN3      PIC X(1).
      10 SQLWARN4      PIC X(1).
      10 SQLWARN5      PIC X(1).
      10 SQLWARN6      PIC X(1).
      10 SQLWARN7      PIC X(1).
   05 SQLEXT.
      10 SQLWARN8      PIC X(1).
      10 SQLWARN9      PIC X(1).
      10 SQLWARNA      PIC X(1).
      10 SQLSTATE      PIC X(5).            
Name 
 | 
  
Data Type 
 | 
  
Purpose 
 | 
 
SQLCAID 
 | 
  
CHAR(8) 
 | 
  
An "eye-catcher" for storage dumps containing the text 'SQLCA'. 
 | 
 
SQLCABC 
 | 
  
INTEGER 
 | 
  |
SQLCODE
   
 | 
  
INTEGER 
 | 
  
Contains the
  SQL return code: 0 (successful execution, although there might have been
  warning messages); positive (successful execution, with an exception
  condition); negative (error condition). 
 | 
 
SQLERRML 
 | 
  
SMALLINT 
 | 
  
Length indicator for SQLERRMC, in
  the range 0 through 70: 0 means that the value of SQLERRMC is not pertinent. 
 | 
 
SQLERRMC 
 | 
  
VARCHAR(70) 
 | 
  
Contains one
  or more tokens, separated by X'FF', that are substituted for variables in the
  descriptions of error conditions. 
 | 
 
SQLERRP 
 | 
  
CHAR(8) 
 | 
  
Provides a product signature and,
  in the case of an error, diagnostic information, such as the name of the module that detected the error. In all cases, the first three characters are DSN
  for DB2 for z/OS. 
 | 
 
SQLERRD(1) 
 | 
  
INTEGER 
 | 
  
Contains an
  internal error code. 
 | 
 
SQLERRD(2) 
 | 
  
INTEGER 
 | 
  
Contains an internal error code. 
 | 
 
SQLERRD(3) 
 | 
  
INTEGER 
 | 
  
Contains the
  number of rows affected after INSERT, UPDATE, and DELETE but not rows deleted
  as of a result of CASCADE delete. Set to 0 if the SQL statement fails,
  indicating that all changes made in executing the statement were cancelled.
  Set to 1 for a mass delete from a table in a segmented tablespace. SQLERRD(3)
  can also contain the reason code of a timeout or deadlock for SQLCODES 911
  and 913. 
 | 
 
SQLERRD(4) 
 | 
  
INTEGER 
 | 
  
Generally contains a timer-on, a
  short floating-point value that indicates a rough relative estimate of resources required. It does not reflect an estimate of the time required.  
 | 
 
SQLERRD(5) 
 | 
  
INTEGER 
 | 
  
Contains the
  position or column of a syntax error for a PREPARE or EXECUTE IMMEDIATE
  statement. 
 | 
 
SQLERRD(6) 
 | 
  
INTEGER 
 | 
  
Contains an internal error code. 
 | 
 
SQLWARN0 
 | 
  
CHAR(1) 
 | 
  
Contains a W
  if at least one other indicator also contains a W; otherwise, contains a
  blank. 
 | 
 
SQLWARN1 
 | 
  
CHAR(1) 
 | 
  
Contains a W if the value of a
  string column was truncated when assigned to a host variable. 
 | 
 
SQLWARN2 
 | 
  
CHAR(1) 
 | 
  
Contains a W
  if null values were eliminated from the argument of a column function; not
  necessarily set to W for the MIN function, because its results are not
  dependent on the elimination of null values. 
 | 
 
SQLWARN3 
 | 
  
CHAR(1) 
 | 
  
Contains a W if the number of
  result columns is larger than the number of host variables. Contains a Z if
  fewer locators were provided in the ASSOCIATE LOCATORS statement than the
  stored procedure returned. 
 | 
 
SQLWARN4 
 | 
  
CHAR(1) 
 | 
  
Contains a W
  if a prepared UPDATE or DELETE statement does not include a WHERE clause. 
 | 
 
SQLWARN5 
 | 
  
CHAR(1) 
 | 
  
Contains a W if the SQL statement
  was not executed because it is not a valid SQL statement in DB2 for z/OS. 
 | 
 
SQLWARN6 
 | 
  
CHAR(1) 
 | 
  
Contains a W
  if the addition of a month or year duration to a DATE or TIMESTAMP value
  results in an invalid day, such as June 31. This indicates that the value of the day was changed to the last day of the month to make the result valid. 
 | 
 
SQLWARN7 
 | 
  
CHAR(1) 
 | 
  
Contains a W if one or more
  nonzero digits were eliminated from the fractional part of a number used as
  the operand of a decimal multiply or divide operation. 
 | 
 
SQLWARN8 
 | 
  
CHAR(1) 
 | 
  
Contains a W
  if a character that could not be converted was replaced with a substitute
  character. 
 | 
 
SQLWARN9 
 | 
  
CHAR(1) 
 | 
  
Contains a W if arithmetic
  exceptions were ignored during COUNT DISTINCT processing. Contains a Z if the
  stored procedure returned multiple result sets. 
 | 
 
SQLWARNA 
 | 
  
CHAR(1) 
 | 
  
Contains a W
  if at least one character field of the SQLCA or the SQLDA names or labels is
  invalid because of a character-conversion error. 
 | 
 
SQLSTATE 
 | 
  
CHAR(5) 
 | 
  
Contains a return code for the outcome of the most recent execution of an SQL statement. 
 | 
 
Important SQLCODE list.
- SQLCODE = +0 Successful.
 - SQLCODE = +100 No More Rows.
 - SQLCODE = -805 Package or DBRM issue.
 - SQLCODE = -811 Return Multiple Rows.
 - SQLCODE = -818 Timestamp Mismatch.
 - SQLCODE = -904 Unavailable Resource.
 - SQLCODE = -911 Deadlock or timeout.
 - SQLCODE = -922 Authorization failure.
 - SQLCODE = -501 DB2 Cursor not open.
 - SQLCODE = -305 Missing Null indicator variable.
 - SQLCODE = -805 Duplicate Index.
 
Note: This is not complete list of SQL Error code. We would recommend that you should go through complete list of SQL error code and based on program logic you should handle negative error code in your COBOL-DB2 Program to avoid program abend.


No comments:
Post a Comment