DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01...

48
© Xephon plc 2001 November 2001 109 3 COPYTOCOPY – a new DB2 utility for Version 7 8 Improve DSN1COPY performances 12 LASTDATE and LASTDAY functions 17 Generating recovery control cards 31 Unique and primary key constraints in DB2 for OS/390 Version 7 39 DB2 stored procedures and dynamic cursors 46 November 1998 – November 2001 index 48 DB2 news

Transcript of DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01...

Page 1: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© Xephon plc 2001

November 2001

109

3 COPYTOCOPY – a new DB2utility for Version 7

8 Improve DSN1COPYperformances

12 LASTDATE and LASTDAYfunctions

17 Generating recovery control cards31 Unique and primary key constraints

in DB2 for OS/390 Version 739 DB2 stored procedures and

dynamic cursors46 November 1998 – November 2001

index48 DB2 news

Current Support
Xephon magazine issues are now supported at www.cbttape.org. Please go to www.cbttape.org if you have any support questions.
Page 2: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

2

DB2 UpdatePublished byXephon27-35 London RoadNewburyBerkshire RG14 1JLEnglandTelephone: 01635 38342From USA: 01144 1635 38342E-mail: [email protected]

North American officeXephonPO Box 350100Westminster, CO 80035-0100USATelephone: 303 410 9344

Subscriptions and back-issuesA year’s subscription to DB2 Update,comprising twelve monthly issues, costs£255.00 in the UK; $380.00 in the USA andCanada; £261.00 in Europe; £267.00 inAustralasia and Japan; and £265.50elsewhere. In all cases the price includespostage. Individual issues, starting with theJanuary 1997 issue, are available separatelyto subscribers for £22.50 ($33.75) eachincluding postage.

DB2 Update on-lineCode from DB2 Update, and complete issuesin Acrobat PDF format, can be downloadedfrom our Web site at http://www.xephon.com/db2; you will need to supply a wordfrom the printed issue.

© Xephon plc 2001. All rights reserved. None of the text in this publication may be reproduced,stored in a retrieval system, or transmitted in any form or by any means, without the priorpermission of the copyright owner. Subscribers are free to copy any code reproduced in thispublication for use in their own installations, but may not sell such code or incorporate it in anycommercial product. No part of this publication may be used for any form of advertising, salespromotion, or publicity without the written permission of the publisher. Copying permits areavailable from Xephon in the form of pressure-sensitive labels, for application to individualcopies. A pack of 240 labels costs $36 (£24), giving a cost per copy of 15 cents (10 pence).To order, contact Xephon at any of the addresses above. Printed in England.

EditorTrevor Eddolls

DisclaimerReaders are cautioned that, although theinformation in this journal is presented in goodfaith, neither Xephon nor the organizations orindividuals that supplied information in thisjournal give any warranty or make anyrepresentations as to the accuracy of thematerial it contains. Neither Xephon nor thecontributing organizations or individualsaccept any liability of any kind howsoeverarising out of the use of such material.Readers should satisfy themselves as to thecorrectness and relevance to theircircumstances of all advice, information,code, JCL, and other contents of this journalbefore making any use of it.

ContributionsWhen Xephon is given copyright, articlespublished in DB2 Update are paid for at therate of £170 ($260) per 1000 words and £100($160) per 100 lines of code for the first 200lines of original material. The remaining codeis paid for at the rate of £50 ($80) per 100lines. In addition, there is a flat fee of £30($50) per article. To find out more aboutcontributing an article, without anyobligation, please download a copy of ourNotes for Contributors from www.xephon.com/nfc.

Page 3: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

3© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

COPYTOCOPY – a new DB2 utility for Version 7

DB2 Version 7 introduced several new utilities and utility functions,one of which is the utility called COPYTOCOPY. The purpose ofCOPYTOCOPY is to make additional image copies of currentlyexisting image copy datasets.

The primary benefit of COPYTOCOPY is a reduction in the amountof time required to run the COPY utility. Remember that COPY Aformatting routine for DSNTIAUL unload filescan be used to take upto four image copies with a single execution of the utility. But withCOPYTOCOPY available, instead of using COPY to make fourimage copy back-ups, the DBA can use it to make a single image copy,and then run COPYTOCOPY to make additional image copies. TheCOPY utility will take less time to create a single image copy back-up than it will to take multiple image copy back-ups. And thecombination of COPY plus COPYTOCOPY can be used to increaseavailability.

When COPYTOCOPY is running, the database object (table space orindex space) being copied is placed in Utility Restricted Read/Writestate (URRW). This prevents other users from dropping the tablespace or index while COPYTOCOPY is running.

Individual data and index partitions are treated as distinct targetobjects by the COPYTOCOPY utility. Any other utilities operatingon different partitions of the same table space or index space can berun concurrently with COPYTOCOPY.

The following utilities cannot be run concurrently on the samedatabase object as the COPYTOCOPY utility:

• COPY

• LOAD

• MERGECOPY

• MODIFY

• RECOVER

Page 4: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 4

• REORG INDEX

• REORG TABLESPACE.

Furthermore, COPYTOCOPY is flexible enough to run against anyDB2 image copy dataset. This includes inline copies made during theexecution of the REORG and LOAD utilities. COPYTOCOPY muststart with a primary image copy back-up – either the local primary orrecovery site primary copy. From that image copy, the COPYTOCOPYutility can make up to three copies of one or more of the followingtypes:

• Local primary

• Local back-up

• Recovery site primary

• Recovery site back-up.

Copies created by COPYTOCOPY can be used by the RECOVERutility just like regular image copies created using the COPY utility.Both table space and index space copies can be made using theCOPYTOCOPY utility. Any DB2 utility process that uses imagecopy datasets can use the image copy datasets created byCOPYTOCOPY. This includes MERGECOPY, UNLOAD, andsubsequent runs of COPYTOCOPY. However, bear in mind thatimage copies created with the CONCURRENT option of the COPYutility are not supported by the COPYTOCOPY utility.

Just like COPY, COPYTOCOPY records information about theimage copies that it creates in the SYSIBM.SYSCOPY systemcatalog table. The COPYTOCOPY utility will insert the values in theDSNAME, GROUP_MEMBER, JOBNAME, AUTHID,DSVOLSER, and DEVTYPE columns as appropriate, depending onthe copies that are being created.

You cannot run COPYTOCOPY to create additional image copies forcertain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory(DSNDB01 and SYSUTILX both in DSNDB01) objects.

The COPYTOCOPY utility operates in these distinct phases:

Page 5: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

5© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

• UTILINIT – initialization and set-up.

• CPY2CPY – copying the image copy.

• UTILTERM – clean-up.

REQUIRED AUTHORIZATIONS

To execute COPYTOCOPY, the process or user running the utilitymust have been granted one of the following privileges:

• SYSADM.

• SYSCTRL.

• DBADM, DBCTRL, or DBMAINT for the database in which theindex or table space resides.

• IMAGCOPY for the database in which the index or table spaceresides.

The only exception to the above is for the DB2 directory (DSNDB01)and the DB2 catalog (DSNDB06). Any process or user havingINSTALL SYSOPR authority can run COPYTOCOPY for tablespaces in the directory or catalog.

TERM AND RESTART ISSUES

The use of the TERM command to terminate a COPYTOCOPY stepthat has abended is not recommended. A current restart should bedone instead to allow COPYTOCOPY to pick up where it left off.Terminating COPYTOCOPY in such a situation might causeinconsistencies between the ICF catalog and DB2 catalog whenGDGs are used.

You cannot use RESTART(PHASE) for a COPYTOCOPY job. It isfine to use RESTART(CURRENT) as long as you avoid using theTERM UTILITY command to terminate a COPYTOCOPY step.When you use RESTART(CURRENT), COPYTOCOPY will restartfrom the last commit point with the same image copy dataset, so besure to code a dataset disposition of DISP=(MOD,CATLG,CATLG)on your JCL DD statements.

Page 6: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 6

INLINE COPY EXCEPTION

When using COPYTOCOPY to copy an inline image copy that wasmade by the REORG utility with the part range option, you will needto specify individual DSNUMs for the partitions to be copied. TheCOPYTOCOPY utility does not support part range. COPYTOCOPYwill copy only the specified partition data from the input inline imagecopy dataset into the output image copy dataset.

COPYTOCOPY EXECUTION

To run the COPYTOCOPY utility, it is not necessary to provide theexplicit dataset name of the image copy being copied. Instead, theinput to the COPYTOCOPY utility is the name of the table space,index space, or index for which the original copy was made, and anindication of which image copy in the catalog should be copied. Tospecify this information COPYTOCOPY provides three options:

• FROMLASTCOPY – indicates that the most recent image copytaken for the table space or index space is to be used as input tothe COPYTOCOPY utility. The input could be either a full imagecopy or incremental copy. The utility will retrieve the informationfrom the SYSIBM.SYSCOPY system catalog table.

• FROMLASTFULLCOPY – indicates that the most recent fullimage copy taken for the object is to be used as the input to theCOPYTOCOPY job. Once again, this information is obtained byquerying the DB2 Catalog.

• FROMLASTINCRCOPY – indicates that the most recentincremental image copy taken for the object is to be used as theinput to the COPYTOCOPY job. FROMLASTINCRCOPY isnot valid for index spaces or indexes. If FROMLASTINCRCOPYis specified for an index space or index, COPYTOCOPY will usethe last full image copy that was taken for the index, if one isavailable. And once again, this information is obtained byquerying the DB2 catalog.

Of course, you may choose instead to specify the dataset name for theimage copy that is to be copied by the COPYTOCOPY utility. Thiscan be accomplished by using the FROMCOPY clause. But bear in

