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

Db2 Mainframes

Uploaded by

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

Db2 Mainframes

Uploaded by

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

®

IBM Software Group

IBM Developer for z Systems – for ISPF Developers

Module 8 – Using the Data Source Explorer

DevOps
Jon Sayles, IBM - [email protected]

© 2019 IBM Corporation


@Copyright IBM – January, 2020
IBM Trademarks and Copyrights
© Copyright IBM Corporation 2008 through 2020

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

After completing this topic, you should be able to:


Use the IDz Data Perspective to:
▪ Connect to local and remote databases
▪ Edit test data interactively
▪ Display results of SQL queries
▪ Perform DBA activities on tables in a local database
▪ Display the data model for your application/DB2 tables and views

 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.

▪ IBM Also supplies excellent SQL and DB2 documentation:


 DB2 Documentation
 SQL Getting Started
 SQL Reference Manual
 Message (error code) Reference. Cached pdf version of full guide.
 DB2 Application Development Guide with example embedded SQL programs.
 Triggers in DB2
 Constraints in DB2
▪ And there are plenty of non-IBM sites to learn about SQL:
 Http://en.wikipedia.org/wiki/SQL

▪ Note: In order for you to get the above links to work, view the PowerPoint in
Slide Show mode.

▪ Here is an example of COBOL database access:


 http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.apsg/db2z_sa
mplecoboldrdathreepartnames.htm

© 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

2. Cost Savings - z/OS MIPS reduction:


▪ IDz is substantially less expensive than
TSO/SPUFI or QMF for doing
DB2/SQL development
▪ JDBC** Drivers
– Ziip/Zaap

In place of SPUFI/QMF we’ll use the Data Source Explorer


© IBM Corporation 8
Data Source
Explorer
DB2/SQL
Development
Tools

If your z/OS Projects


perspective doesn’t show
the Data Explorer view –
from: The Data Source Explorer View:
 Connections – which contain references to:
Window ➔
▪ Schemas and tables
Show View ➔ Other
▪ Processing options
Locate and open the view  Raw DB2 Table Data View(s):
▪ Your DB2 Tables/Views are displayed WYSIWYG like
Excel spreadsheets
▪ And you can access update/cell values – along with
adding new rows & deleting rows
 SQL Statement Output View
▪ Shows the results of running SQL queries
© IBM Corporation 9
Data Source Explorer View – Integrated into the z/OS Projects Perspective
By integrating the Data Explorer View into z/OS Projects you can work in one environment on all of
the tasks and projects z/OS developers perform – including the three standard DB2 tasks…

© 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

You connect to DB2 using JDBC Access to DB2 Tables is


drivers – provided by: defined in the DB2 Catalog
thru DBA Grants – not RACF
 IBM/IDz
IDz Client Software
 3rd Party
z/OS
DB2 Data
• Schemas
• Tables/ Views
• Indexes
• Stored Procedures
• Etc. DB2 System
• LOCATION
• PORT#
To obtain the Location and Port#
1. From ISPF go to DB2I -
Option 7 - DB2 Commands
2. Issue the command: DB2 Catalog
-DISPLAY DDF
• Grant/Privileges
DB2 Libraries
• SDSNLOAD
• Meta-Data
• PROCLIB
© IBM Corporation 12 • RUNLIB.LOAD
Connecting to DB2 on z/OS
▪ Connecting to DB2 on z/OS:
▪ From the Data Source Explorer – select New Connection Profile
▪ Select: DB2 for z/OS
as the database manager
▪ Enter Properties:
 Location:
▪ TCP/IP Location name
of the DB2 Server on
z/OS (get values from DBA)
 Host:
▪ IP Address of the
z/OS mainframe
 Port:
▪ For DB2 on z/OS
 Do NOT check:
▪ Retrieve objects created
by this user only
 User name/Password:
▪ Required – or use Single sign-on thru your z/OS Host Connection Note that connection
values to your DB2
▪ Click Test Connection, and if successful…Click Next > system will be
13
completely different
© IBM Corporation
Filtering Schemas
At Data Privacy Modeling – click Next >

Your DB2 instance on z/OS, databases could


easily contain:
▪ Thousands of tables
▪ Hundreds of Schemas
To simplify your work you will - Filter the
available DB2 objects

1. Un-check: □ Disable filter


2. Click  Selection
3. Check  <Schema_Name> for each
DB2 Schema you wish to add to your
Connection

Click Finish to create your connection and


return to the Data Source Explorer
© IBM Corporation 14
Filtering Schemas and Tables
▪ After you’ve created your connection
you can continue to Filter your DB2
Schemas and/or Tables any time
you need ➔
Right-click over Schemas (or Tables)
Select Filter…

Uncheck: Disable Filter


Check: Selection

Decide which tables you want

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)

The properties of a DB2 Table


– Indexes
– Triggers
– User-defined functions
▪ Views
▪ The Properties view can be helpful in expanding the
information presented.
▪ Many additional context menu options exist off these
entries
© IBM Corporation 17
Exploring DB2 Meta Data
▪ Use your mouse to expand/collapse
DB2 object meta-data categories
▪ Information is presented through a
hierarchical tree-control – modeling
the structure in the DDL that was
used to create the object

▪ All of the meta-data shown in the


Explorer is pulled dynamically from
the DB2 Catalog, making it 100%
Accurate
Current
▪ The Context Menu provides (much)
additional functionality:
Select a DB2 object
Right-click
Context options pop-up in the
menu and sub-menus
© IBM Corporation 18
Exploring Table Values – Sample (Data) Contents in a DB2 Table/Column
▪ IDz provides a canned SELECT DISTINCT/GROUP BY query
▪ The query results show column cardinality
The number of discrete values in each column, throughout the Table

© IBM Corporation 19
Exporting Column “Sample Contents”

▪ You can Export All Results into a


spreadsheet – and turn data into information

© 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

This kind of diagram (see


results on next slide)
is often called an
"Entity-Relationship
Diagram" – because it
draws out the
relationships between
your DB2 "entities" –
tables/views/synonyms

© 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

From the Data Source Explorer:


 Right-click over the table name
 Select: Generate DDL…
 Follow the wizard
▪ Check/Un-check selections

© 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

Data Source Explorer - Context Menu, Data options


Viewing a table's column
definitions

© 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

▪ IDz Data tools provide many additional


features. Some of them are traditional
DBA functions which you may not be
authorized to use (Updating Statistics)
Data Source
Explorer –
Context Menu,
Data options

© 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.

▪ Note that this is essentially a Select * from <schema.table>


 The # of rows returned is configurable in Preferences
▪ Consider using SQL Scripts to write statements that filter the result tables

© 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

Note that you can export the results


of any SQL statement
 Reduces the effort to build xml and html
reports off of DB2 data
© IBM Corporation 32
Table Editing – 1 of 2
Another very common requirement for SQL programming is to customize your test data. Rather than fussing with
interactive SQL INSERT/UPDATE/DELETE statements using QMF or SPUFI, try this:
 From the Data Source Explorer
 Right-click over a table
 Select: Data > Edit

© 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

This opens the Table Data Filter dialog

