
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Common Error Trapping Logic for SQL Statements in Programming
A COBOL-DB2 program can have multiple DB2 SQL statements. In order to implement the common error-trapping for all the SQL statements in a COBOL-DB2 program, we will use WHENEVER statement.
The WHENEVER statement can direct the control to the error handling section or routine based on the value returned in SQLCODE field of SQLCA. For example, we can declare WHENEVER statement in COBOL-DB2 program as below−
EXEC SQL WHENEVER SQLERROR GOTO ERROR-ROUTINE END-EXEC
In the above example, the SQLERROR parameter will be set only when the value of SQLCODE will be lesser than zero, which indicates that there was some error occurred while executing the query. In that case, the control will be transferred to the ERRORROUTINE paragraph of the program.
Advertisements