training & consulting db2 for z/os: utilities and ... for z/os: utilities and application...

36
TRAINING & CONSULTING DB2 for z/OS: Utilities and Application Development ABIS Training & Consulting www.abis.be [email protected] 2005, 2006 Document number: 0092_03b.fm 11 January 2006 Address comments concerning the contents of this publication to: ABIS Training & Consulting, P.O. Box 220, B-3000 Leuven, Belgium Tel.: (+32)-16-245610, Fax: (+32)-16-245691 © Copyright ABIS N.V.

Upload: lymien

Post on 20-Apr-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

TRAINING & CONSULTING DB2 for z/OS: Utilities and Application DevelopmentABIS Training & [email protected]

2005, 2006

Document number: 0092_03b.fm11 January 2006

Address comments concerning the contents of this publication to:ABIS Training & Consulting, P.O. Box 220, B-3000 Leuven, BelgiumTel.: (+32)-16-245610, Fax: (+32)-16-245691

© Copyright ABIS N.V.

D iii

T

U

1

2

3

4

B2 for z/OS: Utilities and Application Development

ABLE OF CONTENTS

TILITIES & APPLICATION DEVELOPMENT 5

____Introduction ____________________________________________________61.1 Utilities and application-related functionality 61.2 Utility processing versus SQL processing 71.3 Usability 81.4 Alternative: dropping indexes 9

____Supported functionality __________________________________________102.1 UNLOAD utility for READ activities 102.2 LOAD utility for WRITE activities 132.3 REORG utility for REMOVE activities 152.4 REORG utility for REWRITE activities 16

____Examples of simple scenarios_____________________________________173.1 Adding many rows 173.2 Copying many rows 193.3 Deleting many rows 22

____Examples of mixed scenarios _____________________________________244.1 Deleting many parent rows 244.2 Use of INCURSOR 264.3 INSERT after complex control 294.4 Utilities and remote access 33

D iv

B2 for z/OS: Utilities and Application Development

ABIS Training & 5

UtilitieDevelo

between SQL processing and the execu-

tions that can replace SQL processing

plex examples how and when you can lity

Consulting

s & Application pment

Objectives :

• to introduce the main differencetion of utilities

• to give an overview of utility func

• to show with simple and more comtake advantage from this functiona

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 6

Introduction 1

Utilities and application-related functionality 1.1

B2 for z/OS: Utilities and Application Development

UNLOAD:· for READ actions

LOAD:· for WRITE actions

REORG:· for REMOVE actions

REORG PAUSE or UNLOAD - (RE)LOAD:· for REWRITE or COMPLEX actions

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 7

Utility processing versus SQL processing 1.2

SQL modifications:

• a lot of overhead :

- logging

llifies)

F

B2 for z/OS: Utilities and Application Development

- locking

- on the fly:· index maintenance· referential integrity control (and/or actions: cascade/nu

In addition, if large amount of modifications:

---> often, a REORGANISATION needed

or simple actions on 1 table:

---> UTILITIES are much cheaper· most actions directly on VSAM files

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 8

Usability 1.3

In general:

- for simple actions on high volumes· stand-alone tables and activities

th utility

B2 for z/OS: Utilities and Application Development

- if application activity is always (or often) combined wiprocessing· e.g. batch job followed by a REORG

- if asynchronous execution is allowed· e.g action is not a part of a larger transaction

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 9

Alternative: dropping indexes 1.4

If SQL is needed for the modifications· more tables involved in the process

· SQL functions needed

A

sing

B

B2 for z/OS: Utilities and Application Development

· ...

using utilities is no option any more

lternative:

- DROP the INDEXES that cause overhead, before proces· indexes that are maintained ‘in flight’· and not needed for the process itself

- CREATE them again after processing

E prepared for INVALID application plans and packages

- Ask a REBIND for these plans/packages:· check the related access paths (EXPLAIN)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 10

Supported functionality 2

UNLOAD utility for READ activities 2.1

• Example of a “Select of many rows”

04’)

B2 for z/OS: Utilities and Application Development

- one scan of the input data set(no indexes are used)

- selected rows are written as records in an output file

- base table stays intact and available (see SHRLEVEL)

Remark:· UNLOAD utility = COPY of a formatted SUBSET · COPY utility = exact replication (backup)

UNLOADTABLESPACE TBD7971.TBSSTMODFROM TABLE STOCKMODIFICATIONS

(SMID, SM_PRNO, SMTIMESTAMP, SMQUANTITY)WHEN (SMTIMESTAMP BETWEEN ‘01.01.2004’ AND ‘31.12.20

SHRLEVEL CHANGE ISOLATION UR

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 11

UNLOAD utility for READ activities (I)

• Additional possibilities:

UNLOADTABLESPACE TBD7971.TBSSTMOD

04’)