Page 7: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

7© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

mind that when you are using COPYTOCOPY with a list of objectsdefined using the LISTDEF statement, the FROMCOPY clause is notvalid.

If the FROMCOPY keyword is not used, the COPYTOCOPY utilitymust determine which specific image copy is to be copied. BeforeCOPYTOCOPY can execute it may have to choose between the localsite primary copy, local site back-up copy, recovery site primary copy,and recovery site back-up copy datasets. COPYTOCOPY will searchimage copies in the following order to determine the input dataset tobe used:

• If you are running COPYTOCOPY at your local site, the searchorder will be local site primary copy, local site back-up copy,recovery site primary copy, recovery site back-up copy.

• If you are running the utility at your recovery site, the search orderwill be recovery site primary copy, recovery site back-up copy,local site primary copy, then finally local site back-up copy.

If the input dataset cannot be allocated or opened, the COPYTOCOPYutility will try to use the next image copy data with the sameSTART_RBA value in SYSIBM.SYSCOPY column, in the searchorder as indicated previously. When the FROMCOPY keyword isused, though, only the explicitly specified dataset can be used as theinput to COPYTOCOPY.

AN EXAMPLE OF THE COPYTOCOPY UTILITY

Let’s take a quick look at a sample JCL job step to run theCOPYTOCOPY utility. The following code can be run to make aback-up local image copy of the table space DSN8S71E in the sampleDB2 database DSN8D71A. This will be either a full or incrementalimage copy, whichever was last run for this object:

������������������� ��������������������

�������������� �����

����������������������������������

�������������

�������������������������������������������� �������

���������������������� ��!!��������"����#����#!

�������������

Page 8: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 8

������������������������$������$���������������!

��

BOTTOM LINE

The COPYTOCOPY utility provides a useful new feature for thetoolkit of DB2 DBAs. Using COPYTOCOPY to create additionalimage copies from existing image copies can enhance availability andassist DBAs in creating an optimal back-up and recovery plan fortheir DB2 applications and databases.

Craig S MullinsBMC (USA) © C Mullins 2001

Improve DSN1COPY performances

INTRODUCTION

The DB2 utility DSN1COPY can be used to copy DB2 VSAMdatasets to sequential datasets.

In order to improve DSN1COPY execution, you should code an AMPparameter in the SYSUT1 DD statement. The AMP parameter is usedto specify information in an Access method Control Block (ACB) fora VSAM dataset.

In order to get better I/O performance, you should code an optimizedBUFND parameter. This parameter specifies the number of I/Obuffers that VSAM is to use for data records.

By default, the BUFND value is too low – it is 2!

A DB2 VSAM dataset uses 12 CI/track of a 3390 DASD. So, in orderto match a cylinder, you should code BUFND=180 (12 * 15 = 180).

Page 9: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

9© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

BENCHMARK

To test the effect of this optimization, we will use DSN1COPY to‘download’ the SYSPKAGE tablespace (5115 tracks).

Test with BUFND = 2

First, we are not going to code the AMP parameter, so we will use thedefault BUFND value of 2. The JCL for this is shown below:

����������������#��������

������ �������������

�����������������% ����������������&�����'�#������������

����������������

The DSN1COPY results are shown below:

������(�����(������#��)������������������������)�������(�������

*

�� ��+��&�(���,&&��))��%� �������&���#������))

�� ��+��&�(���,&&��������������������-./0�.12��&��34����� 5�&

�6./17�������-89:9/6����

�� ��+��&�(���,&&���;%���<�<������������ ���0�"���������0�� �����

(��=&����0���������

�� ��+��&�(���,&&������������>3?/��,$�<��>21��-9:��>8@/971��>?1

�-71��� ���� ���'�

�� ��+��&�(���,&&������,�<����������0���� ���0������� ��+��&

�� ��,����(���,&&���0�����������������������������������������)�����#�

������!)

�� ��,����(���,&&���0(������������������ ��������� ������������

� ������������� �

�� ��,����(���,&&���0������������������������������,�� $< ,������,

�������,�+���&& '

�� ��,����(���,&&������,�,����������0�����0������� ��,���

�� ��,����(���,&&���0������������������0��������������������������

�������������,�������

�� ��,����(���,&&���;%���<+ ������������

�)))�(����(�������������)))

0���&���#������(���������������

0������������ �� �� ��

0�����������&<��������� ���� �� �

0������������������������%� �� �

0������������,��������������'�����

0���������,�+<����������������������

This first execution of DSN1COPY used 58354 EXCP, 2.78 CPUseconds, and its elapsed time was 4.93 minutes.

Page 10: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 10

Test with BUFND = 180

The JCL with BUFND = 180 is shown below:

����������������#��������

������ �������������

�����������������% ����������������&�����'�#�������������

��������������������������$��!

����������������

The DSN1COPY results are shown below:

���������(�����(������#��)����������������� �����)�������(�������

�� �����,�(���,&&��))��%� �������&���#������))

�� �����,�(���,&&��������������������-./0�.12��&��34����� 5��

�6./17�������-89:9/6����%

�� �����,�(���,&&���;%���<�<������������ ���0�"���������0�� �����

(��=�����0���������

�� �����,�(���,&&������������>3?/��,$� ��>21��-9:��>8@/971��>?1

�-71��� ���� ���'�

�� �����,�(���,&&������,�<����������0���� ���0������� �����,

�� ����<��(���,&&���0�����������������������������������������)�����#�

������!)

�� ����<��(���,&&���0(������������������ ��������� ������������

� ������������� �

�� ����<��(���,&&���0������������������������������,����&$��������

��������� �����<'

�� ����<��(���,&&������,�,����������0�����0������� ����<�

�� ����<��(���,&&���0������������������0��������������������������

���������������������

�� ����<��(���,&&���;%���<+ ������������

�)))�(����(�������������)))

0���&���#������(���������������

0������������&�� �� ��

0�����������&,��������� ���� �� �

0������������������������%� �� �

0������������,��������������'�����

0����������� ,����������������������

This second execution of DSN1COPY used 681 EXCP, 1.62 CPUseconds, and its elapsed time was 0.54 minutes.

MEMORY CONSTRAINTS

If the region of your job is too small to allocate 180 data buffers, yourjob will fail (RC=8) with the following messages:

Page 11: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

11© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

���&������0� ,��++� �������������������

���&���������������&�����'�#�������������

���&���������������&�����'�#������������������#����

A�

���+++����� �������������� �(����++� ���������

���++&������������� � ����� ��#����<&��������

���++<����������� ��������������������#���� �����

CONCLUSION

The results of these two executions of DSN1COPY are summarizedin Figure 1.

You should notice that you can save 89.05% execution time using anoptimized BUFND parameter!

(France) © Xephon 2001

BUFND EXCP CPU Elapsed

2 58354 2.78 4.93180 681 1.62 0.54

-98,83% -41.73% -89.05%

Figure 1: Result summary

Have you come across any undocumented features in DB2Version 7? Why not share your discovery with others? Sendyour findings to the editor, Trevor Eddolls, at any of theaddresses shown on page 2 or e-mail [email protected].

Page 12: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 12

LASTDATE and LASTDAY functions

I have prepared two more user-defined functions (see DB2 Updateissues 103 and 104, May and June 2001, Sample user-definedfunctions). The first function is called LASTDATE and the secondfunction is LASTDAY. I wrote all these functions in PL/I.

LASTDATE

The schema is SYSADM.

The LASTDATE function returns the last date of the month in dateformat.

The expression must be a date, for example:

��������������� �������!����������������

���������������������+$�0�<0���!!���������

� ������������������

This gives the following result:

����������������

0000000000��0000000000

����0� 0<����+$�0�<0<�

The current date for this example was ‘2001-05-28’.

LASTDAY(expression)

The schema is SYSADM.

The LASTDAY function returns the last day of the month in smallint(small integer) format.

The expression must be a date, for example:

�������������� �������!���������������

��������������������+$�0�<0���!!��������

� ������������������

This gives the following result:

������������

Page 13: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

13© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

000000��000000

<�

The current date for this example was ‘2000-11-27’.

THE UDF CREATE DEFINITIONS

LASTDATE

��������������������������

�������������!

��� ������������

��������������

���� ������������������������00�����:>-2�7>23:1

���#��#�����

�� ����� ����������B�

��� �������

�����B�����

�����

����

������������

"������� ����������"��� 00�"���-CC:98-/9>?

����� ����������

� �# ������������

������� ���������

��� ���������������������

���� ��%��

������������

������"��� �����

����������������

��� ������D

LASTDAY �������������������������

�������������!

��� ������������

�������������

���� �����������������������00�����:>-2�7>23:1

���#��#�����

�� ����� ����������B�

��� �������

�����B�����

�����

����

�����������

"������� ����������"��� 00�"���-CC:98-/9>?

����� ����������

Page 14: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 14

� �# ������������

������� ���������

��� ���������������������

���� ��%��

������������

������"��� �����

����������������

��� ������D

LOAD MODULES

LASTDATE – PL/I source code��� ���������������!D

�������5�� ����=�� ������= ������

�����������������=��������=�� �

�����������������=�B����������=��������=���=�����

�����������������=��#=��#����=� ��%���

�����������������=���=��������=�����!

�������������������������������� ���� ���!D

�����������������������������������������������������������������������

������������5��������������������������������������������������������

�������������5���=�� ������%� ���!�����������������������������������

�������������5���= ��������������������������������������������������

�����������������������������������������������������������������������

������=�� ��������%� ���!D��������������������� ����� �������������

������= ����������%� ���!D������������� �������� ����� ������������

������=�������������������� !D�������������� ��� ��������� �����

������=�� ����������������� !D�������������� ��� � �������������

��������=� ��%������������������������ ��%��������������������

��������<���=���=����������������<�!�

��������<���=���=�������%� ����!D

��������=��������������������������������������������������������

������<���=�����=��������������� !��������������������#�%���������

������<���=�����=����%� ���$!������������������������������������

������<���=�����=��������������� !������������%������#�%����������

������<���=�����=���%�%� ���$!����������������%� �E���������������

������<���=�����=���%� �,$!������������������� �������<+����

������� ���=�����=��������������<�!������������������������

������� ���=�����=���������������<�!�����������������������

������� ���=�����=�������������<�!�����������������������

������� ���=�����=��������������<�!��������������������������

������� ���=�����=���������������<�!�������������������������

������� ���=�����=�������������<�!�������������������������

������� ���=�����= ��� ���%� ���!���������� ��� ������������������

������<���=�����=B�������������� !���������B������� ����#�%��������

������<���=�����=B������%� ���$!�����������B������� ���������������

Page 15: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

15© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

������<���=�����=��������������� !������������������#�%������������

������<���=�����=�������%� ���$!�����������������������������������

������<���=�����=�������������� !������������������#�%�����������

������<���=�����=������%� ���$!����������������������������������

������<���=�����= ���� �%� �$!���������������� �������������������

������<���=�����=������ �����������<�!������������������� ��������

������<���=�����=������������������ !�����F���������������������

������<���=�����= ��� ���%� ��,!����������� ��� ������������������

������<���=�����=���������� ���������������0G���������������������

������<���=�����= ��� ���%� ��,!D���������� ��� ������������������

������ ����#�%������ �����!����������D

�������B���������B��D

������������������������������������������������������������������

����� ��� ����%���������������%������%������ ���������0��0�����

����������������������0�$0�$�!!���0G��������0�$0<���������������

������������������������������������������������������������������

�������B�

������������ ���%� ���� �5��=�� ��!!!HH�0�HH

���������������� ��#��������%�5��=�� ��!!��+���!HH�0�HH

�����������%� ���������� ���%� ���� �5��=�� ��!!!HH�0�HH

���������������� ��#��������%�5��=�� ��!!��+���!HH�0���!

�����������I�������%�0�����!!

���������5��= �����

��� �������������������"��%�� D

����������D

LASTDAY – PL/I source code��� ���������������!D

�������5�� ����=�� ������= ������

�����������������=��������=�� �

�����������������=�B����������=��������=���=�����

�����������������=��#=��#����=� ��%���

�����������������=���=��������=�����!

�������������������������������� ���� ���!D

�����������������������������������������������������������������������

������������5��������������������������������������������������������

�������������5���=�� ������%� ���!�����������������������������������

�������������5���= ���������������������������������������������������

�����������������������������������������������������������������������

������=�� ��������%� ���!D��������������������� ����� �������������

������= �������������������� !D�������� �������� ����� ������������

������=�������������������� !D�������������� ��� ��������� �����

������=�� ����������������� !D�������������� ��� � �������������

��������=� ��%������������������������ ��%��������������������

�������<���=���=����������������<�!�

�������<���=���=�������%� ����!D

Page 16: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 16

��������=���������������������������������������������������������

������<���=�����=��������������� !��������������������#�%���������

������<���=�����=����%� ���$!������������������������������������

������<���=�����=��������������� !������������%������#�%����������

������<���=�����=���%�%� ���$!����������������%� �E���������������

������<���=�����=���%� �,$!������������������� �������<+����

������� ���=�����=��������������<�!������������������������

������� ���=�����=���������������<�!�����������������������

������� ���=�����=�������������<�!�����������������������

������� ���=�����=��������������<�!��������������������������

������� ���=�����=���������������<�!�������������������������

������� ���=�����=�������������<�!�������������������������

������� ���=�����= ��� ���%� ���!���������� ��� ������������������

������<���=�����=B�������������� !���������B������� ����#�%��������

������<���=�����=B������%� ���$!�����������B������� ���������������

������<���=�����=��������������� !������������������#�%������������

������<���=�����=�������%� ���$!�����������������������������������

������<���=�����=�������������� !������������������#�%�����������

������<���=�����=������%� ���$!����������������������������������

������<���=�����= ���� �%� �$!���������������� �������������������

������<���=�����=������ �����������<�!������������������� ��������

������<���=�����=������������������ !�����F���������������������

������<���=�����= ��� ���%� ��,!����������� ��� ������������������

������<���=�����=���������� ���������������0G���������������������

������<���=�����= ��� ���%� ��,!D���������� ��� ������������������

������ ����#�%������ �����!����������D

�������B���������B��D

������������������������������������������������������������������

����� ��� ����%��������������%������%������ �������������������

���������������������0�$0�$�!!���0G���<�������������������������

������������������������������������������������������������������

�������B����������������� ���%� ���� �5��=�� ��!!!HH�0�HH

�������������� ��#��������%�5��=�� ��!!�+��!HH�0���!

���������I�������%�0�����!

������������5��= �����

��� �������������������"��%�� D

����������D

Bernard ZverDBA (Slovenia) © Xephon 2001

Page 17: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

17© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

Generating recovery control cards

This REXX EXEC helps DBAs in building recovery control cardswhen the recovery to be performed is of the type TOCOPY. Based ona selection criterion given by the DBA, this EXEC reads theSYSIBM.SYSCOPY catalog table, selects image copy records basedon the selection criterion, and displays these entries to the DBA inanother panel. A DBA can browse these entries in the panel and selectthe entries required for recovery. Once these entries are selected, theEXEC generates SYSIN control cards ( RECOVER TABLESPACE…. TOCOPY ….. ) to be used by the DB2 RECOVER utility. Thesecontrol statements are generated in the ascending file sequencenumber order. This reduces tapes mount and dismount processeswhen multiple image copy datasets exist on the same tape. This EXECalso generates control cards for the recovery of the correspondingindexes (RECOVER INDEX …).

In the first step, it displays a panel, PRCVR, where the user canprovide the values for:

1 Subsystem ID – this is the DB2 subsystem name from whereSYSCOPY entries are to be retrieved. In cases of data sharing,this is the group name.

2 Database name – this is the database containing tablespacesrequiring recovery.

3 SYSCOPY rows choice – this has three options:

– Retrieve all image copy rows (ICTYPE='F') for a giventablespace name.

– Retrieve all image copy rows (ICTYPE='F') for a given dateand time range.

– Retrieve all image copy rows (ICTYPE = 'F') for a combinationof a given tablespace name and given date and time range.

4 Tablespace name – for choices 1 and 3.

5 Date range – for choice 2 and 3.

Page 18: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 18

6 Time range – for choice 2 and 3.

7 Dataset name – name of dataset for generating recovery controlcards. Allocate this dataset first.

By default, the display allows you to select all the entries for thecurrent date.

In the second step (once required entries are given in the PRCVRpanel), it reads the DB2 catalog table SYSIBM.SYSCOPY rows forICTYPE = 'F' and qualifying SYSCOPY row’s choice (given in thepanel), orders them, and displays these entries in a second panel,PRCVR2. The second panel allows the DBA to browse through all ofthese entries and select the required ones (depending on the date andtime the image copy was taken for a tablespace, and how the DBAwishes to recover a tablespace from that image copy dataset) bytyping ‘S’ to select that entry or by making it blank (to de-select anentry that was previously selected). The DBA can also use F7/F8 keysto browse through multiple screens. Once he selects all his entries, hecan press F3 to return to the PRCVR panel. In the first panel, he canagain make selections for another set of tablespaces. Once you haveselected all the required entries in the first panel, press F3 and theEXEC generates the required recovery control cards for the datasetspecified in the first panel.

In order to configure this REXX EXEC for your installation, make thefollowing changes in this REXX program:

• For variable DYNM_SQL_PGM_LOADLIB, provide the nameof the load library containing the Dynamic SQL program loadmodule.

• For variable DYNM_SQL_PGM, provide the name of theDynamic SQL program.

• For variable FILEO, provide the name of a dataset where youwant to build your recovery control cards.

• ROWS_LIMIT is a variable which allows you to control the totalnumber of rows selected by your query.

• In cases where you are selecting a large number of rows, you have

Page 19: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

19© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

to change the sizes of the work datasets used inside the REXX EXECappropriately.

��� ������

�����=�B�=�#�=�������������B�� ����������

������������������������������������ � ���� ��������B��� �# �����

������������������������

�������������������������������������� �#��� ����#���� ���� ���

�����=�B�=�#��������B��

������������������������������������B��� �# �����

���������������������������������������������������

����������������������������������������������

��������������������

�� �"�=��������&��������������������������������� �� ����

��"������

�� �"=��������

������=�������

��� =����������� ����������!�<!

����������� =���

����������� =���

�������������������

�������������< + +�

����#�����

������������

��"=����� �����

��"=���������

��� ����J������J

��J�����������������������������������'�������������!J

������������������������������������������� � ����

��J�����������������������������������'�����������!J

������������������������������������������� � ����

����"%��������������

����� ����J������J

����J�������������� � !J

�������#�����

��������������������%��

���������

����������������������

����������������

����������

�����������������������������%��

��������

�������������#������������������������

�������������� ���

���������

�������"�������H�"�������H�"����<�����%��

����������

��������

��������

�������������#����%�����������

Page 20: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 20

�������������� ���

���������

�������"�������H�"����<���%��

��������������������������%��

�����������

����������������#�������� ������������������� �%������� �<�

����������������� ���

������������

�������"�������H�"����<���%��

����������������K������������%��

�����������

����������������#����������������������

����������������� ���

������������

�������"�������H�"����<���%��

����������������G�� =������%��

�����������

����������������#������� ������������� ������

����������������� ���

������������

�������"�������H�"����<���%��

����������������K������������%��

�����������

����������������#����������������������

����������������� ���

������������

�������"�������H�"����<���%��

����������������G�� =������%��

�����������

����������������#������������������ ������

����������������� ���

������������

�������"�������H�"����<���%��

����������������K���������%��

�����������

����������������#�������� ��#������������

����������������� ���

������������

�������"�������H�"����<���%��

�����������������K������������%��

�����������

����������������#������� �����������������

����������������� ���

������������

�������"�������H�"����<���%��

�����������������G���< + +����%��

�����������

����������������#������� �����������������

����������������� ���

������������

Page 21: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

21© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

�������"�������H�"����<���%��

�����������������K������������%��

�����������

����������������#����������������������

����������������� ���

������������

�������"�������H�"����<���%��

�����������������G���< + +����%��

�����������

����������������#����������������������

����������������� ���

������������

�������������J�J�����J�J!�KG�J�'J��%��

�������

����������#������� ���� ����������������������

����������� ���

��������

��������� ����=����

����������"%������

��� �������

��J����������'"��������������J

��J� �����������!J

��� ����J������J

��J��������������J

������

������������������������������������������������������������������

���� ������� ����������������0�������������������������������

������������������������������������������������������������������

��� ����=����5

��� �������

��J��������JHH�����HHJ�!������������!��% J

��� �������

��J����������'"�������������J

������=����������

�����= �"�����

���B�������

��(=������

�������

��(����

���B��'������

��� ����J������J�J�� ����������JHH�

������J�'�����������������������������!JHH�

������J������������� �� ���������!JHH�

������J���" ���� �����J

�����������=��=�����

����� �"=����������%��

������

�����������#������� �"����������

��������� ��� �

Page 22: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 22

�������

����� �"=�����G� �"�=�������%��

������

�����������#��������� ���� �"���������������

��������� ��� �

�������

����"%��������=����������

������ ����J������J�J��������������������� � �!J

��������� ���$���%��

�������������=�����������

��������E������G����%��

���������

��������������� ����=��

����������

���������������E�����

�������"%����E�������G��

��������� ����J������J�J�������������J

�����������E������G����%��

������������

������������������� ����=��

�������������

�������

����

������� ����=���

��� ����J������J

��J��������������J

�� ��� �

������������������������������������������������������������������

��� ����� �� ��������������������������������������������������

������������������������������������������������������������������

�����=��=�����5

��������� ����=�B�

������� �"=�����������%��

������� ��� �

������� �"=�����G� �"�=�������%��

������� ��� �

������������������= �"�

������������

������������������������

�������������������

��������������������

����������������������

���������������������

����������� ��������� ��

������� ��������� ���

����������������������

������� ����J������J�J���������J

��������� �G�����%��

���������

�������������������� � ��HH

Page 23: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

23© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

����������� ����J������J�J����������J

��������������

����������

������

��� ����J������J�J���� ��������JHH�

��������������������J��������������������������������������!J

��� ����J������J�J�����������J

����� ��,��%��

�����

������������������ � ��HH

������� ����J������J�J����������J

����������

������

��� �D

������������������������������������������������������������������

���� ����� �� �������������������������������������������������

������������������������������������������������������������������

� ����=��5

������ ������� ��� �����

����������

����� ����J������J�J����������J

��� �D

������������������������������������������������������������������

��� �������������� ����������B��������������������������������

������������������������������������������������������������������

� ����=�B�5

������=��������

��� �������

��J�����'J

��J���������� ���!���"���������������!J

����� �KG����%����

���������� � �������� ������������HH�

��������

����

��J�����������!���"���������������!� ��������!�� ����$�!J

����� �KG����%����

����������� � ������������������HH�

����� ��� �

����

����������=�����

��� �������

��J�����'J

�������= ���#�

��� �������

��J� ������������!J

��J� ����������� ���!J

����� �"=����������%��

����� ��� �

����� �"=�����G�� �"�=�������%��

����� ��� �

Page 24: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 24

������=��������

��� �������

��J�����'J

��J���������� ���!���"���������������!J

����� �KG����%����

���������� � �������� ������������HH�

��������

����

��J�����������!���"���������������!� ��������!�� ����$�!J

����� �KG����%����

����������� � ������������������HH�

����� ��� �

����

����������=�����

��� �������

��J�����'J

�������= ���#�

��� �������

��J� ������������!J

��J� ����������� ���!J

��� �

������������������������������������������������������������������

����������������� ���� ���������������������������������������

������������������������������������������������������������������

����=�����5

���������=�����������%��

������

�������� �� ���J������������HH����HHJ

��������B����� ��

�������� �� ���J������������ ��#��������!�$�<!HH����HHJ

��������B����� ��

�������� �� ���J�����������HH����HHJ

��������B����� ��

�������� �� ���J������������HH����HHJ

��������B����� ��

�������� �� ���J��������% �����HH����HHJ

��������B����� ��

�������� �� ���J������������ ������� ���&!HH����HHJ

��������B����� ��

�������� �� ���J������������ ��#����������B��!�$�<!HH����HHJ

��������B����� ��

�������� �� ���J��������� ��������!�J

��������B����� ��

�������

������

������

Page 25: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

25© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

�������� �� ���J������������!������J

��������B����� ��

�������

�� �� ���J� �������������������J

��B����� ��

�� �� ���J"%� �����������JHHJ�JHH�����HHJ�JHH����

��B����� ��

�� �� ���J������������������J

��B����� ��

�����"�������H�"����<����%��

������

�������� �� ���J���������������JHHJ�JHH�������HHJ�JHH����

��������B����� ��

�������

�����"�������H�"����<����%��

������

�������� �� ���J�����������G��JHHJ�JHH�����HHJ�JHH����

��������B����� ��

�������� �� ���J�����������K��JHHJ�JHH�����HHJ�JHH����

��������B����� ��

�������� �� ���J������������G��JHHJ�JHH������HHJ�JHH����

��������B����� ��

�������� �� ���J������������K��JHHJ�JHH������HHJ�JHH����

��������B����� ��

�������

�� �� ���J�������� � ������J

��B����� ��

���B�������

���J����������'"�������������J

������ �KG����%����

������������������ � �" ����#������������� ����HH�

����������

�����

��� �

������������������������������������������������������������������

��� ����������B��� �# �����������������������������������������

������������������������������������������������������������������

�= ���#�5

��������������� ���J������=�����J�J�J!

����B����J� ���� �# ����JHH���=�B�=�#�HHJ!������JHH���=�B�=�#�HHJ!�J

����B����B�HHJ��������JHH���=�B�=�#�=������HHJ�!J

����B�����B�

����B�����J��J

����� �������

����J����������JHH���HHJ!J

������� �G�,��%��

�������

Page 26: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 26

���������B��'�����

������������������������������� � �� ��������HH

��������

����J����������' ����� ����������J

������� �KG����%����

������������������� � � ����#��������������� ����HH�

�����������

������

����� ����B�����!

������(�������� �

������������ ��

�����������B��'����������%��

�����������

������������� ����� ��

���������������������=H�� ��!���������%��

������������������� ���

�����������������

�����������������

��������������������������=�����������%��

��������������������������� ����= ��

�����������������������

�����������������������

��������������������������������������=H�� ��!

������������������������� ���������� � ��������I�!!

������������������������� ������ �������� ��������H�!

������������������������� �"=�������"� � ����!

������������������������

������������������

������������

�����������

�����������

����������������� ��

������������

�������

������ �������

�����J�����'J

���������������= ��� ����

������������ �"��= ��� ����

��� �

������������������������������������������������������������������

������ ����������� ����������B�� ����������������������������

������������������������������������������������������������������

� ����= ��5

���������= �"��G�� �"�=�������%��

������ ��� �

����������������=H�� ��!

��� ���������� � ��������I�!!

��� ������ �������� ��������H�!

������= �"���������������= �"��I��

Page 27: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

27© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

����"� ��������������"� �� ��!

��������������= �"����"� � ����!

����������= �"�������"� � ����!

������������= �"����"� � ���<!

�������������= �"����"� � ���,!

�����������= �"�������"� � ��� !

�������"� ����$��%��

�������

��������������� ����= �"����"� � ���&!

����������� �����= �"����"� � ����!

�������������������= �"����"� � ���$!

��������

�������

�������

��������������� ����= �"�������

����������� �����= �"�������"� � ���&!

�������������������= �"����"� � ����!

��������

��� �

������������������������������������������������������������������

���� ����� �� ��������������� ������������������������������

������������������������������������������������������������������

� ����=���5

� ����J������J�J���� ��������JHH�

������������������J����������� ���������� ���!J

� ����J������J�J�����������J

��=��������

��"%������=��������

����� ����J������J�J���'��������J

������� �$��%��

���������=���������

��������

��������

����������������������%��

������������������ ����=#��=��

���������

��

�����������

��� �<����

�������� ����=" ���

��

� ����J������J�J�����������J

��=��������

��"%������=��������

����� ����J������J�J���'��������J

������� �$��%��

���������=���������

��������

��������

Page 28: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 28

����������������������%��

������������������ ����=#��=��

���������

��

��� �

������������������������������������������������������������������

���#��� ������� ���� ���� ����������� ���� �����������������

������������������������������������������������������������������

� ����=#��=��5

���"=�����������%��

����

������"=���������

������"=����� ��������

�����

�������� �KG�"=����� ��%��

����

������ �<����

����������� ����=" ���

�����

�<��� ���� �������������

�<� �<HH����� ������HH���HH�����������!

�<� �<HH���������

���������������%��

��� �<� �<HH�������

����

��� �<� �<HH��

����� ����=" ���

�<�������������������

�<� �<HH����� ��������� �!

����� ����=" ���

�������� ��������%��

����

������ �<����������������������������������#��

�����

����

����

������ �<������������������������������

������ �<� �<HH�����

���������� ��KG��������%��

��������� �<� �<HH�������B�����HH� �

�����

����� ����=" ���

��� �

������������������������������������������������������������������

���#��� ������� ���� ���� ������ ���� ����������������������

������������������������������������������������������������������

Page 29: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

29© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

� ����=#��=��5

�<��� ���� �����������!�������������

�<� �<HH����� ������HH���HH�����������!

���������������%��

������

����

��� �<� �<HH���� ���HH��

����� ����=" ���

��� �

������������������������������������������������������������������

���" �����������������������������������������������������������

������������������������������������������������������������������

� ����=" ���5

������������ �<

� �������

J����������'"����������������������J

��� �

PANEL PRCVR

!���

������������������������������������������������������������������������

���������������������0�� � ��������������������������������������������

������������ ����������� �����������������L���������������������������

������������������������������������������������������������������������

������������������������������������������������������������������������

���I����������!������������"!������ �����!����������'�����!

���M����������!����������%�#%!����� �"%���!���������'�����!

���;����������!����������%�#%!����� � �!�����������'�����!

��������������!����������%�#%!����� ������"!��������'�����!

���F������������!��������%�#%!����� ��� B�����!����������!

���N����������!����������%�#%!����� � �!����������������!

���O�����������!���������%�#%!����� �# ���!���������!�%��������� �!

!������!

M))))))))))I� ���� ����������������M)))))))))

