- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 the usage and purpose of DCLGEN and host variables used in COBOL-DB2 program
A COBOL-DB2 program can query/update/insert/delete data from multiple DB2 tables. However, in order to achieve this, we must fulfill two main conditions.
Notify the structure of the DB2 table to the COBOL-DB2 program. This includes all the columns and data types of these columns.
The respective host variables for each column. The host variables are used in the program logic to move the data from DB2 to program and vice versa. There is one host variable for every table column based on its data type. For example, for a table column with data type CHAR(2), there should be a host variable with equivalent COBOL data type as PIC X(2).
The DCLGEN utility helps us to generate the table structures and host variables automatically. Using this utility, we just need to give the DB2 table name and it will return the table structure and the host variables in a PDS member. We can simply use this PDS member in our COBOL-DB2 program in the working storage section using the INCLUDE statement as below−
EXEC SQL INCLUDE ORDERD END-EXEC
The ORDERD is a PDS member which is generated using a DCLGEN utility. This will have the structure of the ORDERS table and host variables for all the columns. For example,the columns ORDER_ID and ORDER_DATE with data type as CHAR(30) and TIMESTAMP will have a host variable as ORDER-ID PIC X(30) and ORDER-DATE PIC X(26) respectively.If we want to use this host variable to move the data from DB2 to program, then we can have−
EXEC SQL EXEC SQL SELECT ORDER_DATE INTO :ORDER-DATE, FROM ORDERS WHERE ORDER_ID = :ORDER-ID END-EXEC END-EXEC
- Related Articles
- Purpose and usage of SAVEPOINT in COBOL-DB2 program
- What is the purpose and usage of “WHERE CURRENT OF” clause in a COBOL-DB2 program?
- What is the purpose and usage of “FOR UPDATE OF” clause in a COBOL-DB2 program
- What is the purpose and usage of SQLCODE within the SQLCA in a COBOL-DB2 program
- How will the COBOL-DB2 program behave if the DCLGEN member is not included?
- How to use SQLCA in a COBOL-DB2 program? What is the purpose of SQLCA?
- What is COBOL host variable equivalent for various DB2 data types?
- Purpose and usage of ROW-ID and SEQUENCE in a DB2
- What are the COBOL host variable equivalent for various DB2 data types?
- What is the usage of host variables in case of multi row fetch?
- What is the purpose and usage of SCROLLABLE CURSOR in COBOLDB2 program?
- How will the COBOL-DB2 program behave when there is a mismatch between the host variable and number of columns in the SELECT statement?
- What will happen if a NULL value is detected for a SQL statement in COBOL-DB2 program and the NULL indicator is not used?
- What is the purpose of “NOT NULL WITH DEFAULT” clause used in DB2 table column?
- Impact of database downtime on the COBOL-DB2 program