B2 for z/OS: Utilities and Application Development

FROMCOPYDDN DB2COPY1FROM TABLE STOCKMODIFICATIONS

SAMPLE 5 LIMIT 2500(SMID, SMTIMESTAMP TIMESTAMP EXTERNAL , SMCOMMENT VARCHAR STRIP TRAILING )

WHEN (SMTIMESTAMP BETWEEN ‘01.01.2004’ AND ‘31.12.20PUNCHDDN DB2PUNCHDELIMITED COLDEL ‘,’SHRLEVEL CHANGE ISOLATION UR

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 12

UNLOAD utility for READ activities (II)

- FROMCOPYDDN· to use an IMAGE COPY as input

- PUNCHDDN

B2 for z/OS: Utilities and Application Development

· to create corresponding LOAD utility statements

- SAMPLE - LIMIT· to limit the number of output records

- TIMESTAMP EXTERNAL - VARCHAR STRIP TRAILING· to format output fields

- DELIMITED COLDEL ‘,’· to format output records

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 13

LOAD utility for WRITE activities 2.2

• Example of an “Insert of many rows”

LOAD DATARESUME YES

B2 for z/OS: Utilities and Application Development

- input records are added as rows to the table(space)

- new index entries are sorted

- they are merged with the existing entries

- corrections are done for:· duplicate keys

· R.I. violations

SHRLEVEL NONEINTO TABLE STOCKMODIFICATIONSFORMAT UNLOAD or <FIELD-specifications>

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 14

LOAD utility for WRITE activities (II)

• Additional possibilities:

LOAD DATALOG NO NOCOPYPEND

B2 for z/OS: Utilities and Application Development

- LOG NO NOCOPYPEND - ENFORCE NO· less overhead - faster processing· only for controlled data

- SHRLEVEL CHANGE:· no solution for performance

(= mass insert with in flight maintenance of indexes)

ENFORCE NORESUME YESSHRLEVEL CHANGEINTO TABLE STOCKMODIFICATIONSFORMAT UNLOAD or <FIELD-specifications>

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 15

REORG utility for REMOVE activities 2.3

• Example of a “Delete of many rows”

le

ace)

d indexes

REORG TABLESPACE TBD7971.TBSSTMODLOG NO SORTKEYS COPYDDN(SYSCOPY)

B2 for z/OS: Utilities and Application Development

- one scan of the input data set (tablespace)(clustering index may be used)

- non-discarded rows are written as records in an output fi

- they are rewritten in clustering sequence into the table(sp

- remaining index entries are sorted and used to rebuil

STATISTICS TABLE ALL INDEX ALLSHRLEVEL REFERENCEDISCARD FROM TABLE STOCKMODIFICATIONS

WHEN (SMTIMESTAMP < CURRENT DATE - 3 YEAR)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 16

REORG utility for REWRITE activities 2.4

• Example of an “Update of many rows”

REORG TABLESPACE TBD7971.TBSSTMODUNLOAD PAUSE

B2 for z/OS: Utilities and Application Development

- unload-file has no indexes

- indexes are REBUILT after restart

- remarks:· constraints (check and R.I.) are not checked

· there will be no CHKP-status

Do whileREAD from <unload-file>modify recordWRITE to <reload-file>

End

RESTART REORG TABLESPACE ...

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 17

Examples of simple scenarios 3

Adding many rows 3.1

o page locks

Do whileREAD input-record

B2 for z/OS: Utilities and Application Development

Problem:

- large input-files and 4 indexes

--> long execution time

- locking:· from exclusive table lock and low ‘commit’ frequency t

and high ‘commit’ frequency:--> more concurrency--> +/- doubled elapsed time

...INSERT INTO StockModifications

VALUES(:WS-StockModifications:WS-SMInd)End

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 18

Adding many rows (II)

• Alternative

LOAD DATARESUME YES

B2 for z/OS: Utilities and Application Development

- Plus:· less execution time (between 25 and 50%)

· no programming effort

- Minus:· FIELD-specifications· SHRLEVEL NONE

(SHRLEVEL CHANGE = INSERT)· only KEY and R.I. control· no TRIGGER support

SHRLEVEL NONEINTO TABLE STOCKMODIFICATIONS<FIELD-specifications>

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 19

Copying many rows 3.2

o long

ult

DECLARE CopyStM CURSOR FORSELECT *

FROM StockModificationsWHERE SMTimestamp = CURRENT DATE - 1 DAY

B2 for z/OS: Utilities and Application Development

Problem:

- time that the table is unavailable (exclusively locked) is to

- lock is needed: concurrent updates can give a wrong res

LOCK TABLE StockModifications IN SHARE MODEOPEN CopyStMDo while

FETCH CopyStM INTO :WS-StockModifications:WS-SMInd...WRITE uotput-record

end

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 20

Copying many rows (II)

• Alternative 1:

UNLOAD DATAFROM TABLE STOCKMODIFICATIONS

B2 for z/OS: Utilities and Application Development

- Plus:· faster than SQL (typical value: 3 times faster)· no programming effort

· format of output records is controllable

- Minus:· no complex conditions

WHEN (SMTIMESTAMP = CURRENT DATE - 1 DAY)SHRLEVEL REFERENCE

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 21

Copying many rows (III)

• Alternative 2:

1)