M����������=���������������������������������������������M� 0=����I

I���������������������������������������������������������������������I

I����>�1?2�29-:>4���?/1P�Q:-?@.�9?��3Q.6./17��2I����������������������I

I���������������������������������������������������������������������I

I���������������������������������������������������������������������I

I��������M�3Q.6./17��2��������5�OR���I��������������������������������I

I��������M-/-Q-.1��-71�������5�OR�������I����������������������������I

I��������M�������P>S.�T>981�5�ORI�����������������������������������I

I�����������������������������������M��0��>P�-�.C189U98��-Q:1.C-81����I

I�����������������������������������M��0��>P�-�-/1�L��971� -?41������I

I�����������������������������������M<�0��>P�-�>7Q9?-/9>?�>U��>/T����I

I�N)))))))))))))))))))))))))))))))))�I

Page 30: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 30

I���������������������������������������������������������������������I

I��������MT>981�����<�0���-Q:1.C-81��-71�5�OR�������I����������������I

I���������������������������������������������������������������������I

I��������MT>981�����<�0��-/1� -?41������5�OR�����IM0�OR�����I�������I

I������������������������M�971� -?41������5�OR�����IM0�OR�����I�������I

I���������������������������������������������������������������������I

I���M-/-�.1/��-715�OR����������������������������������������������I�I