Use the dialog to:


 Add > Columns

 Add Row Selection


 Click Add
 Open the Column
drop-down
 Open the Operator
drop-down
 Specify a search value

© 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

Using the DCLGEN wizard


Connect to the host System
1. Specify the name of your shop's DB2 subsystem
2. Customize the JCL JOB Card, Add //JOBLIB
DD card – referencing your shop's DB2 load library)
3. Click: Next >

• you will need to specify the


correct DSN for the DB2
SDSNLOAD runtime library
© IBM Corporation 38 where the DCLGEN CLIST exists
DCLGEN – 2 of 4
Select:
▪ Language
▪ Browse to select
your DCLGEN
output PDS
▪ Rename the PDS
member
▪ Click Next >

 Customize the DCLGEN-specific options

 Note that at minimum, you will have to


change the Member and Data structure name if
your table name contains an underscore

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

▪ Provided you have the necessary level of


authority in your DB2 subsystem, you can do
the following:
Work with DB2
Databases
and
Tablespaces
Perform certain traditional DBA
functions against Tables, Views
and Indexes

Work with DB2


Storage Groups

© 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

With a DB2 Table selected


you can find out things like:
Total number of rows, etc.

Note that Statistics must


have been run prior
© IBM Corporation 45
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 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”.

To open and work with a SQL Script:


 From the Data Source Explorer
 Right-click over the DB2 system icon shown and select: New SQL Script

© 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)

After you're done coding, right-click (context Menu)


over the statement

Select Execute Current Text


(or Execute All)

View the SQL Results

Note: For Content Assist


to work, you must
qualify the DB2 table,
view, synonym name:
Schema.Tablename
© IBM Corporation 50
Set Current DB2 Schema
By default, IDz will assign your connection
TSO ID as the Schema for your
dynamic SQL statements. If you
need a different schema name...

1. From Window ➔ Preferences, create


a new SQL Editor Template to:
SET CURRENT SCHEMA =
'${SCHEMA}';
2. From a SQL Script editing session
 Type: set
 Press Ctrl+Spacebar
 Select your Template

3. From the SQL Script editor type the


Schema Name you want and run the
query(s)

© IBM Corporation 51
Create New SQL
Statement Template
Not every SQL operator/expression
is available as a Template

To create your own Template:


From Preferences ➔
Data Management ➔
SQL Development ➔
SQL and XQuery Editor ➔
Templates

1. Click New
2. Name the Template
3. Add a Description
4. Code the Pattern

${....} - becomes a fill-in-the-blanks


variable during edit

Content Assist (Ctrl+Spacebar)


invokes the templates

© 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

 Note: As you did with the sample table contents, you


can Right-click over the result rows, and Export the result
data for data compare, reporting, etc.. This can be useful
during DB2 application testing/debugging.
© IBM Corporation 56
Working with Embedded SQL Statements – 3 of 3 (Host Variable Values)
▪ Most of the SQL
statements embedded in
your COBOL and PL/I
programs will have host-
variables
▪ In order to test such
statements, you can:
"Stub the host variables
out" – replacing the SQL
statement operands with
literals
Use the Host Variable
Values wizard (see Qualified Host Variables such as: :DCL.PERF
disclaimer for COBOL) – are supported.
Specifying the Host
Variable values as PL/I Variables (separated by under-scores) are also
shown on the right supported

© 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

Note that – by selecting Run SQL on


the toolbar, you could run the entire
© IBM Corporation 58
file of SQL statements all at once
Cleaning up the scripts in SQL Results view
The SQL Results view has a number of useful actions for development/test
▪ Any statement and its results can be viewed by selecting it
▪ You can Filter the statement list

▪ 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

With EXEC SQL statements enabled:


▪ IDz validates embedded SQL references in your source
▪ You can create embedded SQL statements using Content Assist
– SQL Keywords, DB2 Tables/Views & Columns, Snippets & Templates

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

In order to access this extended SQL development functionality you must


install IBM Data Studio 4.1 so that it “shell shares” with IDz
© IBM Corporation 67
Installation Pre-requisites
▪ IDz and IBM Data Studio 4.1 take advantage of “shell sharing” (essentially multiple-
product integration by installing certain features into the same directory) to provide
much richer integration between the product capabilities and thus enhance the
overall developer productivity and experience.
▪ The first prerequisite to obtaining these features is to install IDz and Data Studio
into the same “SDPSHARE” Package
▪ Installation manager will show you what packages are installed together into the SDPSHARE
directories
▪ Here you can see that the following products are installed into a single package
 CICS Explorer
 Data Studio Client
 DB2 Analytics
 IDz

© 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

▪ Using Data Studio you will be prompted for a Physical data


model
Click Next > without specifying anything

▪ In after un-checking Disable filter, specify your initial


Schema filter from the Expression … Not Selection option

© IBM Corporation 71
Configuring IDz For Enhanced DB2/SQL Functionality With Data Studio - Steps

▪ Once you have successfully Connected to DB2 you will


return to the z/OS Projects Perspective and
perform the following steps
1.Define an MVS Subproject**
2.Add a COBOL or PL/I program with embedded SQL into the Subproject
3.Add Data Access Development Support to the Subproject
4.Work with the enhanced DB2/SQL tooling:
▪ Run SQL statements directly from within source editing
▪ Tune SQL statements from within edit
▪ Open and work with an SQL Outline View – which provides you with Context
Menu access to:
– Visual Explain
– Various table operations
– Filtering SQL statements
**MVS Subprojects are covered in-depth in an upcoming course module. However they are introduced here
in order to facilitate enhanced DB2/SQL work. And in order to define an MVS Subproject, you must have defined
a connection to your mainframe and logged in through Remote Systems, and defined a default Property Group.
These topics will also be covered in an upcoming course module.

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

▪ If everything’s working, you can expand My Data Sets to see


the files you have allocated to your TSO ID

© IBM Corporation 74
Define a Default Property Group – 1 of 2

▪ Once you are connected, from the


Property Group Manager view:
 Right-click over your named connection
 Select: New Property Group…

 From SYSLIB: Specify the name(s) of


any copybook/DCLGEN libraries your
programs reference.
▪ Note that for this module, if you’re
using the course
programs/copybooks you only need
to specify: <HLQ>.TEST.COPYLIB
▪ Press Ctrl+S to save your work

▪ Close the Property-Group editor

 Property Group settings provide IDz with configuration information, such as


destination libraries/SYSLIB concatenation for finding copybooks
© IBM Corporation 75
1.
Define a Default Property Group – 2 of 2

▪ Finally – you associate your new 2.


Property Group with the MVS Files you
will be accessing through IDz

From Remote Systems

Right-click over MVS Files

Select Property Group >


4. 3.
▪ Associate Property Group…

Click OK

© IBM Corporation 76
Define an MVS Subproject

▪ From the z/OS Projects Perspective


 Right-click inside the z/OS Projects view and select:
▪ New > z/OS Project…
▪ Name the z/OS Project ➔

From MVS Subproject Name and Location

▪ Select a Connection name

▪ Name the MVS Subproject

▪ Check the Property Group to associate


with the MVS Subproject

▪ Click Finish

At the prompt to Add Resources to