COPYTABLESPACE TBD7971.TBSSTMOD

B2 for z/OS: Utilities and Application Development

- Plus:· COPY +/- 2 times faster than UNLOAD (of alternative

- Minus:· second job (UNLOAD)

(but without impact on the base table)

SHRLEVEL REFERENCE

UNLOADTABLESPACE TBD7971.TBSSTMODFROMCOPYDDN ...FROM TABLE STOCKMODIFICATIONS

WHEN (SMTIMESTAMP = CURRENT DATE - 1 DAY)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 22

Deleting many rows 3.3

DELETE FROM StockModificationsWHERE SMTimestamp < CURRENT DATE - 2 DAYSAND SMStatus = ‘7’

B2 for z/OS: Utilities and Application Development

Problem:

- +/- 50% of the rows are deleted

- table has 4 indexes

--> very long execution time (60 minutes)

- space management

--> REORG needed after execution

- remarks:· locking: exclusive table lock

--> low CPU-usage, many time-outs

· R.I. is no problem (dependent table)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 23

Deleting many rows (II)

• Alternative

REORG TABLESPACE TBD7971.TBSSTMODLOG NO SORTKEYS COPYDDN(SYSCOPY)

B2 for z/OS: Utilities and Application Development

- Plus:· much faster than SQL (few minutes)· no programming effort

· REORG and DISCARD: one job

- Minus:· no complex conditions· if parent table: CHKP for dependent tables

STATISTICS TABLE ALL INDEX ALLSHRLEVEL REFERENCEDISCARD FROM TABLE STOCKMODIFICATIONS

WHEN (SMTIMESTAMP = CURRENT DATE - 2 DAYSAND SMSTATUS = ‘7’)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 24

Examples of mixed scenarios 4

Deleting many parent rows 4.1

• Process:

- parent rows with a given status must be deleted (+/- 75%)

dent table)

B2 for z/OS: Utilities and Application Development

- delete rule is ‘cascade’

- on average 500 dependents for a parent row

SQL solution