I���M>?/P>:�8-P2�����������������������������������������������������I

I���������������������������������������������������������������������I

I���������������������������������������������������������������������I

I��������F7.4���������������������������������������������������������I

!����

��E�� ������..92�2Q?-71�S�C/.?-71�./2-/1�1?22-/1�.//971�1?2/971�U9:1>!�

!��

PANEL PRCVR2

!���

������������������������������������������������������������������������

������������������������������0�� � �����������������������������������

��������������������������� �������� �� �����������������������������

������������������������������������������������������������������������

������������������������������������������������������������������������

���I����������!������������"!������ �����!����������'�����!

���M����������!����������%�#%!����� �"%���!���������'�����!

���;����������!����������%�#%!����� � �!�����������'�����!

���F������������!��������%�#%!����� ��� B�����!����������!

���V������������!��������%�#%!����� ������"!�������������!

���O�����������!���������%�#%!����� �# ���!�������!�%��������� �!

!������!

M))))))))))I����������������� �� ���M))))))))))

M����������=���������������������������������������������M� 0=����I

I���������������������������������������������������������������������I

I����������3Q.6./175�V����I����-/-Q-.15�V��������������������������I

I���������������������������������������������������������������������I

;����-Q:1�������-/1����971���% ��>:.1P���1W�-/-.1/��-71��I

;����C-81����37������������������������������>����������������I

M

M)))))))))))))))))))))))))))))))))))

!����

O�IF�������F��F����IF�����IF���F����� IF� �F�����

!����

!� �

���� ��L��������������������!

!��

Sharad K PandeSenior DBAPriceWaterhouseCooper (USA) © Xephon 2001

Page 31: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

31© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

Unique and primary key constraints in DB2 forOS/390 Version 7

It was another one of those Sunday night DB2 applicationimplementations – complete with coffee, donuts, chocolate, dumps,and my dog, Skip, helping himself to everything he could reach. Mypartner, Charles, was braving the cold to fetch some pizza and softdrinks for us because it was already beginning to look like a longerevening than we expected. Doing nothing more than waiting for along-running job to finish, it was becoming harder and harder to keepmy eyes open. I was bolted alert by a blast of the north wind. Charlesburst through the door with the promised pizza, soft drinks, and a loton his mind. …

“Prepare yourself, Wilburt, for a singular situation we haven’t seenthe likes of in a new version of DB2 since farther back than my fadingmemory can recall. The DDL you are planning to run at 11pm tonightmay not execute successfully in DB2 Version 7 without modifications.In fact, a negative SQLCODE may be about to display on your screenjust when you think you are ready to logoff. Be assured, though, thata simple change to the DDL will quickly get you on your way to a fullset of zero return codes and a full night’s sleep.”

“Absolutely true, Charles, I’m already informed of this difference!The specifics are that SQLCODE –538 (FOREIGN KEY relnameDOES NOT CONFORM TO THE DESCRIPTION OF A PARENTKEY OF TABLE owner.name) is issued in Version 7 when you try todefine a foreign key that refers to a unique non-primary index on aparent table that does not have a unique constraint.

“I have also analysed the impact and found that foreign keys referringto non-primary unique indexes are a rather infrequent occurrence forus. Only three such foreign keys are affected in the thousands of linesof DDL I’m running tonight, and I spent no more than a few minutesmaking adjustments. However, the changes to unique constraints inVersion 7 involve more than just this.”

Page 32: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 32

HIGHLIGHTS

“Yes indeed, Wilburt, a good bit more. Changes in Version 7 to uniqueand primary key constraints also include the following:

• A user-specified name may be optionally assigned to constraints,similar to the way that names are assigned to foreign keys.

• A constraint may be added to an existing table with the ALTERTABLE statement, after the enforcing unique index has beencreated.

• A constraint must be dropped before its enforcing index can bedropped.

• Information about constraints that are created in Version 7 is nowstored in two new DB2 catalog tables – SYSIBM.SYSTABCONST and SYSIBM.SYSKEYCOLUSE.

• When a DB2 subsystem is migrated from Version 5 or 6 toVersion 7, existing constraints remain untouched by theCATMAINT process. In other words, after the CATMAINTprocess, existing constraint definitions are still stored in the sameplaces. Immediately following a CATMAINT upgrade, the twonew catalog tables are empty, because the CATMAINT processdoes not convert existing information into the new tables.”

NEW RESTRICTIONS

“All of this deserves a thorough examination, Charles, but let’s firstunderstand how to avoid an SQLCODE –538. Before Version 7, theonly prerequisite for creating a foreign key referencing a non-primaryparent key was a unique index on the parent table. In Version 7, we stillmust have a unique index, but in addition a unique constraint mustalso exist on the parent. Let’s look at some DDL that creates parentand child tables, along with a couple of foreign keys and the requiredindexes.

“The following code shows a unique constraint (in italics) defined inthe CREATE TABLE statement. You’ll recall that the UNIQUEparameter existed prior to Version 7, but it was not a prerequisite forcreating a foreign key. However, omitting it from this sample DDL in

Page 33: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

33© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

Version 7 results in an SQLCODE –538.”

���������������"� ��� ���=��

�����������=�'���������������������������

�����������=���B������������#� ����������

�����������=������������%� � !

����� ��� ��'��

����������������

�������B��

�������������� �������

���������B��

����������������"� �����=�'

����������������"� ��� ���=��

������������������=�'��!

���������B��

����������������"� �����=��

����������������"� ��� ���=��

������������������=���B�!

���������������"� �%��=���

������������=%��=�������������������������������

������������=�� �=����������%� ���!���������!

���������������"� �%��=���

������������=%��=������������������#� ����������

������������=#��=����������%� �� !���������!

���� ������������"� �%��=���

��������� ��#��'����%��'�

���������������=%��=�!

������� ��� ��������"� ��� ���=��

���������������=�'��!

���� ������������"� �%��=���

��������� ��#��'����%��'�

���������������=%��=�!

������� ��� ���������"� ��� ���=��

���������������=���B�!

NEW CREATE TABLE PARAMETER CONSTRAINT

“Good job getting straight to the point of the minimum DDL changesthat are required to get around SQLCODE -538, Wilburt. I will buildon your example by demonstrating that Version 7 now allows you tooptionally specify a name for unique and primary key constraints.This is accomplished with the new parameter CONSTRAINT, shown

Page 34: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 34

in italics below. If the CONSTRAINT parameter is omitted, as it is inthe example above, the constraint name defaults to the name of thefirst column in the key.