the Subproject click Cancel
© IBM Corporation 77
Add DB2 Programs to Your MVS Subproject

▪ From Remote Systems:


Expand My Datasets
Scroll and or Page… down through a
library that contains DB2 programs
Right-click over the program and add
it to your MVS Subproject
▪ Note that the program CURSRAVG is
a DB2/COBOL program.
▪ If this program is not currently in a
.COBOL library drag and drop the
program from IDzClass > cobol to a
PDS in Remote Systems

© IBM Corporation 78
Add Data Access Development to Your MVS Subproject – 1 of 2

▪ Adding the Data Access development support results in the association of


an MVS Subproject and its source files with the database connection you
just created:
▪ From z/OS Projects:
Right-click over your MVS Subproject
Select Add Data Access Development Support

Note that if Add Data Access


Development Support does not
appear in the Context Menu more than
likely:
 You are not using IDz version 9 …
or …
 IBM Data Studio 4.1 is not installed
… or …
 IBM Data Studio 4.1 is not shell-
sharing with IDz
© IBM Corporation 79
Add Data Access Development to Your MVS Subproject – 2 of 2

▪ Select a Connection from the drop-down list


▪ If a Default Schema is not entered, type one in at this point
▪ And click: Finish

© IBM Corporation 80
Work with the Advanced DB2/SQL Tooling – Open your DB2 Program

▪ From your MVS Subproject:


Double-click over your program to open it in the Editor
Note that you can use either:
▪ System z LPEX Editor
▪ COBOL Editor
… the DB2/SQL tooling is enabled in both editors

▪ 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

▪ From inside your source editing session:


Access your SQL – by:
▪ Scrolling
▪ Find commands
▪ Filter view

▪ Note that you don’t have to be in Filter view mode to access


the tooling. But you might want to be.
© IBM Corporation 82
Work with the Advanced DB2/SQL Tooling – Select and Run SQL

▪ Select an SQL statement within an edit session for SQL access:


From EXEC SQL ➔ END-EXEC inclusive – see screen capture below
Right-click and you should see three new SQL options:
1. Tune SQL – using OPTIM Query Tuner**
2. Run SQL – execute the SQL statement you’ve selected
3. Refresh SQL in Outline View – open/refresh SQL tooling in a view specific to 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?

▪ You can still run SQL statements from


within an Edit session, even if the SQL
code resides in a copybook:

1. From the program – find, select and


Open the Copybook

2. From the opened Copybook, select


and Run the SQL

© 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:

Same techniques as when you code/test interactive SQL:

▪ Export to different media ➔

▪ RE-Sort the rows


– And then export, etc.
© IBM Corporation 85
Work with the Advanced DB2/SQL Tooling – Statements With :Host-Variables

▪ You can modify and re-run your SQL statements directly in the editor:

▪ You will be prompted for:


DB2 column data type:
▪ Only because you’re editing the SQL (inline)
▪ If your statements already contain
Host Variables the tooling will figure out
the type dynamically
Host variable value

© 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

▪ From the Context menu:


Select: Refresh SQL in Outline View
▪ This opens a new View showing:

▪ SCHEMA:
 Tables within the Schema
▪ SQL referencing the tables

Source: An Outline View of all the


SQL statements in your program

© 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

▪ From your SQL Outline View:


 Right-click over the SQL statement you
1.
want to Explain
 Select Open Visual Explain
 Two Explain Data dialogs will pop-up allowing
you to specify Plan_Table configuration/over-
rides.
 Note that you must have DB2 EXPLAIN
Authorization and may need CREATE Table
Authorization to build the Plan Tables. 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

Cost estimates for the query and


individual query phases
© IBM Corporation 91
Work with the Advanced DB2/SQL Tooling – Find (Table) in the Data Source Explorer
▪ Given the sheer number of DB2 tables you have to work with, it can be
time-consuming to navigate to the table you’re looking for – for any number
of reasons:
Need to see Sample data for a :Host-Variable value
Need to edit the table/modify a row, etc.
▪ The SQL Outline view makes this extremely easy:
Right-click over the Table 1.
And select: Find in Data Source Explorer ➔ 2.
This opens the Data Source Explorer – with your Table selected

© 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.

2. Open another program in the Editor 3.


3. Refresh SQL in the Outline view

4. Note the updated Schemas list –


expanded to include tables and
SQL from all combined programs

4.
© IBM Corporation 94
Work with the Advanced DB2/SQL Tooling – Table and Statement Filters – 1 of 2

▪ Filters are used to present organized DB2/SQL data access by:


Statement type
Named DB2 Object
▪ To access Filtered DB2/SQL elements:
Right-click over a table or SQL statement
Select Filter…

▪ Three filters:
1. Table/View name

1.
2. SQL Statement type
2.

3. Text inside SQL


statements 3.

© IBM Corporation 95
Work with the Advanced DB2/SQL Tooling – Table and Statement Filters – 2 of 2

Note: The EMPL table is showing above because


this SQL statement joins EMPL with PAY

Text Filters are written with Java


Regular Expression syntax

© 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

**For information on Optim Query Workload Tuner:


▪ http://www-03.ibm.com/software/products/us/en/optiquerworktunefordb2forzos/
© IBM Corporation 97
Tune SQL – Using Optim Query Workload Tuner
– 2 of 8
▪ After you launch Optim Query Tuning on an SQL
statement, IDz first checks to ensure that your
mainframe system is enabled and configured
▪ If it is, you will see a multi-step dialog, that allows
you to Select a series of Analysis tools to run
Tabbed steps in the Query Tuning Process and Results

© 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

© IBM Corporation 100


Tune SQL – Using Optim Query Workload Tuner – 5 of 8
▪ Optim will format your query – and describe various DB2 Access Path statistics

© IBM Corporation 101


Tune SQL – Using Optim Query Workload Tuner – 6 of 8
▪ Visual Explain is available – and access to the Explain Plan_Table data

© IBM Corporation 102


Tune SQL – Using Optim Query Workload Tuner – 7 of 8

▪ There are numerous cost estimating reports


▪ These are specific to the environment in which the query workload was run:
 I.E. – production DB2 subsystems are usually different from test, and thus cost estimates
will differ

© IBM Corporation 103


Tune SQL – Using Optim Query Workload Tuner – 8 of 8
▪ The Summary Report is a detailed list of recommended actions for indexing, query re-writing,
and other tuning approaches. It is well worth a look – although the information is technical

© IBM Corporation 104


Tune SQL – Using Optim Query Workload Tuner - Summary

▪ 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.

© IBM Corporation 105


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 for Managing Test Data & Decision Support
▪ Optional Workshops and Appendices

© IBM Corporation 106


Unload (Extract) Rows from a Table
You can unload (extract) test data rows before modifying a table's DDL, either for back-up purposes
or to share among team members or re-load later.

From the Data Source Explorer:


 Right-click over the table name
 Select: Data >
Extract…
 Specify data extract (unload) options:
▪ Output file-spec
▪ Column delimiter type
▪ Char-string delimiter type

To re-insert the rows, select: Load…


Select the same file, and follow script in reverse

© IBM Corporation 107


