- 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
What is COBOL host variable equivalent for various DB2 data types?
Problem: How will the COBOL-DB2 program behave when there is a mismatch between the host variable and number of columns in the SELECT statement?
Solution
In case there is a mismatch in the number of columns and number of host variables, the query will fail. For example, if we have used the below query in a COBOL-DB2 program which processes the ORDERS DB2 table.
Example
EXEC SQL SELECT ORDER_ID, ORDER_AMOUNT, ORDER_DATE, ORDER_STATUS INTO :WS-ORDER-ID, :WS-ORDER-AMOUNT, :WS-ORDER-DATE, FROM ORDERS WHERE ORDER_DATE = ‘2020-09-15’ END-EXEC
There is a mismatch in the number of columns and host variables. There are a total 4 columns used in the SELECT statement and for them only 3 host variables are used. In this case the query will fail and there are two ways in which we can detect this condition.
- The SQLWARN3 field of SQLCA will get the value as ‘W’ in case there is a mismatch.
- In some installations the SQLCODE field for SQLCA gets the error code as -804 when there is a mismatch.
We can use IF condition to check the value in SQLWARN3 or SQLCODE and direct the program processing accordingly.
Following is an example.
Example
IF SQLWARN3 = ‘W’ PERFORM X00-ABEND-SECTION ELSE PERFORM A100-SELECT-RESULT END-IF
- Related Articles
- What are the COBOL host variable equivalent for various DB2 data types?
- Convert DECIMAL(7,3) into equivalent COBOL host variable PIC form.
- What are the default values used by DB2 for various data types?
- What are COBOL equivalents of DB2 data types SMALLINT, INTEGER and DECIMAL?
- What are COBOL equivalents of DB2 data types CHAR, DATE, TIME and TIMESTAMP?
- What is the usage and purpose of DCLGEN and host variables used in COBOL-DB2 program
- How to truncate trapping of a DB2 column data when assigned to a host variable
- How will the COBOL-DB2 program behave when there is a mismatch between the host variable and number of columns in the SELECT statement?
- How does DCLGEN utility accommodate NULL host variable for VARCHAR(n) data type?
- What is the purpose and usage of “FOR UPDATE OF” clause in a COBOL-DB2 program
- How to verify NULL value in DB2 column data using COBOL paragraph?
- What are various Text data types in Python pandas?
- How to precompile a COBOL-DB2 program?
- What are the various techniques for data extraction?
- How to use SQLCA in a COBOL-DB2 program? What is the purpose of SQLCA?