“Notice in the following code that the CONSTRAINT keyword iscoded once for each constraint, if the table has multiple constraints.Two unique constraints are named MYUNIQ1 and MYUNIQ2. Tablesdon’t have to have primary keys, even if they have unique constraints.However, another way to define this table would have been with aprimary key and one unique constraint, just like in the first example.”

���������������"� ��� ���=��

���������=���B����������#� ����������

���������=���B����������������������

���������=����������%� � !

��� ����� ����� ���

��������B��

�����������=���B�!

���� ����� ����� ���

��������B��

�����������=���B�!��!

ADDING CONSTRAINTS WITH ALTER TABLE STATEMENT

“Even better, Charles, is that the same parameter has been added tothe ALTER TABLE statement – so it can also be optionally used todefine the named primary key and unique constraints on an existingtable. Just as in the CREATE TABLE statement, the name defaults tothe name of the first column of the key if the CONSTRAINT keywordis omitted.

“Sample DDL that adds a primary key constraint named MYPKEY isshown below. Remember in prior DB2 versions how we could add aprimary key with an ALTER TABLE statement? Now with the newCONSTRAINT parameter in Version 7, we can name the primary keyas well. Observe that the statements must be executed in the ordershown: the unique index must be created before the constraint.

���������B��

����������������"� �����=�'

����������������"� ��� ���=��

������������������=�'��!

���� ������������"� ��� ���=��

�������������� ����� ������

Page 35: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

35© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

��������������������������� �����

“A unique constraint named MYUNIQ3 is added to a table in the codebelow. Prior to Version 7, we could not use an ALTER TABLEstatement to add unique constraints. So naturally, this DDL will proveitself priceless when the occasion arises to add a foreign key thatreferences a parent without a unique constraint. In that instance, wecan alter the constraint into the table instead of having to drop and re-create the table. Notice again that the unique index must be createdbefore the unique constraint can be added.”

���������B��

���������������"� �����=�<

����������������"� ��� ���=��

������������������=���B<!

���� �����������"� ��� ���=��

�������������� ����� ����� ���

�������������� ����������� ����

DROPPING CONSTRAINTS WITH ALTER TABLE STATEMENT

“DDL we’ve used in the past to drop primary keys is still valid. Torefresh our memories, Wilburt, the code below shows a sample:

���� �����������"� ��� ���=��

�������������������

“To drop a unique constraint, we must use the ALTER TABLEstatement with the CONSTRAINT parameter. The new syntax shownbelow works for primary key constraints, too. Note that the constraintname must be specified, even though a default name may have beenused when it was created.”

���� �����������"� ��� ���=��

������������� ����� ������

CHANGING EXISTING CONSTRAINTS

“You can’t exactly ‘change’ constraints, Charles. The ALTER TABLEstatement can only add and drop constraints. Changes to existingconstraints such as adding, deleting, renaming, or reordering columns,or renaming the constraint, require the constraint to be dropped andrecreated. Dropping a primary or unique constraint makes dependent

Page 36: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 36

foreign keys disappear too, so be prepared to recreate them as well.”

DROPPING INDEXES THAT ENFORCE CONSTRAINTS

“Speaking of dropping constraints, Wilburt, we have one moreimportant new rule to tuck away in our memories. When we drop anindex (but not the table) that enforces a primary key or uniqueconstraint, we must first drop the constraint. If the constraint existswhen the DROP INDEX statement is executed, DB2 issues SQLCODE-669, ERROR: THE OBJECT CANNOT BE EXPLICITLYDROPPED. Before Version 7, if we dropped such an index, DB2issued SQLCODE 625, WARNING: THE DEFINITION OF TABLEowner.name HAS BEEN CHANGED TO INCOMPLETE, and theindex was dropped.

“The exception to this is that if the objects were created before Version7, a unique constraint won’t exist, just a unique index and a foreignkey. In this case, Version 7 now requires us to drop the foreign keybefore we drop the index, otherwise DB2 reminds us of this fact withSQLCODE –669.

“Just remember Wilburt, ‘Create the index first, then the constraint.When you want to drop the index, you must first drop either theconstraint (if one exists), or the foreign key (if no constraint exists)’.Of course, if we drop the table, then the constraints, indexes, andforeign keys all go down with the table, as always.”

NEW DB2 CATALOG TABLES

“Your earlier point about specifying the constraint name reminds meto bring to your attention, Charles, my discoveries from querying thenew DB2 catalog tables, where everything about constraints is stored.SYSIBM.SYSTABCONST contains one row for each constraint.SYSIBM.SYSKEYCOLUSE contains one row for each column ineach constraint. By joining these two tables on columnsCONSTNAME, TBCREATOR, and TBNAME, we can obtain acomprehensive report of both our primary and unique constraints. AnSQL statement that selects my favourite columns from these twotables is displayed below:

Page 37: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

37© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

�����

����������������

���������� ����

��������������

�����������"��

��������������

������������

��������������

������������B

������������

� �������������������������

�����������������������'���������

"%� ����������������������������

������������� ���� ����������� ����

���������������������������������������

� � ���

���������� ����

��������������

������������

����������������

“Charles, let’s look at the report produced by this query. It shows theconstraints we created in the second and third examples, and alsosome constraints created by the people in Department 123.”

�� ���� ���������������������������������B���������"�� ������

�����<������=%��� �� �#��� ������=�� � � �����< ������

�����<������=%��� ����%��� �����=��� � �����< ������

�����<������=%��� ����%��� �����=��� �=�� , �����< ������

���"� ����� ���=�� ���'�� ����=�'�� � � ���"� ����=�'

���"� ����� ���=�� �����B� ����=���B� � � ���"� ����=��

���"� ����� ���=�� �����B� ����=���B� � < ���"� ����=��

The columns are described as follows:

• TBCREATOR – owner of the parent table.

• TBNAME – name of the parent table.

• CONSTNAME – name of the constraint.

• TYPE – type of constraint (P = Primary, U = Unique).

• COLNAME – name of the column.

• COLSEQ – numeric position of the column in the key.

• COLNO – numeric position of the column in the table.

• IXOWNER – owner of the index enforcing the constraint.

• IXNAME – name of the index enforcing the constraint.

Page 38: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 38

NAMING CONVENTIONS FOR CONSTRAINTS

“Viewing the information in your report, Wilburt, I know enough toreconstruct the constraint parameters in DEPT123’s CREATE TABLEDDL, shown above. The names they chose for their constraints andcolumn names give us good clues about the reason for two uniquekeys on the same table. Referring back to the report, it appears thatthey are using an identity column for a surrogate key as the primarykey. Looking at the columns in unique constraint EMPLHIST, I wouldsay this table is a history of the dates of service of all the employeeswho have worked in the department. With EMP_STRT_DT as part ofthe key, it allows for employees who leave the department and returnat a later date.

�����������������<�����=%���

�������������� �!"#$ $%$� &'

����� �������� �#���

������ ��� �

�������������=��!

������ ����������%���

��������B��

������������ �(�

�����������������������

“Instituting good naming conventions for constraints, which helpsdescribe their meaning and purpose, is a good idea, as it is in generalfor DB2 objects. It gives us a new opportunity to self-document andconvey information about the design of our structures for developersand others who rely on the DB2 catalog to answer their questions.”

SOME THINGS NEVER CHANGE

“I did a little digging into the DB2 catalog myself, Wilburt, and foundthat the KEYSEQ column in SYSIBM.SYSCOLUMNS is still beingmaintained in Version 7. Therefore, all of our existing primary keyreports are still reliable. They just won’t show the constraint nameunless we update them to reference the new catalog tables. Of course,since we couldn’t tell from the catalog before Version 7 the exact stateof unique constraints, we didn’t write queries about them.”

Cathy LappeBMC Software (USA) © BMC Software 2001

Page 39: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

39© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

DB2 stored procedures and dynamic cursors

With a more complete implementation of stored procedures in DB2Versions 5 and 6, many new distributed access opportunities havebeen given to the DB2 developer. Many shops, ours included,severely limited or completely denied Dynamic SQL access tooperational Online Transaction processing (OLTP) databases. Thefear of reducing CICS response time by even tenths of a second wasenough to keep Dynamic SQL out of all mission-critical databases.

At the same time, a great deal of pressure was mounting to give greateraccess to mission-critical data via the Web. Statically bound storedprocedures were viewed as the optimal solution for this problem.Utilizing stored procedures with a combination of Active ServerPages (ASP) and ActiveX Data Objects (ADO) produced guaranteedaccess paths, with known performance results.

The newly-allowed DB2 access from the Web platform resulted instored procedures becoming an integral member in the tool set usedto produce distributed applications. In a very short time, hundreds ofstored procedures were written, providing much-needed DB2 accessand extending the OLTP database information to the Web.

However, as with any solution, stored procedure use was pushed untila definite weakness was exposed. Statically bound SQL has theadvantage of pre-defined access paths, but it lacks the ability tochange in a reporting type of environment. Many of the Webapplications being developed needed the ability to perform sorts andlook-ups based on a varying number of predicates.

Using Dynamic SQL, you would create a new query based on theuser’s input and re-issue the SQL statement to DB2. In the storedprocedure environment, the same task was being performed byinserting additional SQL into the COBOL programs. What started outas one cursor turned into multiple cursors with different predicatesand sort orders.

Page 40: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 40

Below is just one example of the problem that faced the storedprocedure programmer.

Initial query:

�������./=�����./=�����22P=�=������22P=�=�����9/6=�����/-/1=��E9C=

"%� ���-./=�����'��"�=���=��

������-P/9-:=������

������41=����G�&

� � �����./=�����/-/1=

Some sort and predicate variations:

"%� ���-./=�����'��"�=���=��

������-P/9-:=������

������41=����K�&

� � �����./=�����/-/1=

"%� ���-./=�����'��"�=���=��

������-P/9-:=������

������41=����G�&

� � �����./=����E9C=

"%� ���-./=�����'��"�=���=��

� � �����./=�����41=���

"%� ���-./=�����'��"�=���=��

������?8>71=����G������

� � �����?8>71=���

In each case, the access path selected utilized an index on Lst_NM;the only difference was sort order and/or the number of predicates. Asone can see, the number of cursors needed to support the user requestis equal to the number of possible sort orders multiplied by the numberof predicate combinations. A simple Dynamic query coded as StaticSQL in a stored procedure can result in an unmanageable number ofcursors. One example we encountered had two predicate variations,with nine possible sort orders resulting in 18 different cursors. Clearlythis was not acceptable.

We determined that it was necessary to combine the use of storedprocedures with Dynamic SQL. Using Dynamic SQL within staticallybound modules is nothing new. However, using it with the new cursorcapabilities within stored procedures is.

Stored procedures use the RESULT-SET-LOCATOR in order to

Page 41: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

41© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

address where the answer set from a cursor is returned to. Wecombined this capability with a dynamically-prepared cursor. Ouronly requirement was that the dynamically-prepared cursor has aknown access path. This meant that one or more predicates thatresulted in a known access path had to be coded in the COBOLprogram. Other predicates and sort orders could be added or changed,but those predicates that were pre-determined to provide efficientaccess had to be hard-coded.

Below is one way this can be accomplished using the COBOLSTRING function.

Defined in Working Storage:

������������0��0����������������������#���B���������

������������������������������������ �����0���0����� ��� ���#�

����"�0�����0����������

����,+��"�0�����0���������0����������+��,!������������I+++�

����,+��"�0�����0���������0������������+++!�

�����B����� ����������0� 0��� ��

�����"��%� ��� ���� ������

�������0����

Coded in the Procedure Division:

�� ��#�J�����J

��������B�0�����0�� 0������5�B�0�����0�� 0���#�%!

�������J�� ������=���������J

�������J�"%� �J

�������J����=�����'����M�J

�������J����J

��������B�0� �����=�� =������5�B�0� �����0�� 0���#�%!

��������B�0� � ��0�� 0������5�B�0� � ��0�� 0���#�%!

������������������E�

����������"�0�����0���������0����

�����B�

������ ��� ��������� ���5"�0�����0���������

�������0����

�����B�

������������������0� 0�

�������0����

This example demonstrates the extreme amount of flexibility that this

Page 42: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 42

solution can provide. Here, the developer can choose to supply eitherno additional predicates or as many as they like. The same can be saidof the sort order. This example will work if no sort order is provided,or if many columns are included in the order by clause. However, insome instances, the column(s) specified in the order by statementneed to be referenced by integer position, instead of column name (forexample: ORDER BY 2,1).

In this example, the columns selected are being determined by thedeveloper. This means one cursor could satisfy a SELECT count(*) orreturn a list of all employees with a last name beginning with S%. Inany case, since LST_NM is included as a hard-coded predicate, theaccess path should use the index associated with the LST_NMcolumn.

By utilizing Dynamic cursors in a controlled manner, the distributeddeveloper can be given as much control as the DBA deems necessaryand safe. If the developer codes an incorrect column name, a SQLerror will occur in the PREPARE statement. This error situation canbe eliminated by forcing the stored procedure caller to specifyparameters that indicate which columns they want returned, insteadof the column name. This method would also control which columnsare accessible via the stored procedure, thus adding an additionallevel of security.

Cursors could also be asked to return a list of columns separated bycommas (CSV file). The developer may want to feed an answer setdirectly into MS Excel. He could request that the answer set returncolumn1 || ‘,’ || column2 || ‘,’ etc. Again, one cursor could be used foran almost limitless combination of answer sets as long as the callercan handle them.

An additional benefit of using Dynamic cursors in a stored procedureenvironment is that you can use Dynamic SQL without having togrant direct access to the underlying objects. A developer’s bestsecurity work in a distributed application can be useless if the user iscapable of bypassing the application. Most distributed applicationsusing Dynamic SQL require that all users have access to the actualDB2 objects. With this access, users can use MS Access or some otherODBC tool instead of the application. In the stored procedure

Page 43: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

43© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

environment, access to only the stored procedure is given to the caller.No authorization is needed to any object referenced within the storedprocedure.

We have found including Dynamic cursors within DB2 storedprocedures to be an extremely valuable tool. We now have theflexibility of Dynamic SQL, in a very controlled environment.Depending on the application, and the DB2 knowledge that specificdevelopers have, you can give a varying amount of control to what theDynamic SQL can perform.

Below is a complete working example of a DYNAMIC cursor withsomewhat more limited flexibility:

����������������������������

�������� �# ��0����������� �

�����������������������������������������������������������������������

���������))�%���� �# ���������������������� ��� ��� ��)))0

���������� �# ��5������� �0���'������������� ������� �����

�������������������������������� �����������

����������� ����5

��������������������%���� ������������%� ��� ������� ����������

������������ �� ������������ ��%������ ������� �����������

������������������B�������������������� ������������������ �

�����������������������#�� �������#!�� ������������"��#���

�����������+����� ������ ��� � ���� ���%������������ �������

�����������������������������������������������������������!�

���������� �������#�5

������������� ����%���� ��������������%� �� ������� �������

�����������������������

��������������������������'�5

����������������� ����B���������������������$������� �

���������������� ���0����� � �%����

����������� ���������������

�������������������

�����������������������������������������������������������������������

�������������"��� �'�����#����������� ���#��������������������

�����������������������������������������������������������������������

�������"� '��#0��� �#���������

�������

�����������"�0"� '��#0��� �#�0���� �����������������<&!��������

����������������� �"� '��#���� �#����#����%� ���

�������

�����������"�0�B��

������������ ��"�0�B����������������������������)++��������E� ��

������������ ��"�0�B��0����������������������������!��������������

�������

�����������"�0�����0�B��

Page 44: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 44

�����������,+��"�0�����0�B�0����������������+��,!������������I&���

�����������,+��"�0�����0�B�0������������������&��!�

���������� ������� �� ��B������

�����������"�0�����0�B�0 ������

������������ ������� ���������������������������������!���������������

������������ ������� ��������������������������������+!

����������������������� �� �=���

������������ ������� ��������������������������������+!

��������������������������=���

������������ ������� ��������������������������������+!

��������������������������=����

������������ ������� ��������������������������������+!

��������������������������=����=����

������������ ������� ��������������������������������+!

������������������������ #�=���

������������ ������� ���������������������������������!

�����������������������������=��

������������ ������� ��������������������������������+!

���������������������������==����

������������ ������� ���������������������������������!

���������������������������=����=��

������������ ������� ��������������������������������+!

�������������������������=����==����

������������ ������� ���������������������������������!

�����������������������������=���=����

������������ ������� ��������������������������������+!

���������������������������=���

������������ ������� ��������������������������������+!

����������������������������"=��=���

������������ ������� ��������������������������������+!

����������������������� �� =����

������������ ������� ��������������������������������+!

����������������������� �� =����=����

������������ ������� ��������������������������������<!

����������������������� ���������= �� ��������

������������ ������� ��������������������������������<!

��������������������������������$=����=�����

������������ ������� �������������������������������<<!

����������������������"%� ��������=���������������=��

������������ ������� �������������������������������<$!

�������������������������������=����=���������=����=���

������������ ������� ��������������������������������,!

����������������������������� ���=���=������

������������ ��"�0 ���0���0�0 �����������������+��+!�

������������ ������� �������������������������������� !

���������������������J�������� #�=�����"�����J�

������������ ��"�0��#��0� #�0�0 ���������������������!�

������������ ������� ���������������������������������!

���������������������J������J�

������������ ��"�0��0� #�0�0 �����������������������!�

������������ ������� �������������������������������� !

Page 45: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

45© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

���������������������J�����������=����"�����J�

������������ ��"�0��#��0����00 ���������������������!�

������������ ������� ���������������������������������!

���������������������J������J�

������������ ��"�0��0����00 �����������������������!�

������������ ������� ���������������������������������!

���������������������J�J�

������������ ��"�0� � 0��0������0 �

������������������������ �����������������������������!

���������������������������� � ������

�������������������"�0� � 0��0�����0 ��������������$!�

������������������������ �����������������������������!

�����������������������������

�������������������"�0� � 0��0��0 0��������������,!�

������������������������ ����������������������������$!

������������������������������=����==����

������������������������ �����������������������������!

�����������������������������

�������������������"�0� � 0��0��0 0��������������,!�

���������������� �� ��B������

�����������"�0�����0�B�0�����

������������ ������� ���������������������������������!���������������

������������ ������� ��������������������������������$!

����������������������� �� �=���

������������ ������� ��������������������������������$!

��������������������������=���

������������ ������� ��������������������������������$!

��������������������������=����

������������ ������� ��������������������������������$!

��������������������������=����=����

������������ ������� ��������������������������������$!

������������������������ #�=���

������������ ������� ��������������������������������$!

�����������������������������=��

������������ ������� ��������������������������������+!

���������������������������==����

������������ ������� ��������������������������������$!

���������������������������=����=��

������������ ������� ��������������������������������+!

�������������������������=����==����

������������ ������� ��������������������������������$!

�����������������������������=���=����

������������ ������� ��������������������������������$!