Extract – Data Format and Uses
The Extract process unloads row-values into “plain-text”. This makes them
available for use in standard MS-Windows technology.
Besides text (*.txt) files – you can extract into:
• Excel
• Extract to: *.csv
• MS-Word
• Extract to: *.doc
• PowerPoint
• Also for Decision Support applications

© IBM Corporation 108


Utilizing Extracted Data for Decision Support – Excel
▪ You can also
open extract
files into Excel
by simply
naming the
output file as:
<filename>.csv

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

© IBM Corporation 110


Modifying Extracted DB2 Table Values using ISPF Edit
After you have successfully Extracted DB2 Table values to a *.txt file:
 Find the file in Remote Systems ➔ Local ➔ Local Files
 Open With z Systems LPEX Editor
 Utilize ISPF techniques: Command Line commands (Find, Change, Picture String edit)
Prefix Area Commands: Repeat (to create new test data rows) Delete, eXclude, etc.
▪ Note that you can create new rows by duplicating existing rows, etc.
Prefix Area commands

• Save your changes


• Load the DB2 table from the file you’ve just modified
© IBM Corporation 111
 Workshop - Extracted Data for Decision Support Applications
▪ Extract a DB2 table into a file named with an extension of .csv
▪ From Remote Systems ➔ Local ➔ Local Files
 Find and Open the .csv extract file

▪ This should open Excel. If it doesn’t you’ll need to use


Preferences ➔ General ➔ Editors ➔ File Associations
to add a new File Association for *.csv and Associated editor

From here you have all the tools of Excel at your disposal

© IBM Corporation 112


Modifying Extracted DB2 Table Values using Excel – 1 of 2
▪ You can also open DB2 extract files using Excel – and modify row values with Excel
 Extract to a file named: *.csv
 Find the file in Remote Systems:
▪ Local
– Local Files
 Double-Click to open the file
▪ This should open the file into MS-Excel

© IBM Corporation 113


Modifying Extracted DB2 Table Values using Excel – 2 of 2
Modify the table values using Excel editing techniques

▪ Save your changes


▪ Load the Data back into the table

For Date/Time/Timestamp you


may have to Format the Cell type

This depends on your Excel vs.