- Problem:· index maintenance on LastStockModifications (depen· (index maintenance on LastOrders)

DELETE FROM LastOrdersWHERE LOStatus = ‘OK’

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 25

Deleting many parent rows (II)

• Alternative

UPDATE LastStockModificationsSET LSMStatus = ‘OK’

B2 for z/OS: Utilities and Application Development

· efficient UPDATE process if no indexes on LSMStatus

· DISCARD of parent rows --> dependent table: CHKP

WHERE EXISTS (SELECT 1 FROM LastOrdersWHERE LOStatus = ‘OK’AND LO_PrNo = LSM_PrNo)

REORG TABLESPACE TBD7971.TBSLSTSMDISCARD FROM TABLE LASTSTOCKMODIFICATIONS

WHEN (LSMSTATUS = ‘OK’)

REORG TABLESPACE TBD7971.TBSLSTORDISCARD FROM TABLE LASTORDERS

WHEN (LOSTATUS = ‘OK’)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 26

Use of INCURSOR 4.2

• Process:

- information must be copied from a source table to a target table

- availability of the target table is critical

B2 for z/OS: Utilities and Application Development

- complex selection criteria for the source table

SQL solution

- Problem:· index maintenance on StockModifications

INSERT INTO StockModificationsSELECT * FROM LastStockModifications T

WHERE NOT EXISTS (SELECT 1 FROM ProductsWHERE PrNo = T.LSM_PrNo

AND PrStatus = ‘7’)

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 27

Use of INCURSOR (II)

• Alternative 1:

EXEC SQLDECLARE GETSTMOD CURSOR FOR

B2 for z/OS: Utilities and Application Development

SELECT * FROM LASTSTOCKMODIFICATIONS TWHERE NOT EXISTS (SELECT 1 FROM PRODUCTS

WHERE PRNO = T.LSM_PRNOAND PRSTATUS = ‘7’)

ORDER BY LSMTIMESTAMPENDEXECLOAD DATA

INCURSOR GETSTMODRESUME YESSHRLEVEL NONEINTO TABLE STOCKMODIFICATIONS

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 28

Use of INCURSOR (III)

- Alternative 2:

s

INSERT INTO TempStockModificationsSELECT * FROM LastStockModifications T

B2 for z/OS: Utilities and Application Development

· efficient SQL if no indexes on TempStockModification

WHERE NOT EXISTS (SELECT 1 FROM ProductsWHERE PrNo = T.LSM_PrNo

AND PRStatus = ‘7’)

UNLOAD DATASHRLEVEL NONEFROM TABLE TEMPSTOCKMODIFICATIONS

LOAD DATARESUME YES SHRLEVEL NONEINTO TABLE STOCKMODIFICATIONS

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 29

INSERT after complex control 4.3

Process:

- uncontrolled information (but correct format) must be copied from an input-file into a target table

B2 for z/OS: Utilities and Application Development

- availability of the target table is critical

- complex control criteria for the input information

SQL solution

- Problem:· again index maintenance on StockModifications

Do whileREAD input-record<control activities>If OK

INSERT INTO StockModificationsVALUES(:WS-StockModifications:WS-SMInd)

End

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 30

INSERT after complex control (II)

• Alternative 1:

LOAD DATARESUME YES

B2 for z/OS: Utilities and Application Development

· by default: SMStatus = NULL (i.e. not yet available)--> additional VIEW (SMStatus IS NOT NULL)?

SHRLEVEL NONEINTO TABLE STOCKMODIFICATIONS<FIELD>-specifications

DECLARE NewStMod CURSOR FORSELECT * FROM StockModificationsWHERE SMStatus IS NULLDo while

FETCH NewStMod INTO :WS-StockModifications:WS-SMInd<control activities>If NOT-OK

<correction>End

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 31

INSERT after complex control (III)

• Alternative 2:

LOAD DATARESUME YES

B2 for z/OS: Utilities and Application Development

· no impact on the base table

· no impact on the base table

SHRLEVEL NONEINTO TABLE NEWSTOCKMODIFICATIONS<FIELD>-specifications

DECLARE NewStMod CURSOR FORSELECT * FROM NewStockModificationsDo while

FETCH NewStMod INTO :WS-StockModifications:WS-SMInd<control activities>If NOT-OK

<correction>End

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 32

INSERT after complex control (IV)

- Alternative 2 (cont.):

EXEC SQLDECLARE GETSTMOD CURSOR FOR

B2 for z/OS: Utilities and Application Development

· efficient index manipulation of StockModifications

SELECT * FROM NEWSTOCKMODIFICATIONSWHERE NSMSTATUS IS NOT NULLORDER BY NSMTIMESTAMP

ENDEXECLOAD DATA

INCURSOR GETSTMODRESUME YESSHRLEVEL NONEINTO TABLE STOCKMODIFICATIONS

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 33

Utilities and remote access 4.4

Process:

- refresh of a replicated table inside DB2

- at runtime initiated by a ‘remote Java application’

S

P

B2 for z/OS: Utilities and Application Development

tandard solution using SQL:

roblem:

- in flight index maintenance

- how to use utilities as alternative?

DELETE FROM LastStockModifications

INSERT INTO LastStockModificationsSELECT *

FROM STOCKMODIFICATIONSWHERE SMTIMESTAMP = CURRENT DATE

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 34

Stored Procedure: DSNUTILS

• St Proc to execute utilities:

- allocates dynamically data sets

- creates the utility statements

B2 for z/OS: Utilities and Application Development

- invokes DB2 utilities using program DSNUTILB

- inserts the result (SYSPRINT) into a temporary table (SYSIBM.SYSPRINT)

- declares a cursor:

- OPENs the cursor and RETURNs

DECLARE SysprintCURSOR WITH RETURN FOR SELECT seqno, textFROM sysibm.sysprint ORDER BY seqno

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 35

Stored Procedure: DSNUTILS (II)

• Calling DSNUTILS:

CALL DSNUTILS(<utility-id>,

B2 for z/OS: Utilities and Application Development

Utility statements

<restart-indicator>, <utility-statements> , <return-code>, <ANY / <utility-name>, <dataset-name1>, .....)

UNLOAD DATAFROM TABLE STOCKMODIFICATIONS

WHEN (SMTIMESTAMP = CURRENT DATE)

LOAD DATA REPLACEINTO TABLE LASTSTOCKMODIFICATIONS

Utilities & Application Development

1. Introduction2. Supported functionality3. Examples of simple scenari-

os4. Examples of mixed scenari-

os

D ABIS 36

Stored Procedure: DSNUTILS (III)

• Checking the execution

- SQLCODE (in calling program):· 466: PROCEDURE ... RETURNED ... QUERY RESULTS SETS

B2 for z/OS: Utilities and Application Development

- return-code (out parameter from St Proc)· utility RETURN CODE (0, 4, 8 ...)

- utility report:· can be fetched from SYSIBM.SYSPRINT