���������������������������=���

������������ ������� ��������������������������������$!

����������������������������"=��=���

������������ ������� ��������������������������������$!

����������������������� ���=����

������������ ������� ��������������������������������$!

����������������������� ���=����=����

������������ ������� ��������������������������������<!

Page 46: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

© 2001. Xephon UK telephone 01635 33848, fax 01635 38345. USA telephone (303) 410 9344, fax (303) 438 0290. 46

����������������������� ���������= �� ��������

������������ ������� ��������������������������������<!

��������������������������������$=����=�����

������������ ������� �������������������������������<<!

����������������������"%� ��������=���������������=��

������������ ������� �������������������������������<$!

�������������������������������=����=���������=����=���

������������ ������� ��������������������������������,!

���������������������������� �� =���=�������

������������ ��"�0 �� 0���0�0������������������+��+!�

������������ ������� ��������������������������������,!

������������������������ ��� #�� =���=��������

Editor’s note: this article will be concluded in the next issue.

Tim AlbrechtDB2 Database Administrator (USA) © Xephon 2001

Accounting 92.3-15, 103.11-29Active log status 77.3-9Administration 107.40-51, 108.35-43Ageing data 80.3-8ALTER 91.23-32,

92.17-22, 94.43-47ALTERing DSETPASS 77.35-38Back-up 86.3-22, 89.7Business Intelligence 97.19-25, 104.3-12Case study 95.34-36Catalog 95.3-7Catalog information 86.38-47, 87.20-37Catalog statistics 78.8-24, 79.15-23CICS 102.8-22Cloning 99.12-22COPYTOCOPY 109.3-8Coupling facility 88.29-39, 89.8-30CREATE 91.23-32Creating DB2 statements 78.3-8Data copying 76.7-24Data display 101.39-47Data warehouse 81.14-22,

83.43-47, 86.23-28

DATE 98.3-8DB2 Version 5 76.3-6DB2 Version 6 77.39-47, 94.34-42DCLGEN output 76.25-31DDF thread 107.3-13DDL 91.23-32Design tips 99.3-11Dictionary pages 108.32-34DISTINCT 88.40-47DRDA 97.35-47, 98.33-47Dropped tables 106.3-6DSETPASS 77.35-38DSN1COPY 89.31-47, 90.29-47,

91.14-22, 109.8-12DSNHDECP 101.39-47, 104.13-21DSNTEP2 85.3-9, 102.23-30DSNTIAUL 91.3-13, 92.32-47, 96.3-8DSNZPARM 90.29, 104.13-21DSNZPARM load module 80.24-37,

81.35-47, 82.14-25Dump 102.8-22Dynamic cursors 109.39-45Dynamic SQL 93.3-7

November 1998 – November 2001 index

Items below are references to articles that have appeared in DB2 Update since November1998. References show the issue number followed by the page number(s). Back-issues of DB2Update are available back to Issue 73 (November 1998). See page 2 for details.

Page 47: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

47© 2001. Reproduction prohibited. Please inform Xephon of any infringement.

E-business 100.18-28EXPLAIN 102.31-47Extent checker 81.22-34, 82.37-47Fastunload 101.15-38FIELDPROC 79.23-33, 80.38-47Fuzzy logic 94.13-17Fuzzy SELECT 87.13-19, 89.3-7GROUP BY 98.27-33, 100.12-18IFCID6 records 73.3-12Image copy 79.3-14, 91.3-13,

92.32-47, 95.37-47, 96.29-37Imagecopy 106.29-54Index 74.3-6, 81.3-13,

82.9-13, 93.18-31, 93.32-47Index, Type 1 81.3-13Index, Type 2 74.3-6, 81.3-13, 82.9-13Indexspace 87.37-47, 88.10-29Installation 94.34-42Java 83.23-35, 84.3-10, 97.3-10JDBC 95.8-33, 97.7-10Joins 97.11-18, 101.8-12Linux 94.3-9LISTCAT output 78.25-32LISTCAT 90.3-15, 92.17-22,

94.43-47, 98.15-26, 105.23-30MODIFY RECOVERY 85.18-31MODIFY 90.16-22Monitor 88.29-39, 89.8-30Monitoring 87.3-13OLAP 102.3-7, 103.29-33, 105.3-7On-line statistics 69.17-19Optimizer 94.9-12Parallel operations 107.14-19Performance 109.8-12PL/I 76.25-31Plan table 85.32-47, 92.23-31PLAN/PACKAGE management

73.26-47, 74.6-20, 75.7-21Positioning 107.39Primary key constraints 109.31-38Procedural DBA 88.3-9QMF user-id 74.45-47Query 105.7-22Query Patroller 96.38-47, 97.19-25Query performance 107.14-19REBIND 85.18-31Recover 101.3-7, 106.3-6,

107.20-38, 109.17-30Recovery 91.3-13, 92.32-47,

98.8-14, 99.28-39Referential integrity 82.26-36

Relational database 83.43-47Relinking DB2 modules 73.13-16REORG 77.10-16Reorganizing 93.7-17Restricted tablespaces 82.3-9REXX 99.40-47, 100.3-11RI constraints 108.3-13RUNSTATS 85.18-31, 96.3-8Simulate production environment 73.17-25SMART REORG 77.10-16SnapShot 99.12-22Space 87.3-13SPUFI panels 75.43-47SQL 75.43-47, 76.3-6SQLJ 84.3-10, 95.8-33, 97.7-10Start-up parameters 78.32-47, 79.34-47Statistics 92.15-16, 94.18-33Stopping DB2 100.28-47, 101.12-14Stored procedures 99.23-28, 109.39-45SUPERCE 75.3-6Syntax check 91.23-32SYSCOPY 90.22-23,

96.9-28, 108.13-31Table information 84.36-45,

85.9-17, 86.29-37Tablespace, modified 83.5-22Tablespace, restricted 82.3-9Tablespaces 83.3-5, 87.37-47,

88.10-29, 103.3-10,104.22-34, 107.20-38

Thin workstation 91.32-47TIME 98.3-8Timestamp checking 83.35-42, 84.29-35TIMESTAMP 98.3-8Trace analysis 84.11-29Triggers 77.39-47UDB text extenders 108.44-47UNION 106.7-12User-defined functions 103.34-47,

104.35-47, 109.12-16Utilities 105.31-51, 106.12-28, 107.19Utility services 74.21-44, 75.22-42,

76.31-45, 77.17-34Verify start-up parameters 78.32-47,

79.34-47Version 6.2 97.26-35Version 7 97.26-35VSAM extents 80.9-20VSAM to DB2 conversion 80.20-23Year 2000 76.46-47

Page 48: DB2 Nov title2 - CBT Tape · certain DB2 catalog (SYSCOPY in DSNDB06) and DB2 directory (DSNDB01 and SYSUTILX both in DSNDB01) objects. The COPYTOCOPY …

IBM has announced QMF High PerformanceOption (HPO) as a direct feature of DB2 forOS/390 V6 and DB2 for z/OS and OS/390V7, and of QMF, QMF for Windows, andQMF HPO for z/OS and OS/390 V7.

QMF has new capabilities for theworkstation environment and enhancementsfor the mainframe that help access andpresent data better. V7 works with data fromDB2 for OS/390, DB2 for VSE and VM,DB2 for AS/400 to workstation serversrunning OS/2, Windows NT, AIX, and otherUnix operating systems and massivelyparallel processors.

When coupled with DB2 DataJoiner, itallows access to non-relational and other datasources.

QMF V7 enhancements include improvedcommand processing and defaults, new DB2data types for large objects, VSE DRDARUOW Application Requestor and DB2 forAS/400 support, Java-based query from aWeb browser, aggregation, grouping, andformatting in the query results, point-and-click interface to QMF Form creation, and apersonal data portal for the desktop, whichcan be used for launching centrally-sharedqueries and reports, sending results todesktop tools and browsers, and sharingalready-formatted spreadsheets.

For further information contact your localIBM representative.URL: http://www.ibm.com/qmf.

* * *

Savvion is to integrate DB2 UDB with theSavvion BusinessManager, promising themeans to automate and manage variedbusiness processes, ranging from enterprise-wide procurement through asset

management to human resource systems.

BusinessManager helps automate operationsboth internally and across enterprises.Integrated management systems, includingbalanced scorecards, allow managers tocontinuously monitor, measure, and improveoperational efficiencies.

Integrating DB2 as the database, says thefirm, helps simplify database integrationwhile optimizing system operation.

For further information contact:Savvion, 5000 Old Ironsides Drive, SantaClara, CA 95054, USA.Tel: (40) 330 3400.URL: http://www.savvion.com.

* * *

IBM has announced new tools, functions,and tool integration for its DB2 UDB andIMS databases. These include the DB2Administration Tool for z/OS, Version 3.1,DB2 Automation Tool for z/OS, Version 1.2,DB2 High Performance Unload for z/OS,Version 1.2, DB2 Log Analysis Tool forz/OS, Version 1.2, DB2 Object Restore forz/OS, Version 1.2, DB2 Table Editor foriSeries, Version 4.2, and DB2 Table Editorfor z/OS, Version 4.2.

Other tools include IBM DataPropagator forz/OS, Version 3.1, DB2 Buffer PoolAnalyzer for z/OS, DB2 SQL PerformanceAnalyzer for z/OS, Version 1.2, DB2 DataExport Facility for z/OS, DB2 Web QueryTool for iSeries, Version 1.2, and DB2 WebQuery Tool for z/OS, Version 1.2.

For further information contact your localIBM representative.URL: http://www.ibm.com/software/data.

DB2 news

� xephon