DB2 Date/Time defaults
© IBM Corporation 114
Using Update-able Views to Edit Subsets of Large Tables – 1 of 2
▪ One of the current limitations of the IDz table editor is that – for very large
tables (100's of columns, 100's of 1,000's of rows) you cannot filter table data
▪ One solution for this is to create a view that renders the rows you want to
modify, and edit through the view (note that this is limited to version 8.0 and later)

▪ 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'

© IBM Corporation 115


Using Update-able Views to Edit Subsets of Large Tables – 2 of 2
▪ Steps – including screen captures:
1. Create an updatable view

2. Edit (through) the view:

3. Make changes

Ctrl+S
4. Save your edits

© IBM Corporation 116


Support for "Current SQLID"
You can SET the CURRENT SQLID (just as you do on QMF/SPUFI) in order to run
SQL statements with unqualified table/view names.

© IBM Corporation 117


®

IBM Software Group

IDz Workbench – Using the Data Source Explorer

Workshops

DevOps

© 2019 IBM Corporation


@Copyright IBM – March, 2019
Data Perspective Workshop – Using Your Company's DB2
If you are connecting to DB2 on your own LPAR, with the help of your DBA and/or
Systems Programming staff do the following:
1. Open the Data Perspective
2. Connect to a z/OS DB2 database
3. Filter the Schema to your table Owner name
4. Use the Data Source Explorer:
1. View some of the tables and their relationships through the Overview
Diagram
2. Show a table’s Sample Contents
3. Code a few simple SQL statements (or copy/paste from a COBOL program)
and run them in a SQL Query
4. Create a simple new SQL statement using the statement builder
5. Edit one of the DB2 tables you have update access to:
– Add a few new rows - Update some values - Delete one or two rows
– Save your changes – Ctrl/S

▪ 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

▪ Un-check: □ Disable Filter


▪ Enter: DDS0001
In: ◙ Expression name

© IBM Corporation 120


 Data Perspective Workshop – Data Source Explorer
When your connection create process finishes, you will be returned to the Data
Perspective, where you now can:
 Expand:
▪ Schemas
– Synonyms
– Tables
– Table elements Expand
– Views

 Explore and with the DB2 objects:


▪ Expand RESULTS
– Look at the various elements

© IBM Corporation 121


 Workshop – Data (Entity/Relationship) Analysis
Next try the "Overview Diagram"
 Select one or more tables
 Right click and select: Add to Overview Diagram
 Click OK
▪ This opens an Entity/Relationship analysis view

You can also work with a Table, View or Synonym's DDL:


▪ Try the following with the CUST table:
1. Extract table data to a comma delimited file on your workstation
2. Generate the DDL for your table
 Be sure to:
 Browse and select one of your chapter folders
 Check the option to  Open the DDL file for editing

© IBM Corporation 122


 Workshop – View, Analyze, Export Data
To view your DB2 table data and export reports from it:
▪ Select the table or view you wish to edit. Right click and select: Data > Sample Contents

Sort
your
results
Export your
results

© IBM Corporation 123


 Workshop – Read/Only View of a Table's Row Values
▪ From the Data Source Explorer, Right-click over CUST and
▪ Browse the Data and Sample Contents
▪ Try out: New “Select” Script
▪ Press <F5> to run the Select script
▪ Value Distributions > Multivariate
▪ Repeat these steps with one or two other tables

▪ 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

© IBM Corporation 124


 Workshop Edit Tables

To edit your DB2 table data:


▪ Select the table or view you wish to edit
▪ Right click and select: Data > Edit
▪ Note that you can open (edit) multiple tables. And project them out in multiple window views –
so that you can analyze data, or copy/paste values from one table to another

If you wish to edit


subsets of large tables
you can use the Optim
Data Studio 3.1.1 – which
© IBM Corporation 125
is a free IDz plug-in
 Workshop – Table Filtering
From the Data Source Explorer
 Right-click CUST
 Select: Data > Edit Data
 Click: Filter the data

This opens the Table Data Filter dialog…

Use the dialog to:


 Add > Several columns

 Add Row Selection


 Click Add
 Open the Column
drop-down
 Open the Operator
drop-down
 Specify a search value

© IBM Corporation 126


 Workshop – Testing Interactive SQL Statements
▪ Click New SQL Script
 Type in SQL statements
 Right-click over the
Content Area and
select: Run SQL
 In the Results, for
multiple statements you
can expand and select
one at a time
 The Result1 tab shows
statement results
 You can Export results

Optional
▪ Copy and all of the commented
SQL statements in the Slide
Notes
▪ Try other Context Menu
selections like Format SQL

Statement Run Console Data Results

© IBM Corporation 127


 Workshop – Testing Embedded SQL Statements – 1 of 2
▪ From the Remote Systems view:
 Open <HLQ>.TEST.COBOL(CURSRAVG)
 Right-click and from the Context menu select: Filter view > Embedded SQL/CICS/DLI
 Select and Copy the Interactive portion of the SQL SELECT statement in this paragraph –
minus all of the embedded COBOL syntax (shown below in the screen capture)

© IBM Corporation 128


 Workshop – Testing Embedded SQL Statements – 2 of 2
▪ Swap back to the script editor and paste the copied embedded SQL inside
the SQL script editing area
▪ Right-click and select Run SQL

▪ Try adding an additional where clause predicate


 What happens when you run the query?

© IBM Corporation 129


 Workshop – Testing Embedded SQL Statements
If you are shell-sharing with IBM Data Studio 4.1 – return to slides 57 ➔ 93 in
this slide deck and:
1. Create connections – to DB2 and through Remote Systems Explorer (RSE)
2. Create a Property Group for the RSE connection to pick up your copybooks and DCLGEN
includes
3. Create an MVS Subproject – and copy a few DB2/COBOL programs into the Subproject –
from the COBOL programs you copied to the host from IDzClass:
 CURSRAVG.cbl
 TRTMNT.cbl
 CADDDB2.cbl
4. Add Data Access Development Support to the Subproject
5. Open a DB2/COBOL program – and start following the use cases shown on slides:
72 ➔ 84 in this slide deck, but using your own SQL statements/DB2 tables and views, etc.
 Note that you may need your DBA’s assistance for doing things like creating the
EXPLAIN/Plan Tables, etc.
6. You can use IBM’s Optim Workload Query Tuner – which is installed on the zserveros:
 And start following the use cases shown on slides: 85 ➔ 93 in this slide deck
 Use the SQL statement

© IBM Corporation 130


 Workshop – Testing Embedded SQL Statements - with IBM Data Studio 4.1
Open to slide 57 in this PowerPoint.
Follow the slide instructions/screen captures and do the following:
1. Create connections – to DB2 and through Remote Systems Explorer (RSE)
2. Create a Property Group for the RSE connection to pick up your copybooks and DCLGEN
includes
3. Create an MVS Subproject – and copy a few DB2/COBOL programs into the Subproject
– from the COBOL programs you copied to the host from IDzClass:
 CURSRAVG.cbl, TRTMNT.cbl, CADDDB2.cbl
4. Add Data Access Development Support to the Subproject
5. Open a DB2/COBOL program – and start following the use cases shown on slides:
72 ➔ 84 in this slide deck, but using your own SQL statements/DB2 tables and views, etc.
 Note that you may need your DBA’s assistance for doing things like creating the
EXPLAIN/Plan Tables, etc.
6. If you are using the zserveros you can use IBM’s Optim Workload Query Tuner:
 Start following the use cases shown on slides: 85 ➔ 93 in this slide deck
 Tune the SQL statement
 From: CURSRAVG.cbl

© IBM Corporation 131


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 132


Topic Summary
▪ Now that you have completed this topic, you should be able to:
 Launch the Data Perspective
 Connect to a Data Source
 Use the Data Source Explorer to:
▪ View tables and relationships
▪ View sample table rows and values
▪ Edit (create, update, delete) row values
▪ Test interactive SQL
▪ Code/Build SQL statements
▪ Generate Table DDL

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

© IBM Corporation 134


Optional Topics and Workshops For This Section
▪ If you have time, and are comfortable with the material covered, or if you
are part of an IDz "Tools Team" and need deeper content – or if you just
have "mad SQL skills" please read through the next series of slides – and
try out the techniques shown using IDz and sample programs in your
IDzClass project.

© IBM Corporation 135


Optional Topic - Exploring Meta Data
By selecting meta-data elements and then selecting the Properties view you
can see
▪ Examples:
The Properties/Details of an index design

The Properties/Details of a Foreign Key relationship between two tables

© IBM Corporation 136


Optional Topic – Working with/Understanding DB2 Views
By selecting the DB2 View and then selecting the Properties view you get:
▪ Dependencies:

▪ You can see the SQL that was used to create the View (DDL)

▪ And most of the Data features


work with Views ➔

© IBM Corporation 137


Filtering/Re-Filtering The Data Source Explorer
You can filter Schemas when you create your
connection to DB2. But you can change or re-filter
your DB2 objects dynamically (at any time)

▪ To re-filter your data objects:


Select the connection
Right-click and select Properties

▪ From Properties you can re-filter:


Schema names
Stored Procedures
Tables

Steps:
▪ Select the filter
▪ Un-check Disable filter
▪ Specify your new filter
▪ Click OK

© IBM Corporation 138


(Data Model) Overview Diagram– 4 of 5 (optional features)
If you are a database administrator (acting database administrator for your local copy of a database) or data
modeler/data analyst you might be interested in other context menu options:

▪ Enhance your data module with the Diagram Tool:


 Right-click over the RESULTS entity
 Select:
▪ Add note
▪ Type text into the edit area
▪ When finished,
– Click the diagram again with your mouse
– You can delete the note by selecting it
– Right-click and select Delete

 Other context menu options of interest:


▪ Right click over the white space (not over an entity)
▪ Zoom
– In or out to scale
▪ File
– Save image

© IBM Corporation 139


(Data Model) Overview Diagram– 5 of 5 (Properties View)
Another useful
Overview Diagram
feature is:
Show
Properties
View
– which displays
meta data for:

▪ Tables

▪ Relationships
(click the lines drawn
between the entities)

▪ Views

© IBM Corporation 140


Optional - DBA and SQL Programmer/Analyst Feature – Analyze Impact
▪ For tables with DB2-enabled "Referential Integrity"
Select a table (either parent or child table)
▪ Note that the table should have constraints
Right-click and select: Analyze Impact…

Select the type of impact analysis to perform


▪ Only children objects
▪ Only parent objects
▪ Both children/parent objects
Click OK

▪ Read the Model report produced


Dependent Object is the "child" table or view that will be impacted
"Impactor Object" is the parent table or view (of what has been analyzed)

© IBM Corporation 141


DBA and SQL Programmer/Analyst Feature –
DB2 Object Compare
▪ Detailed comparison tool for analyzing
differences between tables, views, etc.
▪ Side-by-side graphical results – from DB2
System Catalog
▪ Can span multiple connections – I.E. Compare a
table in Test with one in Production

© IBM Corporation 142


Optional - SQL Results View
Additional options exist to Re-sort, save and reuse the results set:
▪ Re-sort the result rows from a query, Sample Data, etc.

▪ Other result row options


 Right-click over the rows in the SQL Results view (and/or press the Shift
key and select multiple rows)
 You can:
▪ Copy rows and Paste specific results rows into Notepad file
▪ Export results rows (next slide)
▪ Save results rows
▪ Convert Hexadecimal
– Note that this options shows:
– ASCII hex characters for CHAR and VARCHAR data
– Actual binary value - for INT, SMALLINT data

© IBM Corporation 143


Optional – SQL Results Set Options
▪ Export All vs. SQL Output Preferences
Data Management > SQL Development > SQL Results View Options allows you to
specify the Max display row count – which is the number of rows that you see in SQL
Results
▪ However, Export > All Results... will export all DB2 rows matching your
statement’s criteria - I.E. this over-rides the Max display row count setting

▪ Export Selected Rows...


Most of the time you’ll Export All Results.
But if you use Selected Rows, you can
▪ Sort by Column
▪ Export Selected/Sorted Rows.

▪ By working with the Display Results options you can create an output report
that combines queries and results in one file (like SPUFI output)

© IBM Corporation 144


Writing SQL Against any DB2 Connection
Data Source Explorer also has the New SQL Script functionality as an icon on the toolbar
 From the Data Source Explorer
 Click the New SQL Script icon

 Choose a Database connection


▪ Note that this is the difference from the prior slide – that you can choose a connection

 Using Content Assist – create your statement one SQL element at a time
▪ Some SQL syntax errors are flagged dynamically

© IBM Corporation 145


SQL Statement GUI-Development
▪ An alternative to SQL statement
development using Content Assist is to
use a Data Development Project, which
enables you to do graphical SQL
development
 This can be a useful feature if some of
your development staff are new to SQL

▪ Steps:
From the Data Project Explorer
Right-click and select:
▪ New > Data Development Project

Name the Project

Select a Connection

Click: Finish

© IBM Corporation 146


SQL Statement GUI-Development – continued
▪ From the Explorer:
Right-click over SQL Script and select:
▪ New > SQL or XQuery script
▪ Name the script
▪ Select the Statement type
This will open a new SQL editor

Select  SQL Query Builder

Note – Other statement types include:


 Insert
 Update
 Delete
 FULLSELECT (Union / Union All)
 WITH (Statements built using temporary
tables)
© IBM Corporation 147
SQL Statement GUI-Development – continued
Using the editor you can follow the prompts and
layout to create SQL statements graphically

▪ Add a new table

▪ From the list of columns select one or more


columns to add

© IBM Corporation 148


SQL Statement GUI-Development – continued
▪ From the Conditions tab, add a
WHERE clause

▪ Note that you can:


Select a column, Operator, Value,
AND/OR from a drop-down list box

▪ Or you can type the statement


portions (and the graphical view will
synchronize)

Right-click over the statement


and select Run SQL to test

Note that you will definitely have


to understand SQL to use this tool
© IBM Corporation 149
Graphical SQL Script Builder – Joining Tables
▪ A terrific use of the GUI SQL-builder is in creating statements that join tables.
By adding more than one table, the tool will create the SELECT and FROM clauses.
By selecting: Create Join… you can specify the Where clause aka: "Join Condition"

 Note the graphical


rendering of the joins
as connections
between the tables

© IBM Corporation 150


Graphical SQL Script Builder – Reverse Engineering SQL Statements to Graphics
Just as the SQL Script Builder will generate SQL out of your GUI building
process, for certain SELECT and INSERT statements it will also show
elements of your statements graphically, if you start with the SQL

▪ Steps:
1. Create a new statement

2. Type in your statement ➔

3. Click inside the GUI areas ➔


Your statement is displayed graphically

▪ IDz will show different GUI


elements, as you type

This works best with:


SELECT
INSERT
© IBM Corporation 151
 Relative SQL Performance Benchmarks
▪ You can use the facilities of the Data Perspective creatively, to benchmark different SQL
designs. Steps:
 Create a series of SQL statements
▪ Sandwich each SQL design between a SELECT of the
current timestamp (as shown)
▪ After you run your statement series use the timing
data to determine the "relative" performance results
of each design

▪ Optionally –
copy the Result
rows to an external
file for further
analysis

Expand Script Status


Entry ➔

© IBM Corporation 152


More Relative SQL Performance Benchmarks – Using Query execution time

▪ You can use the facilities of the


Data Perspective creatively, to
estimate the effect of different SQL
coding approaches on execution time

▪ Steps:
 Using the SQL Script editor, code
and run your statement

 Note the Query execution time in


the Status tab

Try different coding approaches


Note the relative differences in Query execution time

© IBM Corporation 153


Optional Topic – Using DB2 Explain
▪ Provided that you have
rights to access a
PLAN_TABLE, you can
use the Data Tools to
execute traditional DB2
Explain statements ➔

▪ Notes:
 Plan_Tables are DB2
version specific
 There is a Visual Explain
product from IBM that
plugs into Eclipse

© IBM Corporation 154


Selecting Rows from the DB2 System Catalog (SYSIBM.SYSxxx) – 1 of 2
▪ Provided you have DB2 catalog access privileges, the tables and views in
the DB2 System Catalog (SYSIBM.SYSINDEXES, SYSIBM.SYSTABLES, etc.) can be
queried

▪ 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

© IBM Corporation 155


Selecting Rows from the DB2 System Catalog (SYSIBM.SYSxxx) – 2 of 2
(Again) Provided you
have DB2 catalog
access privileges, you
can also use the Data
Source Explorer to
browse the catalog
tables

Note that in order for the


Data Source Explorer
to provide this meta-
data you will need to
access the schema:
SYSIBM in your
connection

© IBM Corporation 156


Preferences to Code SQL Statements Against the System Tables
▪ From:
Window > Preferences
Data Management
SQL Development
SQL Editor
Code Assist

…You can customize your workspace


for easier SQL statement editing
against the system tables

© IBM Corporation 157


Optional Topic – Using a Functional (Generic) TSO ID & Password
Some shops have setup a functional – or generic TSO ID, that you need to
login as – in order to access Tables/Views. You can dynamically change
your TSO User Name/PWD as follows...

Right-click the Connection


Select Change User Names and Passwords

© IBM Corporation 158


Optional Topic – Enabling Property Groups for Local Syntax Check of DB2 – 1 of 3
(Assuming you have DB2 Connect installed or are using a local UDB database) –
To setup Local Property Groups file for DB2 Local 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 either:
– A UDB database
– A connection to a DB2
– We will be describing how to create connections to DB2 in an upcoming module
▪ Note that, with EXEC SQL statements enabled, IDz validate your DB2/SQL
references in your source
SQL Options can be used to further customize your Local 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 159
Optional Topic – Enabling DB2 for Real-Time Validation – 2 of 3
If you want to remove Real-Time validation errors for unqualified SQL statements:
1. Select your Database Connection – Right click and select Properties
2. Select Driver Properties – and specify a Default schema:

© IBM Corporation 160


Optional Topic – Enabling Property Groups for Local Syntax Check of DB2 – 3 of 3
If you try and syntax check at this
point, it may not work.

Because, unless you created the


UDB database using the same
ID as your Schema Name
(which is unlikely) you will
receive permission errors ➔

To clear these up, you can open a


new SQL Script and issue
GRANT statements – granting
the SQL operation in your
statements – or possibly SQL
Bind and Createtab

© IBM Corporation 161


 Workshop – Enabling a Local Project for Copybook Access
1. Click (select) your new copy folder,
and from the Properties view
▪ Right-click over location
▪ Select Copy

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

Notes 1. Do this workshop if you are using the


IDzClass project as the source for your program code

2. An alternative to entering the fully-qualified directory


name for SYSLIB, is to type in the following environment
variable: ${project_loc}\copy
© IBM Corporation 162
 Optional Workshop 1 – Using the SQL Script Builder to Join Tables
For a review of this material see the slides in this deck with "SQL Statement – GUI Development"
in the slide header
▪ Workshop steps:
 From the Data Project Explorer
 Right-click and select: New > Data Development Project
 Name the Project
 Select a Connection
 Click: Finish
▪ From the Explorer:
 Right-click over SQL Script and select:
▪ New > SQL or XQuery script
▪ Name the script
▪ Select the Statement type
 This will open a new SQL editor
▪ From the SQL query:
 Add the following tables (all owned by: DDS0001): Entrants, Events, Results
▪ Note – its' a good idea to use Table Aliases – especially in table join statements
 Right-click over Entrants, and join Entrants to Results on the Entrant.Name = Results.Name
 Right-click over Events, and join Events to Results on the Event.Number = Results.Number
 Modify the SELECT statement's SELECT clause to return specific columns
 Run the statement – and review the output
 Optionally:
▪ Add an additional WHERE clause
▪ Sort the results rows
© IBM Corporation 163
 Optional Workshop 2 – Using the Script Builder to Reverse Engineer a Statement
For a review of this material see the slides in this deck with "Reverse Engineering SQL Statements
to Graphics" in the slide header
▪ From the Explorer:
 Right-click over SQL Script and select:
▪ New > SQL or XQuery script
▪ Name the script
▪ Select the Statement type: SQL
 This will open a new SQL editor
From the SQL query statement area Query statement area

 Code or paste the statement shown:


▪ The code is in the slide notes
 Check out the Reverse Engineering
 Run the statement

▪ Try coding any of your own SQL:


 Joins
 Complex single-table queries

SELECT E.DEPT, MIN(E.PERF), MAX(E.PERF),


AVG(E.PERF), MIN(P.HOURS),
MAX(P.HOURS), AVG(P.HOURS)
FROM DDS0001.EMPL AS E, DDS0001.PAY AS P
WHERE E.NBR = P.NBR
GROUP BY E.DEPT
© IBM Corporation 164
 Optional Workshop – Accessing the System Catalog Tables
For a review of this material see the slides in this deck with
"Selecting Rows from the DB2 System Catalog" in the slide header
▪ Create a new connection to DB2:
 Your DB2/zOS instance, or the IBM zserveros/DB2 instance
 Specify the high-level Schema: SYSIBM
From the new connection, copy & paste the following statements or code SQL scripts
(using content assist) to discover:
▪ What views exist that were created by my team:
 Select * from SYSIBM.SYSVIEWS where creator like 'DDS%'
▪ What plans exist that DDS0001 can execute:
 Select * from SYSIBM.SYSPLANAUTH Where GRANTEE = 'DDS0001'
▪ The proper join condition (Primary/Foreign Key) of two DB2 tables:
 SELECT B.REFTBNAME AS PARENTTABLE,COLNAME FROM SYSIBM.SYSFOREIGNKEYS A, SYSIBM.SYSRELS
B WHERE A.RELNAME = B.RELNAME AND B.TBNAME = 'HOSP_BED' AND B.REFTBCREATOR = 'DDS0001'
AND B.REFTBCREATOR = A.CREATOR;
▪ What indexes exist for tables that participate in a DB2 Join:
 SELECT I.NAME, I.TBNAME, K.COLNAME, K.ORDERING FROM SYSIBM.SYSINDEXES I, SYSIBM.SYSKEYS K
WHERE I.TBNAME IN('WARD_DATA','HOSP_BED') AND I.NAME = K.IXNAME;
▪ The primary key of several DB2 tables:
 SELECT NAME FROMSYSIBM.SYSCOLUMNSWHERE TBNAME = 'WARD_DATA'AND TBCREATOR =
'DDS0001'AND KEYSEQ > 0 ORDER BY KEYSEQ ASC
▪ The column names and data types from two tables: WARD_DATA and EMP_DATA:
 SELECT NAMEFROMSYSIBM.SYSCOLUMNSWHERE TBNAME = 'WARD_DATA'AND TBCREATOR = 'DDS0001'

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

Setup (from Remote Systems Explorer):


z/OS File System Map a PDS where you have SPUFI/SQL statements to a type
of sql
▪ See the slide deck titled: IDz Workbench – Using Remote Systems
Explorer for help with this
Create and open (edit) a member of this PDS
From the Connection profile:
– Select the database/connection
– Note you may need to revisit the Data Perspective to find which database Type to select

© IBM Corporation 166


 Advanced Workshop – SPUFI Emulation – 2 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 – like you currently do with SPUFI

 Map your SPUFI file to a type of sql


z/OS File System Map a PDS where you have SQL statements you've used with
SPUFI to a PC file type of sql
▪ See the slide deck titled: IDz Workbench – Using Remote Systems Explorer for
help with this

© IBM Corporation 167


 Advanced Workshop – SPUFI Emulation – 3 of 6
Code your statements and select: Execute All
▪ This opens the SQL Results view within z/OS Project - and allow you
edit/test/analyze:

Optionally you may:


Execute only a selected statement ➔

Edit a statement in the GUI SQL builder ➔

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

© IBM Corporation 169


 Advanced Workshop – SPUFI Emulation – 5 of 6
An optional exercise to use the graphical SQL development features:
 Select the entire query from the sql file.

 Right-click and select:


Edit in SQL Query Builder ➔
© IBM Corporation 170
 Advanced Workshop – SPUFI Emulation – 6 of 6 – Dealing with Line Numbers
If you want to use a
SPUFI file from the
mainframe, and
COBOL Numbers
were created by
TSO's file statistics,
you can delete the
numbers as
follows:

1. Open the file using the LPEX Editor ➔


Issue the following ➔ c all p'=‘ ' ‘ 73 80

Close and save your


changes

4. Reopen the file with the SQL File Editor

© IBM Corporation 171


®

IBM Software Group

IDz Workbench – Using the Data Source Explorer

Appendices
- Connecting to DB2/UDB
- Connecting to a Derby database
- Using Data Studio 3.1.1
Back-up Slides

© 2019 IBM Corporation


 Data Perspective Workshop – DB2/UDB
▪ From this URL: http://www.ibm.com/developerworks/downloads/im/udb/
1. Download and install UDB on your workstation

2. From IDz and the Data Perspective


▪ Create a new connection to the UDB SAMPLE Database
– See next slide for help with this
▪ Select and copy the SQL statements in the slide Notes
▪ Create a new SQL Script to the UDB SAMPLE Database
▪ Run the script against the SAMPLE Database
▪ Refresh the SAMPLE Database in the Explorer

© IBM Corporation 173


 Advanced Workshop – SPUFI Emulation – 2 of 6
▪ Create and open (edit) a member of this PDS
▪ Right-click and select: Set Connection Info
▪ From the Connection profile:
▪ Select the database Type: DB2 UDB zSeries …
– Note you may need to revisit the Data Perspective to find which database Type to select
▪ Name: <your z/OS DB2 connection name>

▪ Select the Database: from the drop-down control

© IBM Corporation 174


 Creating a new Connection to UDB
▪ You will need the:
Database name: SAMPLE
Host + Port number ➔
▪ IP address if shared/network
or mainframe DB2
– Note that the default port is:
50000
▪ localhost if on your Windows
machine
User ID
Password

▪ Recommend that you save the


password properties

© IBM Corporation 175


 Using UDB
▪ If you've successfully executed the
SQL DDL against the UDB/SAMPLE
database you should get the relational
objects described in this unit to work
with
▪ But note that the UDB/SAMPLE
database comes with additional:
Schemas
Objects, including:
▪ Stored Procedures
▪ Additional tables/views/etc.

© IBM Corporation 176


 Data Perspective Workshop – Derby
If you do not have access to the RAD product on your
workstation, you can do the following with an open-source
DB2/SQL DBMS named Derby:
 Obtain the file: EGLDerbyR7.zip from your instructor

 Unzip this file on your workstation in a directory named: \databases\ –


wherever you have admin rights to create a file (your C: or D: drive, etc.)

 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

© IBM Corporation 177


 Data Perspective Workshop – Derby
From the New Connection wizard:
1. Select Derby
2. Select the BIRT SampleDb Derby Embedded Driver JDBC driver
(it's the default)

2.
1.

3. Click Test Connection


3.
4. Click: Finish 4.

© IBM Corporation 178


 Data Perspective Workshop – Derby
When your connection create process finishes, you will be returned to the Data
Perspective, where you now can:
 View some of the tables and their
relationships using the Overview Diagram
 Recall that from the Overview Diagram
you can try: Add Note and/or Zoom
Expand

© IBM Corporation 179


UNIT The IDz Workbench
Topics: Optim Data Tools
▪ Using Visual Explain
▪ Test Table Subsetting

© IBM Corporation 180


 Optim Tools – Create a Connection – 1 of 2
▪ Open the Data
Source Explorer

▪ Create a new
connection to a
mainframe z/OS
Database

© IBM Corporation 181


 Connection – 2 of 2
▪ Specify your connection
criteria

▪ Click Next > twice

▪ Select your Schema filters


and click Finish

© IBM Corporation 182


 Visual Explain and SQL Query Tuning

▪ 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

▪ We will cover the use of both of these options in the slides

© IBM Corporation 183


 Visual Explain – 1 of 3
▪ From the Data Source explorer – Right Click and select New SQL Script
▪ Type in your SQL statement (or copy/paste from an application program)

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 ➔

From: Collect Explain Data

▪ 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.

You will want to



manipulate the view Mouse-over the individual
widths – to better see and graphics to drill into
understand the results
© IBM Corporation
access path details
186
 Optim – SQL Tuning
▪ From the Data Source
view
Right-click over your
connection
Select Analyze and Tune
> Start Tuning…

▪ Depending on the DB2


release you're working
with, you may get a
warning message
Click OK Recall that Query
Tuning requires
IBM InfoSphere, in
addition to IBM
© IBM Corporation 187 Data Studio client
 Optim – Query Tuning Project
▪ You will proceed through the steps in the Query Tuning Project
The initial Configuration page shows what tuning options are available to you
The steps progress through tabs
Query Tuning Progress Tabs

Global tuning options

© IBM Corporation 188


 Optim – Query Tuner Workflow Assistant – Overview
▪ From the Query Tuning Workflow Assistant: Click Capture

▪ Enter your SQL Statement and click: Invoke Advisors and Tools

Input options (for statement tuning)

© IBM Corporation 189


 OPTIM -

▪ Click: Select What to Run…


 Select the tuning activities to run against your query ➔
 Click OK

▪ 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

You can save the tuning advice for future analysis


Recommendations
Specific Tuning

© IBM Corporation 191


 Review Access Plan Graph
▪ Select Open Access Plan Graph – this opens the
graph depicting all of the stages of the DB2 access
path employed by the Optimizer
▪ Note that you will need to understand relational
access path theory to understand the nuances shown

Mouse over
the activities
and outcomes
of the access
path for
details of the
Optimizer's
decisions

© IBM Corporation 192


 OPTIM – Access Plan (Detailed) Explorer
▪ There are additional DBA-level tuning reports

Reports on the Nested Loop Join –


including (not shown) Total, CPI
and IO cost
© IBM Corporation 193
Notes: The Access Path and
Plan reports and graphs are
also DBA-oriented. And they
require a DBA auth-level

© 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

© IBM Corporation 195


 Optim – Test Table Subsetting
▪ Optim allows you to choose columns and
create SQL "Where Clause Predicates" to
filter rows
▪ This allows you to subset large test tables
for data access and update
▪ You'll start by creating a table filter

▪ Steps:
Assuming you're connected…
 Expand your Database location
 Expand Schemas
 Expand the Schema you wish to filter


 Right-click Tables
 Select Properties

This will open the Catalog


Table Filter
© IBM Corporation 196
 Table Filter
▪ Specify your table
filter selection
Click the
 Selection radio
button

▪ Check the table


names you want
included in your
filter

▪ Note that you could


also have checked
Expression and typed
in a LIKE (Where)
clause to filter table
names via wildcard
pattern

▪ Click OK

© IBM Corporation 197


1. Open the
 Select a Table for Subsetting Administration Explorer
View

▪ A few more selection steps…

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

© IBM Corporation 198


 Table Data Filter
From the Toolbar click: Filter the data

▪ From Table Data Filter

 Select Columns to show

 Add Row Selection Conditions

Specific Tuning
▪ Click OK Recommendations

© IBM Corporation 199


 Edit values through your Table Data Filter
You can now edit through the table
subset criteria
Commit Changes
Modify row/column filter
This table editing functionality is
the same as IDz's "Edit table" –
in that you can:
Modify row values
Delete rows
Add new rows

Click the Commit Changes icon


(or press Ctrl+S) to save your
table edit values

© IBM Corporation 200


UNIT The IDz Workbench
Topics: Optim Data Tools
▪ Using Visual Explain
▪ Test Table Subsetting
▪ Backup Slides

© IBM Corporation 201


Backup Slides

© IBM Corporation 202


Creating a new Driver Definition
▪ If you want to connect to
Oracle, SQL Server,
Sybase, MySQL, etc.
you will need to define
and configure the
JDBC driver from:
Preferences ➔
 Data Management ➔
▪ Connectivity➔
– Driver Definitions➔

▪ You will need the Jars,


and Jar properties in
order to build the
connection.....

© IBM Corporation 203


Native Stored Procedures/Data Studio
Native Stored Procedure development is delivered in Data Studio
- which is also used to debug Stored Procedure. Step-for-step
tutorial…
https://www.ibm.com/support/knowledgecenter/SS62YD_4.1.1/com.ibm.datatools.routines.tutorial.doc/topics/routines_lesson3.html

For training on this topic, see:


204
https://www.themisinc.com/CourseDetail.aspx?id=DB1029
© IBM Corporation
The Data Source Explorer – in the Data Perspective
All of your work in the Data Perspective is done through a database
Connection. In this course our Data Source Explorer screen
captures show four connections – your machine may have more or
less, depending on the databases you have access to.
▪ In the Data Perspective, you can define a new Connection or
reconnect to a database through an existing connection (like the one
you’ve been using in debug, and used for the SQL Access Application
import earlier in this course)

▪ When “connected” you can:


 Expand folders
 Use the Data Perspective
▪ Tools
▪ Views
▪ Wizards

 Data Studio
version of Data
Source Explorer

© IBM Corporation 205

You might also like