0% found this document useful (0 votes)
9 views

DB2 Session06

The document discusses the process of preparing and executing Cobol programs that use DB2. It covers precompilation, compilation, binding, and execution. It also describes concepts like DBRMs, packages, plans and how errors are handled.

Uploaded by

ritankardey21
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

DB2 Session06

The document discusses the process of preparing and executing Cobol programs that use DB2. It covers precompilation, compilation, binding, and execution. It also describes concepts like DBRMs, packages, plans and how errors are handled.

Uploaded by

ritankardey21
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

DB2 session 6

Cobol and DB2


Program Preparation and Execution

 Pre-compilation
 Compilation
 Linking
 Binding
 Execution

© Strictly confidential 2
Pre-compilation
Involves the following sequence of events.

 Syntax checking of SQL statements embedded in the host language.


 Checking for datatype matches.
 Commenting out the SQL statements and replacing it with equivalent
COBOL CALL statements.
 Creation of DBRM.

© Strictly confidential 3
Binding
 Is the process of generating an application plan/package from a
DBRM.
 Involves the following sequence of events.
◦ Checking syntax of SQL statements.
◦ Verification of authority on DB2 objects.
◦ Optimization of SQL statements to create an application plan.

© Strictly confidential 4
Application plan and package
Package
 Is the executable form of a single DBRM, but is not independently
executable.
 Is bound to an application plan with related packages.
 Only the plan is independently executable.
 If any DBRM is altered, then only the corresponding package needs
re-binding.

Plan
 Is the executable form of one or more DBRMs and application
package.
 Should be generated every time any DBRM is modified.
 Are kept in the buffer pools during program execution.

© Strictly confidential 5
Relationship between DBRM, Package and Plan

PLAN

PACKAGE PACKAGE PACKAGE DBRM

DBRM DBRM DBRM

© Strictly confidential 6
Some Issues related to Binding
 In CICS, every DBRM associated with a transaction
must be put under the same Plan.
 The RCT (Resource Control Table) in CICS maintains TRANSID to
PLAN NAME relationship.
 Good to use packages to avoid long bind time.

© Strictly confidential 7
Source Program
Program Preparation Summary

Precompile Hostvariables DCLGEN


copybook

DBRM
Catalog Tables

BIND Plans & DB


Modified Source
packages Objects
program
Info Info

Packages
Plans
Bufferpool

Compile & Link Load Module Execution


What to do when a new Program in added?
 Create PCT, PPT and RCT entries (for CICS applications)

 Pre-compile

 Translate

 Compile

 Bind

 Install new copies of all the programs

© Strictly confidential 9
Some common SQL codes

0 Successful execution
+100 Row not found or end of records
-811 Multiple rows returned, but not coded
using cursor in application program
-803 Duplicate insertion for unique column
-818 Timestamp mismatch between DBRM and
load module
-911,-913 Deadlock or timeout
-904 Resource not available

+ indicates warning, - indicates error


DB2 error handling…
• As it is difficult to remember what each every SQLCODE
represents, IBM has provided a sub-program called
DSNTIAR to provide more information to the programmer
when his / her program abends with an SQL error.
• How to use DSNTIAR?
• In WORKING STORAGE, declare the following data items:
01 WS-ERR-MSG.
05 WS-ERR-LEN PIC S9(4) COMP VALUE +720.
05 WS-ERR-TXT PIC X(72) OCCURS 10 TIMES
INDEXED BY WS-ERR-INDEX.
77 WS-ERR-TXT-LEN PIC S9(9) COMP VALUE +72.
…DB2 error handling
• In the PROCEDURE DIVISION, in the abend para, code:
CALL ‘DSNTIAR’ USING SQLCA,
WS-ERR-MSG,
WS-ERR-TXT-LEN.
PERFORM VARYING WS-ERR-INDEX FROM 1 BY 1
UNTIL WS-ERR-INDEX = 10
DISPLAY WS-ERR-TXT (WS-ERR-INDEX)
END-PERFORM.
• When DSNTIAR is called (with SQLCA being passed to it),
WS-ERR-MSG (that has an array) will be populated with the
details of the error that SQL encountered.
• To see the details, values in the WS-ERR-TXT data items are
displayed.

You might also like