Chapter objectives
Be able to:
Explain how databases are used in a
typical online business.
Describe two models for network
connectivity for large systems.
Compose simple SQL queries to run
on z/OS.
Give an overview of application
programming with DB2.
2
Key terms in this chapter
Database
DBMS
SPUFI
QMF
SQL
Plan, Package
View
3
What is a database?
A database provides for the storing and
control of business information, independent
from (but not separate from the processing
requirements of) one or more applications.
4
Entities
Database example
Shipment
Shipment No
entity
Customer
Customer No
Customer Order
Order No
Attributes
Relationships
Dispatch Shipment Customer Customer Quantity
Date to Customer Address Orders Parts Delivery
Note: An attribute is always dependent on
Address an entity – it has no meaning by itself
Order for Part
Part
one-to-one
Part No Relationships {
one-to-many
many-to-many
Name
Note: Relationships can
Unit Price be recursive
Purchase Order
Purchase of
Part
Attributes Order No
Quantity
5
Databases on z/OS
Hierarchical databases, such as IMS
Relational database management
system (RDBMS), such as DB2
6
Hierarchical DB : Relationships &
Level 1 sequence ROOT
(1)
Level 2 Segment A Segment B Segment C
(2) (7) (9)
Segment D Segment E Segment F Segment G Segment H
Level 3 (3) (4) (8) (10) (12)
Segment I Segment J Segment K
(5) (6) (11)
Level 4
7
Hierarchical data structure
Parent of STOCK
Level 1 (or root)
PART and
PURCHASE ORDER
Level 2 PURCHASE
STOCK
ORDER Child of Part
and
Parent of DETAIL
Child of
Level 3 DETAIL DETAIL
PURCHASE
ORDER
8
Segment types and their
relationshipsRecord 1
PART
Record 2
PART
Record 3
PART
1 2 1
Parent of
DETAIL
STOCK ORDER STOCK ORDER STOCK ORDER
11 11 21 21 31 31
STOCK ORDER
12 22
DETAIL DETAIL DETAIL
Siblings
111 211 311
These are
twins
DETAIL
112
DETAIL is:
All segments are dependents of PART Dependent of ORDER
Dependent of PART
Child of ORDER
Grandchild of PART
9
DB2 – The Relational Database
Relational Structures include:
Database: A logical grouping of data for one or more
applications
Table: A logical structure composed of rows and
columns
Index(es): an ordered set of pointers to rows of a table
(ensures uniqueness)
Keys: One or more columns that are identified as
such in the creation of a table or used for
referential integrity
10
Example of a DB2 Department Table i.e. “[Link]”
At the intersection of every column and row is a
specific data item called a value or more precisely
an atomic value
11
DB2 Table Create and inserting a row (record)
12
Creating a primary key (index)
13
Sample DDL for a DB2 Table/View
VIEW
Table
14
Examples of other Data Definition Language (DDL)
15
DB2 Administration (transactional interfaces)
SQL Processor Using File Input (SPUFI)
A SQL interface through TSO providing a means for a
transactional facility used by DBAs. This requires knowledge of
ISPF and basic PDS.
Pronounced “Spoo Fee”
Query Management Facility (QMF)
Is a tightly integrated, powerful, and reliable tool that performs
query and reporting for DB2. It offers an easy-to-learn, interactive
interface. Users with little or no data processing experience can
easily retrieve, create, update, insert, or delete data that is stored
in DB2.
16
First you need to create the output file (if not existing)
Invoke SQL on z/OS: SPUFI
Select option 1 to enter SPUFI
17
Invoke SQL on z/OS: SPUFI (CONT…)
Enter the input and output dataset, if they are not yet in place.
Change the member of the PDS, if you want to enter a new SQL
Defaults are set to NO from YES.
18
Invoke SQL on z/OS: SPUFI (CONT…)
Enter the SQL statement you want to execute.
Press F3 to return to the previous screen (to execute the SQL).
19
Invoke SQL on z/OS: SPUFI (CONT…)
When you get back to this screen, the “edit input” is put to “*”.
Press ENTER to execute the SQL and to see the output.
20
Invoke SQL on z/OS: SPUFI (CONT…)
F8 brings the rest of the results on your screen
21
Invoke SQL on z/OS: SPUFI (CONT…)
22
Query Management Facility
23
24
25
26
Application Programming: the flow
Source
Program
Modified Precompile DBRM
Source
Compile Include Bind
Member
DCLGEN
Object Package
Module
Linkedit Bind
Load RUN Plan
Module
27
Sample COBOL DB2 program
28
29
SQLCA (SQL communication area)
An SQLCA is a set of variables that may be
updated at the end of the execution of every
SQL statement.
A program that contains executable SQL
statements may provide one, but no more
than one SQLCA (unless a stand-alone
SQLCODE or a stand-alone SQLSTATE
variable is used instead), except in Java™,
where the SQLCA is not applicable.
30
31
COBOL DB2 Pre compilation
process
The DB2 Precompiler splits the program into
two parts: a COBOL and a DB2 part.
The embedded SQL is stripped out of the
program and put into a partitioned data set
(PDS) member, called a DBRM.
Just as the COBOL part has to be compiled,
the DBRM part has to go through BIND
process to create the run-time executable
code for the DB2 portion of the COBOL
program.
32
Plan
A plan is an executable module containing
the access path logic produced by
theDB2 optimizer. It can be composed of one
or more DBRMs and packages. Before
aDB2 for z/OS program (with static SQL) can
be run, it must have a plan associated with
it. Plans are created by the BIND command.
33
Package
A PACKAGE is a single, bound DBRM with
optimized access paths. The DBRM of a single
program is bound into a PACKAGE. To
execute a PACKAGE, it should be included in
the package list of a PLAN. PACKAGEs are
not directly executed, they are only indirectly
executed when the PLAN in which they are
contained executes.
34
Utilities used:
PRECOMPILE – DSNHPC
COMPILATION – IGYCRCTL
LINK EDIT – IEWL
BIND THE DB2 PACKAGE - IKJEFT01
35
Summary
The only way to access the data in DB2 databases is with
SQL.
On the mainframe, SPUFI is a tool used to enter SQL
statements.
The DBRM performs a bind process that determines the
access path and stores this executable SQL code in a
package.
36
Thank you
37
Any Questions!
38