Академический Документы
Профессиональный Документы
Культура Документы
Basic Programming
B
Database Overview
DB2 Database
SQL Programming Language
SQL Tools: SPUFI / Platinum Interactive SQL
COBOL DB2 Programming
References
Questions
Recap
Exercises
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
2
1405002 rev 6.27.14
Database Overview
What is 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.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
3
1405002 rev 6.27.14
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
4
1405002 rev 6.27.14
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
5
1405002 rev 6.27.14
• Index(es)
an ordered set of pointers to rows of a table (ensures uniqueness) and it is
stored separately from the table.
• Keys
One or more columns that are identified as such in the creation of a table
or used for referential integrity
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
6
1405002 rev 6.27.14
• View
Is an alternative way of representing data that exists in one or more tables.
A view can include all or some of the columns from one or more base
tables.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
7
1405002 rev 6.27.14
DB2 - Database
DB2 Data Types
At the time DB2 table is created, each “column” correspond to a Data type.
String Data Type - support the character, graphic and binary string
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
8
1405002 rev 6.27.14
DB2 - Database
DB2 Data Types…
Numeric Data Type - use numeric columns rather than the string columns –
requires less space than string.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
9
1405002 rev 6.27.14
What is SQL?
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
10
1405002 rev 6.27.14
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
11
1405002 rev 6.27.14
RDBMS
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
12
1405002 rev 6.27.14
Database Tables
A database most often contains one or more tables. Each
table is identified by a name. Tables contain records (rows)
with data.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
13
1405002 rev 6.27.14
SQL Statements
Example:
SELECT FIRST_NAME FROM PERSONS;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
14
1405002 rev 6.27.14
SQL Commands
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
15
1405002 rev 6.27.14
Syntax:
SELECT * FROM table_name;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
16
1405002 rev 6.27.14
Syntax:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
17
1405002 rev 6.27.14
Syntax:
INSERT INTO table_name
VALUES (value1,value2,value3,...);
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
18
1405002 rev 6.27.14
Syntax:
DELETE FROM table_name
WHERE some_column=some_value;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
19
1405002 rev 6.27.14
Syntax:
SELECT column_name,column_name
FROM table_name
WHERE column_name = operator value;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
20
1405002 rev 6.27.14
Syntax:
SELECT column_name,column_name
FROM table_name
WHERE column_name1 = operator value
AND column name2 = operator value;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
21
1405002 rev 6.27.14
Syntax:
SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
22
1405002 rev 6.27.14
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
23
1405002 rev 6.27.14
Navigation
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
24
1405002 rev 6.27.14
Platinum
To run queries here, select Interactive SQL (I).
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
25
1405002 rev 6.27.14
Platinum
To enter a query, Select Edit SQL (E).
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
26
1405002 rev 6.27.14
Platinum
Type in the query you need to be executed.
Then go back (PF3)
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
27
1405002 rev 6.27.14
Note: For insert/update/delete, make sure the Commit is selected if you want to keep the changes.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
28
1405002 rev 6.27.14
SPUFI
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
29
1405002 rev 6.27.14
SPUFI
• Enter a Data Set name that will serve as the Input data.
• Enter another Data Set name that will serve as the Output data.
• Press ENTER.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
30
1405002 rev 6.27.14
SPUFI
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
31
1405002 rev 6.27.14
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
32
1405002 rev 6.27.14
• Table Declaration
• Host Variables
• DCLGEN
• SQLCA
• Embedded SQL
• Cursors
• Common SQL Codes
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
33
1405002 rev 6.27.14
Table Declaration
Your COBOL program should declare the tables and views that it accesses.
This needs to be declared in the WORKING-STORAGE section or LINKAGE
section.
Example:
EXEC SQL
DECLARE DSNXXX.EMPLOYEE
( EMPID CHAR(10) NOT NULL,
EMPNAME CHAR(30) NOT NULL,
DEPARTMENT CHAR(2) NOT NULL,
SALARY DECIMAL(10,2) NOT NULL,
DESIGNATION CHAR(4) NOT NULL )
END-EXEC.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
34
1405002 rev 6.27.14
Host Variables
• are used for receiving data from a table or inserting data in a table. Host
variables must be declared for all values that are to be passed between the
program and the DB2. They are declared in the Working-Storage Section.
• cannot be group items, but they may be grouped together in host structure.
They cannot be Renamed or Redefined. Using host variables with SQL
statements, prefix them with a colon (:)
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
35
1405002 rev 6.27.14
Following is the syntax to declare host variables and include tables in Working-
Storage section:
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
36
1405002 rev 6.27.14
Your COBOL program should declare the tables and views that it accesses.
However, you can use DCLGEN to produce these declarations, so that you do
not need to code the statements yourself. DCLGEN also generates
corresponding host variable structures.
Syntax:
EXEC SQL
INCLUDE < copybookname >
END-EXEC.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
37
1405002 rev 6.27.14
SQLCA
• SQLCA is a SQL communication area through which DB2 passes the feedback
of SQL execution to the program. It tells the program whether an execution
was successful or not. There are a number of predefined variables under
SQLCA like SQLCODE which contains the error code. The value '000' in
SQLCODE states a successful execution.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
38
1405002 rev 6.27.14
SQLCA Syntax
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
39
1405002 rev 6.27.14
Embedded SQL statements work like normal SQL statements with some minor
changes. For example, that output of a query is directed to a predefined set of
variables which are referred as Host Variables. An additional INTO clause is
placed in the SELECT statement.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
40
1405002 rev 6.27.14
• All the SQL statements must be delimited between EXEC SQL and END-
EXEC.
• SQL statements must be coded in Area B.
• All the tables that are used in a program must be declared in the Working-
Storage Section. This is done by using the INCLUDE statement.
• All SQL statements other than INCLUDE and DECLARE TABLE must appear
in the Procedure Division
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
41
1405002 rev 6.27.14
Cursors
Cursors are used to handle multiple row selections at a time. They are
data structures that hold all the results of a query. They can be defined in
the Working-Storage Section or the Procedure Division.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
42
1405002 rev 6.27.14
Cursors - DECLARE
Syntax:
EXEC SQL
DECLARE STUDCUR CURSOR FOR
SELECT STUDENT-ID, STUDENT-NAME, STUDENT-ADDRESS
FROM STUDENT
WHERE STUDENT-ID >:WS-STUDENT-ID
END-EXEC.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
43
1405002 rev 6.27.14
Cursors - OPEN
Syntax:
EXEC SQL
OPEN STUDCUR
END-EXEC.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
44
1405002 rev 6.27.14
Cursors - FETCH
Fetch statement identifies the cursor and puts the value in the INTO
clause. A Fetch statement is coded in loop as we get one row at a time.
Syntax:
EXEC SQL
FETCH STUDCUR
INTO :WS-STUDENT-ID
, :WS-STUDENT-NAME
, WS-STUDENT-ADDRESS
END-EXEC.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
45
1405002 rev 6.27.14
Cursors - CLOSE
Syntax:
EXEC SQL
CLOSE STUDCUR
END-EXEC.
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
46
1405002 rev 6.27.14
SQL Codes
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
47
1405002 rev 6.27.14
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
48
1405002 rev 6.27.14
COBOL - Questions ??
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
49
1405002 rev 6.27.14
COBOL - References
List of SQLCODEs
http://www.caliberdt.com/tips/sqlcode.htm
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
50
1405002 rev 6.27.14
COBOL - Exercises
Proprietary information of Ingram Micro Inc. — Do not distribute or duplicate without Ingram Micro's express written permission.
51