Db2 Mainframes
Db2 Mainframes
DevOps
Jon Sayles, IBM - [email protected]
All rights reserved by IBM – including the right to use these materials for in-house
IDz technical instruction (please contact [email protected] for permission)
The information contained in these materials is provided for informational purposes only, and is
provided AS IS without warranty of any kind, express or implied. IBM shall not be responsible
for any damages arising out of the use of, or otherwise related to, these materials. Nothing
contained in these materials is intended to, nor shall have the effect of, creating any warranties
or representations from IBM or its suppliers or licensors, or altering the terms and conditions of
the applicable license agreement governing the use of IBM software. References in these
materials to IBM products, programs, or services do not imply that they will be available in all
countries in which IBM operates.
This information is based on current IBM product plans and strategy, which are subject to change
by IBM without notice. Product release dates and/or capabilities referenced in these materials
may change at any time at IBM’s sole discretion based on market opportunities or other factors,
and are not intended to be a commitment to future product or feature availability in any way.
IBM, the IBM logo, the on-demand business logo, Rational, the Rational logo, and other IBM
Rational products and services are trademarks or registered trademarks of the International
Business Machines Corporation, in the United States, other countries or both. Other company,
product, or service names may be trademarks or service marks of others.
© IBM Corporation 2
The IDz Workbench Curriculum
▪ Module 1 – IDz Terms, Concepts and Navigation
▪ Module 2 – Editing Your COBOL Programs
▪ Module 3 – Analyzing COBOL Programs
▪ Module 4 – Remote Systems – Connect, Navigate and Search
▪ Module 5 – Remote Systems – Dataset Access and Organization
▪ Module 6 – Remote Systems – ISPF 3.x, Batch Jobs and Batch Job Management
▪ Module 7 – MVS Subprojects – Organizing PDS Members and SCM Checkout
▪ Module 8 - The Data Tools – SQL Code/Test and DB2 Table Access
▪ Module 9 - Debugging z/OS COBOL Applications
Optional Modules
▪ IDz/Endevor Integration Through CARMA
▪ Git for ISPF Developers
▪ Using Local Workstation Projects & Resources
▪ zUnit – Unit Test
▪ Code Coverage – Test quality feature
▪ Code Review – Application quality feature
▪ Menu Manager – Integrate ISPF REXX Execs and CLISTs
▪ Web Services – SOA development
© IBM Corporation 3
Course Overview
▪ Audience
This course is designed for application developers who have
learned or programmed in COBOL, and who need to do z/OS
Traditional Development and Maintenance as well as build
leading-edge applications using COBOL and Rational Developer
for System z.
▪ Prerequisites
This course assumes that the student has a basic
understanding and knowledge of software computing
technologies, and general data processing terms, concepts and
vocabulary, as well as a working knowledge of COBOL and z/OS.
Knowledge of SQL (Structured Query Language) is assumed for
database access is assumed as well.
Basic PC and mouse-driven development skills, terms and
concepts are also assumed.
© IBM Corporation 4
Topic objectives
Notes:
• In this topic you will be connecting to a z/OS - DB2 database. If you wish to connect to the sample
database shown in these slides, please contact IBM to obtain the:
• DDL (Data Definition Language statements, used to define the table schema)
• Extracted data for importing
• There is a setup job – part of the IDz installation process, that binds the Data Tools to the DB2 Catalog.
If you do not see your tables/views/etc. as expected, check that your DBA has run this job
• Final note – this section assumes you have at least a working-knowledge of SQL. If you do not, please
see the next slide for learning-source links.
© IBM Corporation 5
Learning DB2 and SQL
▪ Many (in the thousands of) books exist that do an excellent job teaching SQL.
▪ Additionally, sites exist on the Internet (GOOGLE: “SQL tutorials” – or “Learn SQL”)
for online (and typically free) education.
▪ Note: In order for you to get the above links to work, view the PowerPoint in
Slide Show mode.
© IBM Corporation 6
UNIT The IDz Workbench
Topics:
▪ Connecting to DB2
▪ Understanding DB2 objects and dependencies
▪ Editing and managing DB2 table data
▪ Coding and testing SQL
▪ Data Studio & IDz Integration – Productivity Techniques
▪ Extract/Load and Managing Test Data & Decision Support
▪ Workshops and Appendices
© IBM Corporation 7
Why use IDz’s Data Tools for DB2/SQL Work?
We currently use SPUFI/QMF… Why change?
Two reasons:
1. Productivity:
▪ The IDz Data Tools have vastly superior means of:
– SQL statement testing
– Managing your DB2 table test data
– Full-screen table editing
– Simple data export/import
– Doing DBA tasks
– Understanding your relational data model
▪ Easy access from the IDz Workbench
– The tools are completely integrated into eclipse
© IBM Corporation 10
What can you do with IDz’s DB2/SQL Tools?
The things that you commonly do when developing DB2 applications that
access Tables/Views with SQL:
1. Investigate and analyze your DB2 Data Model:
▪ What are the DB2 "objects"?
▪ How do they relate (what are the dependencies)
2. Modify and manage DB2 Test Data:
▪ Understand what's in your test bed
▪ Add/Change/Delete/Copy/Paste table values
▪ Filter table rows and columns **
3. Code, test, analyze SQL:
▪ Interactive
▪ Reuse SPUFI files
▪ Embedded **
▪ Graphical
▪ Visual Explain **
Other aspects of the data tools that may be "out of scope" for this session:
DBA Utilities
Creating/Deploying/Testing DB2 Stored Procedures
Mass Data and Schema migration
Working with IMS Databases – through the Data Tools
© IBM Corporation 11
** Requires Data Studio
DB2 Data Access Protocol
IDz Client interacts with DB2 resources through a JDBC driver which connects to DB2/zOS
Click Apply
Click OK
© IBM Corporation 15
UNIT The IDz Workbench
Topics:
▪ The Data Perspective and Connecting to DB2
▪ Understanding DB2 objects and dependencies
▪ Editing and managing DB2 table data
▪ Coding and testing SQL
▪ Data Studio & IDz Integration – Productivity Techniques
▪ Extract/Load and Managing Test Data & Decision Support
▪ Workshops and Appendices
© IBM Corporation 16
The Data Source Explorer – Tree Control
Once you're connected, the Data Source Explorer presents
"meta-data" about the database objects accessible
through your connection:
- Databases within the connection – and within the database:
Schemas (the high-level qualifier of the resource owner)
Within each Schema relational object resources
(DBMS-dependent):
▪ Synonyms
▪ Stored Procedures
▪ (if DB2 for z) – Federated Stored Procedures
▪ Tables and the elements of a table and related
objects:
– Column definitions
– Relational constraints (primary and foreign key rules)
© IBM Corporation 19
Exporting Column “Sample Contents”
© IBM Corporation 20
Overview Diagram – 1 of 4
So what can we do with the Data Source Explorer? Let’s start by having a look at our tables and
table relationships (Parent/Child tables associated by defined Primary/Foreign key constraints)
▪ From the Data Source Explorer:
Expand a folder for a database and navigate the schemas:
▪ Right-click a schema select: Add to Overview Diagram
▪ Select the tables, views, synonyms, etc. you wish to see
Notes:
The Overview Diagram
feature is available in IDz
version 7.6.1 and later
© IBM Corporation 21
(Data Model) Overview Diagram – 2 of 4
The Diagram Tool shows all of the tables, views and synonyms selected through our connection as entities, and
their relationships as defined by Primary/Foreign key SQL specifications. This allows us to understand things
like how to join tables, and where data exists in relation to other table values.
▪ We can also use the Diagram Tool to navigate in the Data Source Explorer
Views
Right-click over Results
Select: Synonym
▪ Navigate >
▪ Show in >
▪ Database Explorer
▪ Note the different icons for:
Tables ➔
Tables:
▪ Events, Entrants, Results
▪ Employee
Views:
▪ Race_Report
▪ Local_Referrals
Synonym:
▪ L_R Table relationships
▪ Notes:
If you select a large number of tables this diagram can take some time to materialize
To read the diagram shown here:
▪ Each Entrant and Event can have many Result rows
▪ Race_Report is a relational View based on the Results table
▪ Local_Referrals is a relational View based on the Entrants table
© IBM Corporation 22
(Data Model) Overview Diagram – 3 of 4
By default, the Overview Diagram shows only DB2 object names and their relationships. You might wish
to show additional attributes. To do this:
▪ Select the object
Right-click and select:
▪ Filters > Show/Hide Compartment > <your option>
© IBM Corporation 23
(Data Model) Overview Diagram – Show View/Table Relationships – 4 of 4
Sometimes you need to find out what base tables underlie a particular DB2 View…
▪ Select the View
Right-click and select: Add to Overview Diagram
Click OK
© IBM Corporation 24
Generate Table DDL
You may wish to access/modify/etc. one or more of your DB2 table's DDL. To do this you'll need
the original DDL – which is obtained from: Generate Table DDL
© IBM Corporation 25
UNIT The IDz Workbench
Topics:
▪ The Data Perspective and connecting to DB2
▪ Understanding your DB2 objects and dependencies
▪ Editing and managing DB2 Table Data
▪ Coding and testing SQL
▪ Data Studio & IDz Integration – Productivity Techniques
▪ Extract/Load and Managing Test Data & Decision Support
▪ Workshops and Appendices
© IBM Corporation 26
The Data Source Explorer – Data Context Menu
You can work with relational objects:
View Schemas, Tables, Table Columns, Referential Integrity
Constraints, Indexes, Synonyms, Aliases
Re-Create the SQL data definition language statements
for the relational objects – from the System Catalog
For individual tables:
▪ View the table contents
▪ View column contents (row cardinality)
▪ Edit table values
▪ Extract/Load the table using a comma-delimited file
▪ Perform a DCLGEN operation
© IBM Corporation 27
The Data Source Explorer – Data Context Menu
▪ View Schemas, Tables, Table Columns, Referential Integrity Constraints, Indexes, Synonyms, Aliases
▪ Re-Create the SQL data definition language statements – from the System Catalog
▪ For individual tables:
View the table contents
View column contents (row cardinality)
Edit table values
Extract/Load the table using a comma-delimited file
Perform a DCLGEN operation
© IBM Corporation 28
Sample Table Contents – Read/Only View of a Table's Row Values
When you are testing your SQL statements, it can be helpful to view the
row/column values in your tables. Sample Contents provides this, in a
SQL Results view.
© IBM Corporation 29
Sample Table Contents – “New Select Script”
▪ Instead of Browse Data or
Sample Contents, you can
use New “Select” Script
▪ Press F5 to run the SQL
produced by the tooling
© IBM Corporation 30
Data > Sample Contents – Display Table Values in a Single Column
It can be also useful to view the sample contents of individual columns – for
various reasons:
Applications:
▪ Test data coverage
▪ Testing and debugging values
DBA:
▪ Candidate indexing
▪ SQL performance issues related to data volume
Steps:
▪ Select a table
▪ Expand Columns, and select a column
▪ Right-click Sample Contents of a table column
▪ Select: 1. Discrete column values
Data 2. The number of occurrences found in the
table for each value (Cardinality)
Sample Contents
© IBM Corporation 31
Export SQL Results
Used to save row values in:
HTML
XML
Plain text
XLS (spreadsheet) format
Steps:
From the Result window:
▪ Right-click
▪ Select which rows to export
▪ Select the Export Format
– Browse to the file name
– Be sure to enter the .file extension
▪ Click Finish
© IBM Corporation 33
Table Row Value Edit Options – 2 of 2
The table editor allows you to:
Modify (update) values - Add (insert) new rows - Delete Rows
Set individual field values to null
Select image files (for columns of type: Blob/Clob)
▪ All values are saved (committed) or not (rolled-back) at once when you press Ctrl/S
Using the Data tools you can: 1. Run a SQL Statement, 2. View the SQL results,
3. Modify table data values in order to test different WHERE clause conditions,
4. Re-run the SQL Statement, etc.
© IBM Corporation 34
Table Filtering (IDz + Data Studio) – 1 of 3
From the Data Source Explorer
Right-click over a table
Select: Data > Edit Data
Click: Filter the data
© IBM Corporation 35
Table Filtering (IDz + Data Studio) – 2 of 3
IBM Data Studio table editor – in data filtering mode allows you to:
Modify (update) values - Add (insert) new rows - Delete Rows
Set individual field values to DB2 Null values
Select image files (for columns of type: Blob/Clob)
▪ All values are saved (committed) or not (rolled-back) at once when you
press Ctrl/S
© IBM Corporation 36
Table Filtering (IDz + Data Studio) – 3 of 3
Filtering options include:
• Sorting
• Sort Order
• Move Column Right/Left
• Move up/Move down
• Multiple Row Selection
Conditions
• Any/All predicate
© IBM Corporation 37
DCLGEN – 1 of 4
DCLGEN – Allows you to create copybooks from
table schemas for: COBOL, PL/I, C, and Java
Steps – from the Data Perspective:
Highlight the table you want
Right-click and select: DCLGEN
Click Finish
© IBM Corporation 39
See Slide Notes
DCLGEN – 3 of 4
▪ The wizard will submit a job, which you
can track in the:
▪ z/OS Projects Perspective
▪ JES facility
© IBM Corporation 40
DCLGEN – 4 of 4
From Remote
Systems explorer
you can also open
the PDS and look
at your DCLGEN'd
source ➔
© IBM Corporation 41
Customizing the Data Perspective – Preferences
▪ Data Studio provides a much large set of tools – which brings many more
options for setup, configuration , customization, etc.
Preferences
for Data Studio
Customization
(again) from:
Window
▪ Preferences
– Data Management
– SQL Development ➔
© IBM Corporation 42
Additional IBM Data Studio Tooling for Working With DB2 Objects – 1 of 3
© IBM Corporation 43
Additional IBM Data Studio Tooling for Working With DB2 Objects – 2 of 3
Table value statistics reporting
© IBM Corporation 44
Additional IBM Data Studio Tooling for Working With DB2 Objects – 3 of 3
DBA, SYSPROG and SQL coding options against the DB2 Subsystem
© IBM Corporation 46
Code Interactive SQL Statements – SQL Script
Similar to SPUFI – you use a SQL Script file to edit and test your SQL. A SQL Script is a text file
that contains interactive SQL statements – with or without host variables
These statements can be tested in the Data Perspective before embedding them in COBOL data
access functions. For complex SQL logic, this is recommended “best practice”.
© IBM Corporation 47
Code Interactive SQL Statements – SQL Script – w/Data Studio
Data Studio provides richer functionality, and there are many additional Context Menu options
(next slide)
Run SQL 4.
1. Code SQL
Access SQL 3.
functionality
2.
5.
SQL
Results
© IBM Corporation 48
Code Interactive SQL Statements – SQL Script – w/Data Studio
Additional SQL
coding/testing/tuning
Toolbar ➔ options in Data Studio
Coding,
Formatting,
Testing
Tuning options
© IBM Corporation 49
Create and Run a SQL Script Statement
You can code your SQL statements using Content Assist – to get the table names and SQL keywords
(Ctrl/Spacebar)
© IBM Corporation 51
Create New SQL
Statement Template
Not every SQL operator/expression
is available as a Template
1. Click New
2. Name the Template
3. Add a Description
4. Code the Pattern
© IBM Corporation 52
SQL Query - Editing and Running Multiple Statements (Similar to SPUFI)
You can code and multiple SQL statements by ending each statement with a semi-colon (see screen capture):
Expand the statement in SQL results.
Each query will have its own results window
Notes:
Each query is treated
as a separate unit of
work.
Successful updates
are committed
between statements
© IBM Corporation 53
New SQL Script – Run SQL
When you are finished coding
1. Right-click over the script area
2. Select Run SQL
3. Verify your results
Note that the Status will show details on your statement's execution
© IBM Corporation 54
Working with Embedded SQL Statements - 1 of 3
You can use a SQL Query to test your COBOL/SQL statements out prior to testing them at the
COBOL procedural logic level (note this saves both time and CPU resources)
▪ Steps:
From IDz, click back over to the z/OS Perspective (but do NOT close the Data Perspective)
Open: cursravg.cbl
Find the 100-DECLARE-CURSOR-RTN paragraph shown below
Copy the SELECT… ➔ GROUP BY DEPT clauses as shown
Select
and
copy
this
- You will test only the interactive SQL portion of your COBOL cursor declaration
© IBM Corporation 55
Working with Embedded SQL Statements - 2 of 3
▪ From IDz, click back to the Data Perspective
▪ If you still have your other SQL Script page open, select and delete the existing
statement, then Paste in the copied SQL cursor code
▪ Right-click and Run the SQL Statement and view results
© IBM Corporation 57
Running SQL From the Outline View
▪ If you have a file of SPUFI statements that you’d like to run with IDz:
Open the SPUFI file in a SQL editor
Open the Outline View – every single SQL statement will be listed in the view
Click a statement – to select a single statement from your file
Right-click, and select Run SQL – Check out the SQL Results View
▪ You can Sort the list – by clicking on a column header (E.G. click on: Date)
▪ You can clean up (Remove), Copy & Paste the queries and Save History
Query+Results to an external PC file
© IBM Corporation 59
Additional SQL Results View Options - 1 of 4
▪ Copy to clipboard
▪ Remove selected entry
▪ Remove ALL entries
▪ Display SQL & Results in single tab
▪ Display rows Vertically/Horizontally
▪ Display in Text Mode
© IBM Corporation 60
Additional SQL Results View Options – 2 of 4
Display result
in single tab…
Copy Results
to Clipboard
Paste into
Windows file
.txt
.csv
.doc
etc.
© IBM Corporation 61
Additional SQL Results
View Options – 3 of 4
Vertical Orientation
Display result
in text mode…
Note Context
Menu Export
and other
actions
available
© IBM Corporation 62
Additional SQL Results View Options – 4 of 4
Toggle
Tabbed
Layout
View
© IBM Corporation 63
Enabling Local Syntax Check of Embedded SQL
Customize Property Groups for Embedded SQL Syntax Check:
From the Property Group Manager view:
▪ Edit the LOCAL Property Group file
▪ Check: Source contains SQL Statements
▪ Either Browse… to a connection, or select New… and create a connection to DB2
SQL Options can be used to further customize your DB2 Syntax check
▪ See screen capture for an example of how you could explicitly set the Schema name for any
unqualified embedded SQL statements
▪ In this example: PROD1DBA will be used to qualify SQL table/view names in your code
© IBM Corporation 64
Review – "How do I" (Using IDz, be sure you know how to do the following…)
▪ Access the data tools in the IDz Workbench (how do you open the Data Perspective)?
▪ Create a connection to a DB2 region?
▪ Filter out Schemas you don't want to see in the Data Source Explorer?
▪ View sample rows from a table, view or synonym?
▪ Edit a DB2 table?
▪ Save changes to my row/column edits?
▪ List indexes for a DB2 table
▪ Generate the table definition (DDL) for a DB2 table or view?
▪ View the different values in a DB2 table column, and see the number of rows each value has in the table?
▪ Understand the relationships among a set of DB2 tables – connected with Primary/Foreign key constraints?
i.e. Create an "Entity-Relationship Diagram"
▪ List the primary or foreign key (constraints) for a DB2 table?
▪ Understand how an index on a table is designed (to see if it will help make my SQL query faster)?
▪ List the columns in a table or view?
▪ Change the default maximum number of rows displayed or edited in a table?
▪ Code a dynamic SQL statement?
▪ Invoke (use) Content Assist to help you code a SQL statement (what two keys??)
▪ Run a SQL statement?
▪ Code and test (run) multiple SQL statements in one batch (like SPUFI)?
▪ Perform (relative) SQL statement efficiency benchmarks?
▪ Export rows from SQL results to a: web page, XML file, Excel spreadsheet?
▪ "Explain" the plan DB2 will use to access the table?
▪ DCLGEN a table?
© IBM Corporation 65
UNIT The IDz Workbench
Topics:
▪ The Data Perspective and connecting to DB2
▪ Understanding your DB2 objects
▪ Editing and managing DB2 table data
▪ Coding and testing SQL
▪ Data Studio & IDz Integration – Productivity Techniques
▪ Extract/Load and Managing Test Data
▪ Workshops and Appendices
© IBM Corporation 66
IDz/IDz + IBM Data Studio Client
Starting Version 9 of IDz and continuing with IDz & Adfz, IBM provided a number of new
SQL/DB2 feature/benefits. Including, but not limited to:
Ability to select an EXEC SQL statement and Run, Tune and Explain the SQL
Ability to create Embedded SQL statements using Content Assist from within COBOL/PL1
▪ Note that the Content Assist (Ctrl+Spacebar) accesses the DB2 Catalog
Populate a SQL Outline view - a feature of Data Studio - with the SQL statements from the COBOL or
PLI program that the user is editing - and thus make available all the menu items to Run, Tune, Visual
Explain etc. from the SQL Outline view
© IBM Corporation 68
Setup and Run Steps (Big Picture)
1. Connect to your mainframe/LPAR. Connect to DB2
2. Create an MVS Subproject and populate the
subproject with your Embedded SQL programs
3. Add Data Access Development Support to the MVS
Subprojects
4. Specify the default SCHEMA
5. Find an embedded SQL statement inside your
source
6. Use your mouse to select the statement text
A few lines, starting from EXEC SQL...
7. Right-click and Run SQL. Check out your results
If your statement contains "host variables" you'll be
prompted for literal values when you Run the SQL
© IBM Corporation 69
Setting up for Integrated DB2/SQL Functionality – 1 of n
▪ You will connect to DB2 from the Data Perspective – and Data Source Explorer the same way
▪ However, you must specify a Default schema
© IBM Corporation 70
Filtering Schemas and Tables – + Data Studio
© IBM Corporation 71
Configuring IDz For Enhanced DB2/SQL Functionality With Data Studio - Steps
Note that defining a connection and an MVS Subproject is a one-time-task. The steps on the next
pages will not need to be repeated each time you want to work with embedded DB2/SQL codes
© IBM Corporation 72
Define a Connection to your Mainframe Through Remote Systems
▪ From Remote Systems:
Expand New Connection and select z/OS…
Enter the Host name for your LPAR (zserveros.demos.ibm.com is what you can use in
class if you are not using your own mainframe)
Specify a Connection name
Press Next >
For both z/OS Unix and MVS Files you will need to specify a Port number. This allows Remote Systems
to interact with your workstation.
▪ The port for zserveros is: 4035.
▪ This port must be available through your firewall
© IBM Corporation 73
Login to Your Connection Through Remote Systems
▪ From your named-new Connection:
Right-click and select Connect
Specify your TSO credentials:
▪ User ID (TSO ID) and Password
Optionally save the user ID and password so that
you don’t have re-enter them and click: OK
© IBM Corporation 74
Define a Default Property Group – 1 of 2
Click OK
© IBM Corporation 76
Define an MVS Subproject
▪ Click Finish
© IBM Corporation 78
Add Data Access Development to Your MVS Subproject – 1 of 2
© IBM Corporation 80
Work with the Advanced DB2/SQL Tooling – Open your DB2 Program
▪ From here on, any COBOL or PLI source being edited in the IDz editors will have additional
menu items enabled when an EXEC SQL statement is selected
© IBM Corporation 81
Work with the Advanced DB2/SQL Tooling – Access Embedded SQL
If you are not already logged in to your DB2 connection you will be prompted
** OPTIM Query Tuner does not install with IBM Data Studio client 4.1
▪ It’s a separately priced host/DB2 package
© IBM Corporation 83
What if my SQL code resides in a Copybook or
EXEC SQL INCLUDE?
© IBM Corporation 84
Select and Run SQL – SQL Results view
▪ After running a statement, the SQL Results view will open, and you may go
to the statement result and work with it:
▪ You can modify and re-run your SQL statements directly in the editor:
© IBM Corporation 86
Using Content Assist to access
Schema/Column/Table names from
within COBOL Edit
▪ You can configure your Property
Group file to allow Content Assist
(Ctrl+Spacebar) access to DB2
Schema, Table and Column names –
as well as SQL statements during
COBOL or PL/I edit.
Configure your language tab, Local
Compiler Options:
- Source Contains EXEC SQL statements
- Browse… to your DB2 Connection
Edit your source:
- Create a statement using Content Assist
Note that you can also use Content Assist to access
Column Names, and other SQL language elements
1. 5.
2.
3. 4.
© IBM Corporation 87
Work with the Advanced DB2/SQL Tooling – Refresh SQL in Outline View
▪ SCHEMA:
Tables within the Schema
▪ SQL referencing the tables
© IBM Corporation 88
Work with the Advanced DB2/SQL Tooling – Schemas Tab Options
▪ From the Schemas tab, you can:
Locate the statement in your program
Run the SQL
Open the Interactive SQL Editor with the
statement copied into it
▪ Provides access to the graphical SQL Editor
– Right-click inside of the Interactive SQL Editor
and select: Open with SQL Query Builder
Export the SQL statement to an
external/local file on your workstation
Retrieve pre-existing EXPLAIN information
from the Plan Table(s)
Launch a Visual Explain on the statement
Launch OPTIM Query Tuner for the
statement
▪ Requires separately priced host product
installation
Generate and Find pureQuery Code http://en.wikipedia.org/wiki/IBM_PureQuery
Show the SQL in table format
Filter the SQL
▪ Allows you to Filter on:
– SQL statement types
– (a single) DB2 Object name
– Using Regular Expressions to search
Show the Explain or Query Tuner
performance information
© IBM Corporation 89
Work with the Advanced DB2/SQL Tooling – Visual Explain – 1 of 2
3.
© IBM Corporation 90
Work with the Advanced DB2/SQL Tooling – Visual Explain – 2 of 2
▪ When
Visual
Explain
finishes, Different Query stages in the
you’ll Visual Explain diagram
probably
want to
go full-
screen.
▪ In order
to see… The potential for (expensive)
Stage 2 predicates in the Access
Path Plan (note that this join
condition is a Stage 1 predicate)
Pop-up DB2 Optimizer
estimates/meta-data
© IBM Corporation 92
Recommendation – Reposition the Data Source Explorer in z/OS Projects
Once you’ve accessed the Data Source Explorer you might want to drag it to
the bottom-left hand corner, where you’re used to seeing and using it
© IBM Corporation 93
Work with the Advanced DB2/SQL Tooling – Working With Additional Programs
2.
1.
1. Add other COBOL/DB2 programs
to the MVS Subproject.
4.
© IBM Corporation 94
Work with the Advanced DB2/SQL Tooling – Table and Statement Filters – 1 of 2
▪ Three filters:
1. Table/View name
1.
2. SQL Statement type
2.
© IBM Corporation 95
Work with the Advanced DB2/SQL Tooling – Table and Statement Filters – 2 of 2
© IBM Corporation 96
Tune SQL – Using Optim Query Workload Tuner – 1 of 8
If your shop has Optim Query Workload Tuner** installed, you can tune an SQL statement:
From the Context Menu within edit on the code
From the:
▪ Outline View
▪ Context menu on a statement
© IBM Corporation 98
Tune SQL – Using Optim Query Workload Tuner – 3 of 8
▪ The tuning can take around a minute or so depending on many factors.
▪ When it comes back, you will be prompted for the various Access Path reports you’d
like Optim to produce.
I usually select all three
And show in HTML format
Tabbed steps in the Query Tuning Process and Results
© IBM Corporation 99
Tune SQL – Using Optim Query Workload Tuner – 4 of 8
The reports will be produced, and you can click each of through them from the Single
Query reports, graphs and explorer
Starting with an Analysis summary of the key findings/recommendations
▪ Open Single-Query Recommendations
Single Query Reports
▪ If Optim Query Workload Tuner is installed on your mainframe, you should try tuning
a query during class from the IDz /IBM Data Studio 4.1 tooling.
▪ You may need authorization or assistance from your DBA to run the Tuning Report
▪ And DBAs will make the best use of the tuning information – as the reports are deep
and highly technical – as they should be for this sort of product functionality.
From there you have all the tools of Excel at your disposal
© IBM Corporation 109
Utilizing Extracted Data for Decision Support: MS-Word
▪ You can create MS-Word and PowerPoint docs by:
Extracting into Excel *.csv
Opening the extract file, selecting all values (Ctrl+A) then copying & pasting the values into
MS-Word
Once inside the Word doc you can create well-formed tables by selecting the values and
(from the Insert tab) creating a table – then formatting the cells
From here you have all the tools of Excel at your disposal
▪ Considerations:
You must have CREATE VIEW privileges
▪ Or optionally, you can ask your DBA or the table "owner" to run a CREATE VIEW for
you, if you don't
You must create an update-able view.
▪ An update-able view is a row-column subset of one table. The statement must not:
– Reference more than one table in the FROM clause, in a sub-select or UNION with other tables
– Contain GROUP BY or HAVING clause or DISTINCT in the selection list.
– Reference a non-updateable view
– Contain an SQL "expression" (functions, computations, etc.)
▪ Here's a sample Create View statement that creates a row/column subset of
the DDS0001.CUST table:
Create View Cust_View_CT as
Select ID, LNAME, ST From DDS0001.Cust Where ST = 'CT'
3. Make changes
Ctrl+S
4. Save your edits
Workshops
DevOps
▪ The slides that follow provide good examples to exercise the techniques
demonstrated in this section. You will have to substitute the names of your
own tables/views for the ones referenced in the slides
© IBM Corporation 119
Workshop – Filtering Schemas and Tables
▪ Recall:
In the DB2 world on z/OS
databases could easily
contain:
▪ Tens of thousands of tables
▪ Thousands of Schemas
▪ To simplify working on your
projects filter the available
DB2 objects
Sort
your
results
Export your
results
▪ Caution about the Browse Data and Sample Contents These options ignore the
Preferences setting for maximum number of rows to return from DB2, and on a very large table will cause
Workbench performance problems
Optional
▪ Copy and all of the commented
SQL statements in the Slide
Notes
▪ Try other Context Menu
selections like Format SQL
Summary
© IBM Corporation 133
UNIT The IDz Workbench
Topics:
▪ The Data Perspective and connecting to DB2
▪ Understanding your DB2 objects
▪ Editing and managing DB2 table data
▪ Coding and testing SQL
▪ The Data Studio + IDz Features
▪ Extract/Load and Managing Test Data
▪ Optional Workshops and Appendices
▪ You can see the SQL that was used to create the View (DDL)
Steps:
▪ Select the filter
▪ Un-check Disable filter
▪ Specify your new filter
▪ Click OK
▪ Tables
▪ Relationships
(click the lines drawn
between the entities)
▪ Views
▪ By working with the Display Results options you can create an output report
that combines queries and results in one file (like SPUFI output)
Using Content Assist – create your statement one SQL element at a time
▪ Some SQL syntax errors are flagged dynamically
▪ Steps:
From the Data Project Explorer
Right-click and select:
▪ New > Data Development Project
Select a Connection
Click: Finish
▪ Steps:
1. Create a new statement
▪ Optionally –
copy the Result
rows to an external
file for further
analysis
▪ Steps:
Using the SQL Script editor, code
and run your statement
▪ Notes:
Plan_Tables are DB2
version specific
There is a Visual Explain
product from IBM that
plugs into Eclipse
▪ Links:
http://www.ibm.com/developerworks/data/library/techarticle/dm-0411melnyk/
http://publib.boulder.ibm.com/infocenter/db2luw//index.jsp?topic=/com.ibm.db2.udb.doc/admin/c0004932.htm
2. Enable your project for copybook access – by customizing SYSLIB in your Property Group file:
- From the Property Group Manager view
- Expand LOCAL
- Right-click COBOL Sample Property Group
- Click on the COBOL tab
- Paste the copied location into SYSLIB
- Delete everything to left of the valid filespec
- Save your changes (Ctrl+S)
- Close the Property Group file
Scroll down into the System tables using the Explorer – research any/all tables that look
interesting – note how easy it is to use the graphical tools for browsing the Catalog and
answering questions
© IBM Corporation 165
Advanced Workshop – SPUFI Emulation – 1 of 6
Use the LPEX Filter feature - combined with a file of type sql to effectively test your
SQL statements from within the z/OS Projects Perspective
Use Content Assist (Ctrl+Spacebar) to create the SQL Statements. Note that
Content Assist pulls DB2 Table/Column Meta Data (names) from the
System Catalog
© IBM Corporation 168
Advanced Workshop – SPUFI Emulation – 4 of 6
▪ Testing embedded SQL from within the z/OS Projects Perspective
Appendices
- Connecting to DB2/UDB
- Connecting to a Derby database
- Using Data Studio 3.1.1
Back-up Slides
When you are finished, you should see the following folders:
▪ Notes:
– I have unzipped the file onto my C: drive ➔
– If you wish to use another drive that's fine
– On the next slide you'll be prompted to specify the database location, so
remember where you unzip
2.
1.
▪ Create a new
connection to a
mainframe z/OS
Database
▪ There are two separate functions for analyzing and tuning your
queries:
1. Visual Explain
▪ Provides a graphical EXPLAIN view for understanding the access paths the
DB2 Optimizer chooses for your queries
▪ Is packaged with the Optim Data Studio 3.1.1 client (i.e. is free)
▪ Requires EXPLAIN tables (but will create these for you on the fly if you don't already
have them)
2. SQL Query Tuning
▪ Provides Visual Explain
▪ Additionally provides a wealth of query tuning advice and recommendations
▪ The SQL Tuning client element is packaged with Optim Data Studio 3.1.1
▪ But there is a Server component (InfoSphere) that must be installed and
configured
– And is not free
If you're Explaining
embedded SQL you will
need to remove host
language constructs such
as EXEC SQL, host
variables, indicator
© IBM Corporation 184 variables, etc.
Visual Explain – 2 of 3
▪ Click the Open Visual Explain
icon ➔
▪ Specify settings:
Tracing options
If you don't own EXPLAIN
(DB2 PLAN_TABLES) check
the Create missing EXPLAIN…
box
▪ Click Finish
© IBM Corporation 185
Visual Explain – 3 of 3
The graphical tree shows
the Optimizer's decisions
for query's access path.
▪ Enter your SQL Statement and click: Invoke Advisors and Tools
▪ Notes
Syntax errors in your SQL statement will be returned with a negative
SQLCODE and explanation
The more options you select the longer the process will take to
complete
© IBM Corporation 190
OPTIM -
▪ Upon completion of the tuning advisor you will be in the Review workflow
Read through the Recommendations
Open the Access Plan Graph/Explorer
Save the query recommendations for future study
Mouse over
the activities
and outcomes
of the access
path for
details of the
Optimizer's
decisions
© IBM Corporation
Specific Tuning
Recommendations
194
More DBA Tuning – the Summary Report
UNIT The IDz Workbench
Topics: Optim Data Tools
▪ Using Visual Explain
▪ Test Table Subsetting
▪ Steps:
Assuming you're connected…
Expand your Database location
Expand Schemas
Expand the Schema you wish to filter
Right-click Tables
Select Properties
▪ Click OK
This will open a list of tables for subsetting based on your Filtering specifications
2. Click Tables ➔
3. Right-Click over
your Table and select
Edit Data
Specific Tuning
▪ Click OK Recommendations
Data Studio
version of Data
Source Explorer