- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to truncate trapping of a DB2 column data when assigned to a host variable
There are situations in which DCLGEN members are not used and the host variables declarations are done explicitly in the working storage section. However, due to these explicit declarations there are chances of human errors. One such error is declaring incorrect data length of COBOL equivalent host variables.
For example, the host variable should have been declared as PIC X(24) but it was declared as PIC X(14) by mistake. In this case when the data transfer takes place from DB2 to COBOL program, the column data might get truncated due to the shorter length of the receiving host variable.
We can detect such situations using SQLWARN1 field of SQLCA. The SQLWARN1 is 1 byte field which contains the value ‘W’ if there is any truncation while data transfer. We can make use of this field as below.
A010-CHECK-ORDER. EXEC SQL SELECT ORDER_DATE INTO :ORDER-DATE, FROM ORDERS WHERE ORDER_ID = :ORDER-ID END-EXEC EVALUATE SQLWARN1 WHEN ‘W’ DISPLAY ‘THE ORDER DATE WAS TRUNCATED’ WHEN OTHER DISPLAY ‘ORDER DATE IS ‘ ORDER-DATE