COBOL DB2 Tutorial
COBOL DB2 Tutorial
Online Tutorials
MainfameGurukul - Discussion Forum
DRONA SERIES
DB2
COBOL DB2 PROGRAMMING - 1
EMPLYEE
EXEC SQL
DECLARE DSNXXX.EMPLOYEE
www.mainframegurukul.com/tutorials/database/db2_tutorials/cobol-db2-sample-program.html 1/4
3/17/2020 COBOL DB2 Tutorial - SAMPLE PROGRAM - DB2 Application Programming
EXEC SQL
INCLUDE < copybookname >
END-EXEC.
01 EMPOYEE-RECORD.
05 HV-EMPID PIC X(10).
05 HV-EMPNAME PIC X(30).
05 HV-DEPARTMENT PIC X(2).
05 HV-SALARY PIC S9(8)V99 COMP-3.
05 HV-DESIGNATION PIC CHAR(4).
If you use db2 tool DCLGEN, it will automatically creates this structure also
along with table declaration specified in step1.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
What is SQLCA?
www.mainframegurukul.com/tutorials/database/db2_tutorials/cobol-db2-sample-program.html 2/4
3/17/2020 COBOL DB2 Tutorial - SAMPLE PROGRAM - DB2 Application Programming
STEP 4. Add a sql statement in procdure division to get the details of employee
with the name XXXXXXX.
.........
EXEC SQL
SELECT SALARY
INTO :HV-SALARY
FROM EMPLOYEE
WHERE EMPNAME = 'XXXXXXX'
END-EXEC.
IF SQLCODE = 0
ELSE
END-IF.
....
....
www.mainframegurukul.com/tutorials/database/db2_tutorials/cobol-db2-sample-program.html 3/4
3/17/2020 COBOL DB2 Tutorial - SAMPLE PROGRAM - DB2 Application Programming
Here SQLCODE = 0 means, sql ran sucessfully without any issues. Hence
we are displaying the HV-SALARY into the spool.
Click here to see the compile JCL. Use this compile jcl to compile the program.
Home | Donations | Online Tutorials | Books | Entertainment | Contactme | privacy | sql tutorial | db2 interview questions | simple jcl
tutorial | DB2 INTERVIEW QUESTIONS | JCL INTERVIEW QUESTIONS
www.mainframegurukul.com/tutorials/database/db2_tutorials/cobol-db2-sample-program.html 4/4