Natural DB2 PDF
Natural DB2 PDF
-1
Cover Page Natural for DB2 Version 3.1.4 for Mainframes
This document applies to Natural for DB2 Version 3.1.4 and to all subsequent releases. Specifications
contained herein are subject to change and these changes will be reported in subsequent release notes or
new editions.
Software AG and/or all Software AG products are either trademarks or registered trademarks of
Software AG. Other products and company names mentioned herein may be the trademarks of their
respective owners.
0
Natural for DB2 Version 3.1.4 for Mainframes
Table of Contents
Natural for DB2 - Overview . . . . . . . . . . . . . . . . 1
Natural for DB2 - Overview . . . . . . . . . . . . . . . 1
New Features . . . . . . . . . . . . . . . . . . . 3
New Features . . . . . . . . . . . . . . . . . . . 3
The Natural for DB2 Server Stub . . . . . . . . . . . . . . 3
New Natural Statement CALLDBPROC . . . . . . . . . . . . 3
Issuing DB2 Commands from Natural . . . . . . . . . . . . . 3
Procedure Maintenance . . . . . . . . . . . . . . . . 3
How to Write Stored Procedures in Natural . . . . . . . . . . . . 3
General Information . . . . . . . . . . . . . . . . . 4
General Information . . . . . . . . . . . . . . . . . 4
Accessing a DB2 Table . . . . . . . . . . . . . . . . 4
Integration with Predict . . . . . . . . . . . . . . . . 4
Natural System Messages Related to DB2 . . . . . . . . . . . . 5
Installation . . . . . . . . . . . . . . . . . . . . 6
Installation . . . . . . . . . . . . . . . . . . . 6
Installation Jobs . . . . . . . . . . . . . . . . . . 6
Using System Maintenance Aid . . . . . . . . . . . . . . 6
Prerequisites . . . . . . . . . . . . . . . . . . 6
The Installation Tape . . . . . . . . . . . . . . . . 7
Copying the Tape Contents to Disk . . . . . . . . . . . . . 7
Installation Procedure . . . . . . . . . . . . . . . . 8
Steps Common to all Environments . . . . . . . . . . . . . 8
Steps Specific to a CICS Environment . . . . . . . . . . . . 13
Steps Specific to a Com-plete Environment . . . . . . . . . . . 17
Steps Specific to an IMS/TM Environment . . . . . . . . . . . 17
Steps Specific to a TSO Environment . . . . . . . . . . . . 19
Installation Verification . . . . . . . . . . . . . . . . 20
Sample Batch Verification Jobs . . . . . . . . . . . . . 20
Online Verification Methods . . . . . . . . . . . . . . 21
Natural Parameter Modification for DB2 . . . . . . . . . . . . 22
Natural Profile Parameter Settings . . . . . . . . . . . . . 22
Performance Considerations for the DB2SIZE Parameter . . . . . . . . 23
The Parameter Module NDBPARM . . . . . . . . . . . . . 25
Parameters in NDBPARM . . . . . . . . . . . . . . . 26
The Natural for DB2 Server Stub . . . . . . . . . . . . . . 31
Special Requirements for Natural Tools for DB2 . . . . . . . . . . 34
Retrieval and Explain Functions . . . . . . . . . . . . . 34
LISTSQL and Explain Functions . . . . . . . . . . . . . 35
Natural Tools for DB2 - Overview . . . . . . . . . . . . . . 36
Natural Tools for DB2 - Overview . . . . . . . . . . . . . . 36
Using Natural Tools for DB2 . . . . . . . . . . . . . . . 37
Using Natural Tools for DB2 . . . . . . . . . . . . . . . 37
Invoking the Natural Tools for DB2 . . . . . . . . . . . . . 37
Main Menu - Functions . . . . . . . . . . . . . . . 37
Editing within the Natural Tools for DB2 . . . . . . . . . . . . 38
Global PF-Key Settings . . . . . . . . . . . . . . . . 40
i
Natural for DB2 Version 3.1.4 for Mainframes
ii
Natural for DB2 Version 3.1.4 for Mainframes
iii
Natural for DB2 Version 3.1.4 for Mainframes
iv
Natural for DB2 Version 3.1.4 for Mainframes
v
Natural for DB2 Version 3.1.4 for Mainframes
vi
Natural for DB2 Version 3.1.4 for Mainframes Natural for DB2 - Overview
In general, there is no difference between using Natural with DB2 and using it with Adabas, VSAM or
DL/I. The Natural interface to DB2 allows Natural programs to access DB2 data, using the same Natural
DML statements that are available for Adabas, VSAM, and DL/I. Therefore, programs written for DB2
tables can also be used to access Adabas, VSAM, or DL/I databases. In addition, Natural SQL statements
are available.
All operations requiring interaction with DB2 are performed by the Natural interface module.
Natural Version 3.1 or above is required for Version 3.1 of Natural for DB2.
Note:
The term "file server" used this documentation only refers to the Natural file server for DB2.
1
Natural for DB2 - Overview Natural for DB2 Version 3.1.4 for Mainframes
General Information Information on how to access DB2 tables, on the integration with
Software AG’s Data Dictionary Predict, and on error messages
related to DB2
DDM Generation Generation of Natural data definition modules (DDMs) using the
SQL Services function of the Natural SYSDDM utility.
Dynamic and Static SQL Internal handling of dynamic statements, creation and execution of
Support static DBRMs, mixed dynamic/static mode, and application plan
switching in the various supported environments.
Statements and System Special considerations on Natural DML statements, Natural SQL
Variables statements and Natural system variables with DB2. In addition, the
Natural for DB2 enhanced error handling is discussed.
Statement Logging Facility to log the SQL statements contained in an executing Natural
program.
Interface Subprograms Several Natural and non-Natural subprograms to be used for various
purposes.
The Natural File Server for Description of the Natural File Server in the various supported
DB2 environments.
2
Natural for DB2 Version 3.1.4 for Mainframes New Features
New Features
This section covers the following topics:
Procedure Maintenance
Procedure Maintenance provides easier handling of stored procedures, data areas and PARMLISTS.
3
General Information Natural for DB2 Version 3.1.4 for Mainframes
General Information
This section covers the following topics:
The Natural interface to DB2 translates the statements of a Natural program into SQL statements.
Natural automatically provides for the preparation and execution of each statement. In dynamic mode, a
statement is only prepared once (if possible) and can then be executed several times. For this purpose,
Natural internally maintains a table of all prepared statements.
Almost the full range of possibilities offered by the Natural programming language can be used for the
development of Natural applications which access DB2 tables. For a number of Natural DML statements,
however, there are certain restrictions and differences as far as their use with DB2 is concerned; see
Natural DML Statements. In the Natural Statements documentation, you can find notes on Natural usage
with DB2 attached to the descriptions of the statements concerned.
As there is no DB2 equivalent to Adabas ISNs (Internal Sequence Numbers), any Natural features which
use ISNs are not available when accessing DB2 tables with Natural.
For SQL-eligible databases, in addition to the Natural DML statements, Natural provides SQL statements.
In the Natural Statements documentation you can find a detailed description of these statements.
DB2 databases, tables and views can be incorporated and compared, new DB2 tables and views can be
generated, and Natural DDMs can be generated and compared. All DB2-specific data types and the
referential integrity of DB2 are supported. See the relevant Predict documentation for details.
In addition, the Predict active references support static SQL for DB2.
4
Natural for DB2 Version 3.1.4 for Mainframes General Information
5
Installation Natural for DB2 Version 3.1.4 for Mainframes
Installation
This section describes step by step how to install the Natural interface to DB2 (in the remainder of this
section also referred to as NDB) in the various environments supported.
The installation procedures contain a number of options that depend on the TP monitor being used as well
as on other site requirements.
Installation Jobs
Using System Maintenance Aid
Prerequisites
The Installation Tape
Installation Procedure
Installation Verification
Natural Parameter Modification for DB2
The Parameter Module NDBPARM
Special Requirements for Natural Tools for DB2
The Natural for DB2 Server Stub
Installation Jobs
The installation of Software AG products is performed by installation "jobs". These jobs are either created
"manually" or generated by System Maintenance Aid (SMA).
For each step of the installation procedure described later in this section, the job number of a job
performing the respective task is indicated. This job number refers to an installation job generated by
SMA. If you are not using SMA, an example job of the same number is provided in the job library on the
NDB installation tape; you must adapt this example job to your requirements. Note that the job numbers
on the tape are preceded by a product code (for example, NDBI070).
Prerequisites
Base Natural Version 3.1 or above must be installed first; you cannot install Natural 3.1 and Natural
for DB2 Version 3.1 at the same time.
The Software AG Editor must be installed (see Installing The Software AG Editor in the Natural
Installation Guide for Mainframes).
If you want to use the DB2 DL/I batch support (DSNMTV01), the Natural interface to DL/I is
required.
If you want to share your FUSER system file between Natural 2.2 and Natural 3.1. INPL update tape
NQ3404 must be applied to your Natural 2.2 environment.
6
Natural for DB2 Version 3.1.4 for Mainframes Installation
Further product/version dependencies are specified under Other Software AG Products and
Operating/Teleprocessing Systems Required in the Natural Version 3.1.4 Release Notes for Mainframes.
The notation nnn in dataset names represents the version number of the product.
In the dataset names, replace nnn with the current version number of the datasets.
With the SER parameter, replace xxxxxx with the volume serial number of the tape.
With the LABEL parameter, replace x with the sequence number of the tape dataset (see the Report
of Tape Creation).
With the VOL=SER parameter, replace yyyyyy with the volume serial number of the disk pack.
With the SPACE parameter, specify the required space for the dataset.
// JOB CARD
//V2COPY EXEC PGM=IEBCOPY
//SYSPRINT DD SYSOUT=A
//IN1 DD DSN=NDBnnn.JOBS,DISP=OLD,UNIT=TAPE,
VOL=(,RETAIN,SER=xxxxxx),LABEL=(x,SL)
//OUT1 DD DSN=SAGLIB.NDBnnn.JOBS,DISP=(NEW,CATLG,DELETE),
UNIT=SYSDA,VOL=SER=yyyyyy,SPACE=(CYL,(1,1,10))
//SYSIN DD *
C I=IN1,O=OUT1
/*
Then adapt and run the job NDBTAPE from the job dataset to copy the load and source libraries from tape
to disk. The sample jobs use the sequential datasets directly from tape. The dataset type and the space it
requires on disk are shown in the Report of Tape Creation.
7
Installation Natural for DB2 Version 3.1.4 for Mainframes
Installation Procedure
This section describes how to install Natural for DB2 in various environments:
Allocate a PDS as DBRM library. The size of this dataset and the number of directory entries depend on
the particular site (5 tracks and 20 directory blocks should be adequate for most environments). The PDS
should have a fixed-block record format and a record length of 80.
Any standard dataset name can be used for this DBRM library; however, this installation procedure
assumes that the name SAGLIB.SMADBRM is used.
Step 2: Generate the NDB I/O module NDBIOMO - Job I055, Step 1600
By executing a standard Natural batch job, this step generates the assembly source for NDBIOMO from
the member NDBIOTM.
This batch job invokes the Natural program NDBGENI, which is loaded with INPL during the base
Natural installation. NDBGENI contains the following two parameters, which you can modify to meet
your specific requirements:
NDBIOMO performs the dynamic access to DB2 and contains all necessary EXEC SQL statements. In
addition, it contains some special SQL statements which cannot be executed in dynamic mode.
An output report is created by this job and should be checked for successful completion. In addition, a
condition code of 0 indicates normal completion.
8
Natural for DB2 Version 3.1.4 for Mainframes Installation
Note:
The link-edit step receives a condition code of 4 because of unresolved references for DSNHLI. This
is normal and can be ignored.
If desired, change library names and plan name to meet site requirements.
The NDB parameter module contains the macro NDBPRM with parameters specific to the Natural
interface to DB2.
You can generally use the default values for all parameters. Modify only the values of the parameters
whose default values do not suit your requirements.
The individual parameters are described in the section The Parameter Module NDBPARM.
Link-edit the environment-independent NDB nucleus NATGWDB2. Verify that the INCLUDE cards refer
to the corresponding DD names for the load libraries.
Adapt your Natural parameter module NATPARM by adding parameters specific to Natural for DB2 and
re-assemble NATPARM.
9
Installation Natural for DB2 Version 3.1.4 for Mainframes
Modify the JCL used to link your Natural shared nucleus by adding the following INCLUDE card:
Modify the JCL used to link your Natural environment-dependent nucleus by adding the following
INCLUDE cards and the corresponding DD statements:
If you want to use the Natural File Server, include SMALIB(NDBPARMF) or SMALIB(NDBPARME)
instead of SMALIB(NDBPARM); see also Step 5 above.
Note:
If you want to use NDB in various environments (that is, with different TP monitors), you must
repeat this step for each of these environments.
10
Natural for DB2 Version 3.1.4 for Mainframes Installation
Instead of link-editing your Natural nucleus in the way described above, you have the following
alternatives:
1. If you do not use a Natural shared nucleus, all modules must be included in the link-edit of the
Natural nucleus.
2. Remove NATGWDB2 from the link-edit of the Natural shared nucleus and run it as a separate
module with the mandatory entry name NATGWDB2. You can modify the name of the module
created in Step 6. However, if you use a name different from NATGWDB2, this name must be
specified as an alias name in an NTALIAS macro entry of the Natural parameter module. This way
of link-editing only applies if the Natural Resolve CSTATIC Addresses feature (RCA) is used.
3. Include all modules in the link-edit job of a separate Natural parameter module with the mandatory
entry name CMPRMTB. The name of the resulting module is arbitrary. This way of link-editing only
applies if an alternative parameter module (PARM profile parameter) is used.
If link-editing is done in this way, you can install NDB without having to modify your Natural
nucleus or driver.
TP-Monitor Requirement
CICS The resulting module must be defined via a PPT entry or RDO.
PPT entry:
DFHPPT TYPE=ENTRY,PROGRAM=module-name,PGMLANG=ASSEMBLER
Com-plete The resulting module must be defined as RESIDENTPAGE or reside in the LPA/(E)LPA.
Step 9: Load Natural objects into system file - Job I061, Step 1600
Before executing this step, change the CMWKF01 DD statement to point to the NDBnnn.INPL dataset.
In this step, the NDB system programs, maps and DDMs are loaded into the Natural system files. The
INPL job loads objects into the libraries SYSDDM, SYSTEM and SYSDB2.
The NDB system programs must be loaded into the Natural 3.1. FNAT system file.
Warning:
Ensure that your newly created SYSDB2 library contains all necessary Predict interface
programs, which are loaded into SYSDB2 when installing Predict (see the relevant
Predict documentation).
Step 10: Load Natural error messages into system file - Job I061, Step 1620
Before executing this step, change the CMWKF02 DD statement to point to the NDBnnn.ERRN dataset.
This step executes a batch Natural job that runs an error load program using the NDBnnn.ERRN dataset as
input. The ERRLODUS job loads error messages into the library SYSERR on the FNAT system file.
The NDB error messages must be loaded into the Natural 3.1. FNAT system file.
11
Installation Natural for DB2 Version 3.1.4 for Mainframes
Step 11: Create an NDB server stub - Job I070, Steps 1604,1606,1608,1610,1612,1614
Create a server stub to execute DB2 stored procedures written in Natural. A Natural for DB2 server stub is
an interface module between the DB2 database system and the Natural server. In order to execute DB2
stored procedures written in Natural, the server stub needs to be installed.
The Natural for DB2 server stubs are generated from the NDBSTUB macro. You can generally use the
default values for all parameters. Modify only the values of the parameters whose default values do not
suit your requirements. The individual parameters are described in the section The Natural for DB2 server
stub.
The resulting load modules have to be placed into a steplib library of the JCL used to execute the stored
procedure address space. Each stored procedure written in Natural has to be declared in a row of the
SYSIBM.SYSPROCEDURES table of the DB2 catalog and the LOADMOD column has to contain the
name of the generated Natural for DB2 server stub module (NDB31SRV).
12
Natural for DB2 Version 3.1.4 for Mainframes Installation
If you want fixed assignment of your transaction code to the DB2 plan, add an additional entry to your
RCT, or create a DB2Entry with RDO if you have CICS TS installed.
Step 1: Modify, assemble and link the CICS RCT or create a DB2Entry
Modify your RCT as follows (for any other parameters, refer to the relevant DB2 literature):
DSNRCT TYPE=ENTRY,PLAN=plan-name,TXID=(transaction-ID)
Or:
Define a DB2Entry with RDO (for parameters, refer to the relevant CICS literature):
DEFINE DB2ENTRY
OVERTYPE TO MODIFY CICS RELEASE = 0530
CEDA DEFine DB2Entry( )
DB2Entry : DB25ENTR
Group : NCI23
DEscription :
THREAD SELECTION ATTRIBUTES
TRansid : transaction-id
THREAD OPERATION ATTRIBUTES
ACcountrec : None None ! TXid ! TAsk ! Uow
AUTHId :
AUTHType : Userid Userid ! Opid ! Group ! Sign ! TErm
! TX
DRollback : Yes Yes ! No
PLAN : plan-name
PLANExitname :
PRIority : High High ! Equal ! Low
PROtectnum : 0005 0-2000
THREADLimit : 0005 0-2000
THREADWait : Pool Pool ! Yes ! No
The plan-name must be the same as the name used in step 4 (Create the NDB plan).
13
Installation Natural for DB2 Version 3.1.4 for Mainframes
If you want to perform plan selection by using the dynamic plan exit, perform the following steps:
Step 1: Assemble the CICS plan specification module NDBPLNA - Job I070, Step 1620
Note:
This step receives a condition code of 4 because of an unresolved external reference for DFHEAI0
and DFHEI1. This is normal and can be ignored.
Step 2: Assemble the CICS dynamic plan selection exit module NDBUEXT - Job I070, Step 1630
The sample exit NDBUEXT can be modified to use a default plan name if none has been specified prior to
the first SQL call. Review the source code in the module NDBUEXT for details about specifying a default
plan name.
Note:
This step receives a condition code of 4 because of an unresolved external reference for DFHEAI0
and DFHEI1. This is normal and can be ignored.
Step 3: Link-edit the CICS plan specification module NDBPLNA - Job I075, Step 1630
The resulting module NDBPLNA must be linked to the CICS load library and defined via a corresponding
PPT entry or RDO.
PPT entry:
DFHPPT TYPE=ENTRY,PROGRAM=NDBPLNA,PGMLANG=ASSEMBLER
Step 4: Link-edit the CICS dynamic plan selection exit module NDBUEXT - Job I075, Step 1640
The resulting module NDBUEXT must be linked to the CICS load library and defined via a corresponding
PPT entry or RDO.
PPT entry:
DFHPPT TYPE=ENTRY,PROGRAM=NDBUEXT,PGMLANG=ASSEMBLER
14
Natural for DB2 Version 3.1.4 for Mainframes Installation
Step 5: Modify, assemble and link the CICS RCT or create a DB2Entry
Modify your RCT as follows (for any other parameters, refer to the relevant DB2 literature):
DSNRCT TYPE=POOL,PLNPGME=NDBUEXT,PLNEXIT=YES
The parameter PLNPGME must specify the same program as the NAME statement of the link step above.
Or:
Define a DB2Entry with RDO if you have CICS TS installed (for parameters, refer to the relevant CICS
literature):
DEFINE DB2ENTRY
OVERTYPE TO MODIFY CICS RELEASE = 0530
CEDA DEFine DB2Entry( )
DB2Entry : DB25ENTR
Group : NCI23
DEscription :
THREAD SELECTION ATTRIBUTES
TRansid : transaction-id
THREAD OPERATION ATTRIBUTES
ACcountrec : None None ! TXid ! TAsk ! Uow
AUTHId :
AUTHType : Userid Userid ! Opid ! Group ! Sign ! TErm
! TX
DRollback : Yes Yes ! No
PLAN :
PLANExitname : NDBUEXT
PRIority : High High ! Equal ! Low
PROtectnum : 0005 0-2000
THREADLimit : 0005 0-2000
THREADWait : Pool Pool ! Yes ! No
The parameter PLANExitname must specify the same program as the NAME statement of the link step
above.
Alternatively or additionally, you can specify the plan exit program NDBUEXT with the PLANExitname
parameter of POOL THREAD ATTRIBUTES of the DB2Conn resource definition of CICS TS.
15
Installation Natural for DB2 Version 3.1.4 for Mainframes
If you want to use the Natural File Server (VSAM), perform the following additional steps:
Step 1: Define a VSAM dataset for the file server - Job I008, Step 1610
Specify the size and the name of the VSAM RRDS that is to be used as the file server.
Step 2: Format the file server dataset - Job I075, Step 1610
Specify the five input parameters required to format the file server dataset.
Shown below are sample additional CICS table entries needed for the file server and for the DB2
components of Natural:
FCT entry:
CMFSERV DFHFCT TYPE=DATASET, X
ACCMETH=VSAM , X
BUFND=5, X
BUFNI=4, X
DATASET=CMFSERV, X
DISP=SHR, X
DSNAME=SAGLIB.NCIDB2.SERVER, X
FILSTAT=(ENABLED,CLOSED), X
JID=NO, X
LOG=NO, X
LSRPOOL=NONE, 1-8 ONLY FOR XA; NONE X
RECFORM=(FIXED,BLOCKED), X
RSL=PUBLIC, X
SERVREQ=(ADD,UPDATE,DELETE,BROWSE), X
STRNO=4
16
Natural for DB2 Version 3.1.4 for Mainframes Installation
Ensure that the changes required for DB2 have been applied to your Com-plete environment (see the
relevant Com-plete documentation).
JOB I055 / Steps 1631, 1632, 1633, 1644 for IMS MPP conversational, IMS BMP Natural,IMS MPP
non-non-conversational, OBMP Natural
If desired, change library names and plan names to meet site requirements.
If the name (or any ALIAS) of your environment-dependent Natural nucleus does not match the name of
your DB2 plan, you must use an Resource Translation Table (RTT).
Add an additional DSNMAPN macro to your RTT as follows (for any other parameters, refer to the
relevant DB2 literature):
DSNMAPN macro:
DSNMAPN APN=load-module,PLAN=plan-name
The load-module represents the environment-dependent Natural nucleus (that is, the IMS application
program) and the plan-name is the same as the one used in the BIND step.
17
Installation Natural for DB2 Version 3.1.4 for Mainframes
Be aware that database loops cannot be continued across terminal I/Os without using the File Server.
If you want to use the Natural File Server (VSAM), perform the following additional steps:
Step 1: Define a VSAM dataset for the file server - Job I008, Step 1600
Specify the size and the name of the VSAM RRDS that is to be used as the file server.
Step 2: Format the file server dataset - Job I075, Step 1600
Specify the five input parameters required to format the file server dataset.
18
Natural for DB2 Version 3.1.4 for Mainframes Installation
If you want to use the Natural File Server (VSAM), perform the following additional steps:
Set the NDBFSRV parameter in the NATTSO macro to "Yes" and reassemble and relink your
Natural/TSO interface NATTSO.
Step 2: Define a VSAM dataset for the file server - Job I008, Step 1620
Specify the size and the name of the VSAM RRDS that is to be used as the file server.
Step 3: Format the file server dataset - Job I075, Step 1620
Specify the five input parameters required to format the file server dataset.
Sample JCL for Starting and Using Natural for DB2 under CAF
To test the TSO installation of NDB under CAF, perform the following steps:
Change the library and program names in the clist NDBCAF to meet site requirements. If you do not use
the file server, remove the ALLOC and FREE statements for CMFSERV.
Invoke Natural by executing the clist created in the previous step. Ensure that DB2 tables can be accessed
and that plan switching can be performed.
Before the first SQL call you must call NATPLAN to explicitly allocate the plan. The plan name must be
the same as the name used in step 4 (Create the NDB plan). NATPLAN can be edited to specify the
appropriate DB2 subsystem ID.
Sample JCL for Starting and Using Natural for DB2 under DSN
To test the TSO installation of NDB under DSN, perform the following steps:
Change the subsystem ID as well as the library, plan and program names in the clist NDBTSO to meet site
requirements. If you do not use the file server, remove the ALLOC and FREE statements for CMFSERV.
Invoke Natural by executing the clist created in the previous step. Ensure that DB2 tables can be accessed.
The plan name must be the same as the name used in the BIND step. For an explanation of the DSN and
RUN commands, refer to the relevant IBM documentation for DB2 TSO and batch users.
19
Installation Natural for DB2 Version 3.1.4 for Mainframes
Installation Verification
This section covers the following topics:
Test the Batch Mode Installation of NDB under CAF - Job NDBBATCA
NDBBATCA contains sample JCL to test NDB in batch mode using the CAF interface. Modify the
sample JCL to meet site requirements.
Before the first SQL call you must call NATPLAN to explicitly allocate the plan. The plan name must be
the same as the name used in step 4 (Create the NDB plan). NATPLAN can be edited to specify the
appropriate DB2 subsystem ID.
Test the Batch Mode Installation of NDB under DSN - Job NDBBATTB
NDBBATTB contains sample JCL to test NDB in batch mode using the DSN command processor.
Modify the sample JCL to meet site requirements.
The plan name must be the same as the name used in step 4 (Create the NDB plan). For an explanation of
the DSN and RUN commands, refer to the relevant IBM documentation for DB2 TSO and batch users.
NDBMTV01 contains a sample JCL to execute Natural using the DB2 DL/I batch support. Modify the
sample JCL to meet site requirements.
The plan name must be the same as the name used in step 4 (Create the NDB plan).
20
Natural for DB2 Version 3.1.4 for Mainframes Installation
To verify and check the installation of NDB using the SQL Services of the Natural SYSDDM
utility
1. Invoke Natural.
2. Invoke SYSDDM.
3. On the SYSDDM main menu enter function code "B" to invoke the SQL Services function.
Enter function code "S" and specify SQL system "DB2" to select all DB2 tables.
The communication between Natural and DB2 works if all existing DB2 tables are displayed.
For one of the tables, generate a Natural DDM as described.
4. After you have generated a DDM, access the corresponding DB2 table with a simple Natural
program:
Example:
FIND view-name WITH field = value DISPLAY fieldLOOP
END
If you receive the message NAT3700, enter the Natural system command SQLERR to display the
corresponding SQL return code. You can find the description of the SQLERR command in the section
Natural System Commands for DB2 (Natural Tools for DB2).
To verify and test your installation you can also use the sample programs DEM2* in the library SYSDB2
provided on the installation tape.
Using these sample programs, you can create a DB2 table using DEM2CREA and create the
corresponding DDM via SYSDDM. You can then store data in the created table using DEM2STOR and
retrieve data from the table using DEM2FIND or DEM2SEL. You can also drop the table using program
DEM2DROP.
21
Installation Natural for DB2 Version 3.1.4 for Mainframes
n1 the number of statements for dynamic access as specified as the second parameter in Job I055,
Step 1600;
n2 the maximum number of nested database loops as specified with the MAXLOOP parameter in
NDBPARM;
n3 the maximum number of file server blocks to be allocated per user specified as the fifth
parameter in Job I075, Step 1620 or the EBPMAX parameter of NDBPARM, if you decided to
use the Software AG Editor buffer pool as file server.
Important:
Ensure that you have also added the Natural parameters required for the Software AG Editor; see the
relevant installation description in the section Installing the Software AG Editor, in the Natural
Installation Guide for Mainframes).
As DB2SIZE applies to Natural for DB2 and Natural for SQL/DS, it should be set to the maximum
value if you run more than one of these environments.
2. Add an NTDB entry specifying the list of logical database numbers that relate to DB2 tables. All
Natural DDMs that refer to a DB2 table must be cataloged with a DBID from this list.
DBIDs can be any number from 1 to 254; a maximum of 254 entries can be specified. For most user
environments, one entry is sufficient.
Important:
Ensure that all DB2 DDMs used when cataloging a given program have a valid DB2 DBID. Also
ensure that the DBIDs selected in the NTDB macro for DB2 do not conflict with DBIDs selected for
other database systems.
As of Natural Version 2.2, the DBID for DB2 used when cataloging a Natural program no longer has
to be in the NTDB list of DBIDs used when executing this program. Therefore, when executing
existing Natural programs, DBID 250 is no longer mandatory. It is, however, still strongly
recommended when cataloging Natural programs, since so far all DDMs have been cataloged with
22
Natural for DB2 Version 3.1.4 for Mainframes Installation
DBID 250.
Two sample NTDB macros follow:
NTDB DB2,250
NTDB DB2,(200,250,251)
In previous Natural for DB2 versions, this storage was always obtained from the TP monitor or operating
system. For performance reasons, it is now first attempted to meet the storage requirements by free space
in the Natural for DB2 buffer (DB2SIZE). Only if there is not enough space available in this buffer, the
TP monitor or operating system is invoked.
To take advantage of this performance enhancement, you must specify your DB2SIZE larger than
calculated according to the formula.
Depending on the SQL execution mode and on the usage of the Natural file server, the additional storage
requirements (in bytes) can be calculated as follows:
Dynamic Mode
Static Mode
Storage Requirements for the File Server
Sample Calculation for Dynamic Mode without Using the File Server
Considerations for VARCHAR Fields
Dynamic Mode
Static Mode
With receiving fields (that is, with variables of the INTO list of a SELECT statement):
64 + n * 24 + 24 + n * 2
where "n" is the number of receiving fields in an SQL statement.
The storage remains allocated until the loop is terminated.
23
Installation Natural for DB2 Version 3.1.4 for Mainframes
When using the file server, additional storage is required for each database loop that contains positioned
UPDATE and/or DELETE statements.
For each of such loops, a buffer is allocated to save the contents of all receiving fields contained in the
INTO list. Therefore, the size of this buffer corresponds to the total length of all receiving fields:
where "v1 ... vn" refers to the variables contained in the INTO list.
Sample Calculation for Dynamic Mode without Using the File Server
If you use the default value 10 for both variables (n1 and n2), the calculated DB2SIZE will be 5896 bytes.
However, if you specify a DB2SIZE of 20 KB instead, the available space for dynamically allocated
storage will be 14584 bytes, which means enough space for up to either 259 sending fields or 249
receiving fields.
Since space for receiving fields remains allocated until a database loop is terminated, the number of fields
that can be used inside such a loop is reduced accordingly: for example, if you retrieve 200 fields, you can
update about 50 fields inside the loop.
When using VARCHAR fields (that is, fields with either an accompanying L@ field in the Natural view
or an explicit LINDICATOR clause), additional storage is allocated dynamically if the L@ or
LINDICATOR field is not specified directly in front of the corresponding base field. Therefore, always
specify these fields in front of their base fields.
24
Natural for DB2 Version 3.1.4 for Mainframes Installation
Parameter Function
BTIGN Ignores errors which result from BACKOUT TRANSACTION statements that are issued
too late.
CONVERS Allows conversational mode (under CICS without the file server only).
DDFSERV Alternate DD name for the file server.
DLISYNC Obsolete and no longer documented. Only maintained for compatibility reasons.
EBPFSRV Indicates that the Software AG Editor buffer pool is used as storage medium of the Natural
for DB2 file server.
EBPPRAL Specifies the number of blocks to be defined as primary allocation per user if the Software
AG Editor buffer pool is to be used as file server.
EBPSEC Specifies the number of blocks to be defined as secondary allocation per user if the
Software AG Editor buffer pool is to be used as file server.
EBPMAX Specifies the number of blocks to be defined as maximum allocation per user if the
Software AG Editor buffer pool is to be used as file server.
ETIGN Ignores END TRANSACTION errors under IMS/TM and continues processing.
FSERV Use and mode of the file server.
MAXLOOP Specifies the maximum number of nested program loops.
NNPSF Set NATURAL NUMERIC’s positive sign to F.
REFRESH Allows the automatic setting of the DB2 server and package set at the begining of a new
database transaction to the values which were in place during the last database transaction.
STATDYN Allows dynamic execution of statically generated SQL statements if the static execution
returns an error.
The individual parameters are described in the following section. Their values cannot be dynamically
overwritten.
25
Installation Natural for DB2 Version 3.1.4 for Mainframes
Parameters in NDBPARM
BTIGN - Ignore Error after late BACKOUT TRANSACTION
Value Explanation
ON The error after a late BACKOUT TRANSACTION is ignored.
OFF The error after a late BACKOUT TRANSACTION is not ignored
This parameter is used to allow conversational mode in CICS environments where no file server is used.
Value Explanation
ON Conversational mode is allowed.
OFF Conversational mode is not allowed.
If this parameter is set to OFF and no file server is used, you cannot continue database loops across
terminal I/Os; if so, the DB2 SQL codes -501, 504, 507, 514, or 518 may occur.
If you are using the SYSDDM SQL services in a CICS environment without file server, you must specify
CONVERS=ON, otherwise you get the errors mentioned above.
This parameter specifies a DD name for the file server module other than "CMFSERV".
26
Natural for DB2 Version 3.1.4 for Mainframes Installation
EBPFSRV
This parameter is used to determine whether the file server uses the Software AG Editor buffer pool as
storage medium or not. If it is OFF, the file server uses the VSAM file as in previous versions. The
parameter must be set to ON, if the file server is to be used in a Sysplex environment.
EBPPRAL
This parameter specifies the number of blocks to be allocated primarily to each user of the file server, if
the Software AG Editor buffer pool is used as storage medium.
EBPSEC
This parameter specifies the number of blocks to be allocated secondarily to each user of the file server if
the Software AG Editor buffer pool is used as storage medium. The secondary allocation is used to
allocate buffer pool block to the user if the primary allocation amount is already exhausted.
EBPMAX
This parameter specifies the maximum number of blocks to be allocated to each user of the file server if
the Software AG Editor buffer pool is used as storage medium. This parameter serves as upper limit for
the allocation of buffer pool blocks to a single user. If the EBPFSRV parameter is set to OFF EBPMAX is
not used at runtime.
27
Installation Natural for DB2 Version 3.1.4 for Mainframes
This parameter is relevant in IMS/TM MPP and message-oriented BMP environments only.
In such a region, an END TRANSACTION cannot be executed by the Natural/IMS interface and is
therefore ignored without any notification. In such situations, the ETIGN parameter can be used to issue
an error message instead.
Value Explanation
ON The END TRANSACTION error is ignored and processing is continued.
OFF The END TRANSACTION error is not ignored.
This parameter determines whether the file server is to be used and whether it can be disabled in the case
of an initialization error.
Value Explanation
ON The file server is to be used.
OFF The file server is not to be used.
DIS The file server is to be used but is to be disabled if it cannot be initialized.
If FSERV is set to ON and the file server is not operational, the initialization of Natural for DB2 is
terminated with a corresponding Natural error message. The Natural interface to DB2 is disabled and any
SQL call is rejected with a corresponding error message.
This parameter specifies the maximum possible number of nested database loops.
28
Natural for DB2 Version 3.1.4 for Mainframes Installation
This parameter changes the sign character of positive Natural variables which have format N, if they are
filled from DB2. Usually these variables have the C as positive sign character. If the parameter NNPSF is
set to ON, F is used as positive sign character.
Value Explanation
ON Positive numbers put into Natural NUMERIC variables by DB2 get the sign F.
OFF Positive numbers put into Natural NUMERIC variables by DB2 get the sign as it was delivered
for DB2.
This parameter is used to automatically set the DB2 server and package set to the values which were in
place when the last transaction was executed. Server and package set are refreshed by using the
CONNECT TO server-name and SET CURRENT PACKAGESET = ’package-name’ SQL statements of
DB2.
Value Explanation
OFF No automatic refreshment is performed.
ON The automatic refreshment is done everytime before a database transaction starts and "old"
values of server and package set are present.
29
Installation Natural for DB2 Version 3.1.4 for Mainframes
This parameter is used to allow dynamic execution of statically generated SQL statements if the static
execution returns an error.
Value Explanation
NEVER Dynamic execution is never allowed.
ALWAYS Dynamic execution is always allowed after an error.
SPECIAL Dynamic execution is allowed after special errors only.
These special errors are:
NAT3706: Load module not found
SQL -805: DBRM does not exist in plan
SQL -818: Mismatch of timestamps
30
Natural for DB2 Version 3.1.4 for Mainframes Installation
Parameter Function
THREADSIZE Determines the size of the Natural threads used by the Natural server.
THREADNUMBER Determines the number of threads to be used by the Natural server.
NATURAL Name of the server front-end or server Natural to be loaded by the server stub if
the external CMSTART is not resolved by the linkage editor.
SERVER Server name used to create the Natural server environment.
MODE Operation mode of server stub.
MAIN IBM Language Environment MAIN program option.
GTRCID GTRACE ID to be used.
GTRACE Specifies whether the server stub executes GTRACE macro calls.
The individual parameters are described in the following section. Their values cannot be dynamically
overwritten.
THREADSIZE - Determines the Size of the Natural Threads Used by the Server Natural
THREADSIZE determines the size of the Natural threads used by the server Natural. The size is specified
in units of kilobytes.
THREADNUMBER determines the number of Natural threads used by the server Natural. This number
influences the number of parallelly active stored procedures in the Natural server.
Keep in mind that the number of concurrently active DB2 stored procedures is limited by DB2 parameter.
Therefore it does not make sense to set THREADNUMBER greater than the DB2 limit.
31
Installation Natural for DB2 Version 3.1.4 for Mainframes
NATURAL denotes the name of the server front-end or server Natural load module which will be loaded
by the server stub if the external CMSTART is not already resolved by the linkage editor during creation
of the server stub. The named load module has to be present in any steplib of the stored procedure address
space.
Server names suffixed with the three characters SRV denote the names of the servers used by the server
front-end in order to identify the server Natural . These names should be unique within one address space.
Value Explanation
STR Invoking this server stub sets up the Natural server environment.
SRV Invoking this server stub invokes the associated stored procedure, which is executed like a
Natural subprogram in the Natural server. If the server environment is not yet set up in the stored
procedure address space, the server stub will implicitly set up the Natural server environment.
TRM Invoking this server stub terminates the Natural server environment in the stored procedure
address space.
MAIN determines whether the generated server stub module will be an IBM Language Environment main
program or not. It directly influences the MAIN parameter of the CEEENTRY macro.
Value Explanation
YES The generated server stub operates as IBM Language Environment main program.
NO The generated server stub operates as IBM Language Environment sub program.
32
Natural for DB2 Version 3.1.4 for Mainframes Installation
GTRCID specifies the event ID recorded with the trace data created by the server stub.
GTRACE - Specifies Whether the Server Stub Executes GTRACE Macro Calls
GTRACE specifies whether or not the server stub executes GTRACE macro calls for tracing purposes.
Value Explanation
ON The generated server stub executes GTRACE macros in order to document its processing.
OFF The generated server stub does not execute GTRACE macros during its processing cycle.
CMPRMIN specifies the DDNAME of the CMPRMIN dataset during startup to read the input PROFILE
parameter for this server.
CMPRINT specifies the DDNAME of the CMPRINT dataset to which the primary report output is
written. If an asterisk (*) is specified, a unique DDNAME Pnnnnnnn is built whenever a stored procedure
is invoked.
CMTRACE specifies the DDNAME of the CMTRACE dataset to which the primary report output is
written. If an asterisk (*) is specified, a unique DDNAME Pnnnnnnn is built whenever a stored procedure
is invoked which makes it possible to store each output separately.
33
Installation Natural for DB2 Version 3.1.4 for Mainframes
Thus, before you can use the Retrieval or Explain functions, you must create these tables. The SYSSAG
tables must have the same columns as the catalog tables of DB2 Version 4 and they must be created as
ALIAS, VIEW, or TABLE.
To help you create these tables, sample SQL code is provided in the members DEMSQL3 and DEMSQL4
in the library SYSDB2, where DEMSQL4 is intended for DB2 Version 4. By default, it creates an ALIAS
SYSSAG.xxx for the corresponding SYSIBM table.
With DB2 Version 3 you must use DEMSQL3. For some tables this member contains CREATE VIEW
statements which emulate the columns of the catalog of DB2 Version 4. It also contains CREATE TABLE
statements for tables that are not part of the catalog of DB2 Version 3.
For some catalog tables no indexes are defined. For performance reasons, you should therefore consider
creating copies of these tables with appropriate indexes.
For the following tables it is recommended to work with copies of the catalog tables:
SYSCOLAUTH
SYSDBRM
SYSFOREIGNKEYS
SYSINDEXPART
SYSKEYS
SYSSTMT
SYSSYNONYMS
SYSTABLEPART
SYSVIEWS
The required CREATE TABLE and CREATE INDEX statements are included as comments in the sample
SQL members DEMSQL3 and DEMSQL4. Also sample SQL to update the data in the copies of the
catalog tables is included in the member DEMSQLUP.
For any other table, it is recommended that you create an ALIAS or a VIEW that points to the
corresponding SYSIBM table.
Note:
The sample SQL members can be executed with the ISQL part of SYSDB2. ISQL enables you to read
SQL members from the library SYSDB2. To save an SQL member in any other library, you can use the
command LIBRARY MYLIB in the ISQL input screen to switch to another library and then save the SQL
member. You cannot save SQL members in the library SYSDB2.
34
Natural for DB2 Version 3.1.4 for Mainframes Installation
It is recommended that you create an index on the following columns of the PLAN_TABLE:
35
Natural Tools for DB2 - Overview Natural for DB2 Version 3.1.4 for Mainframes
Issuing DB2 Commands from Natural Issue DB2 commands from Natural.
Natural System Commands for DB2 Display and explain generated SQL statements.
Natural Tools for DB2 with Natural Security Restrict the use of the Natural Tools for DB by Natural
Security.
36
Natural for DB2 Version 3.1.4 for Mainframes Using Natural Tools for DB2
The Natural Tools for DB2 Main Menu is displayed, which offers you the following functions:
Note:
If you have created a new SYSDB2 library when installing Natural for DB2, ensure that it contains all
Predict interface programs necessary to run the Natural Tools for DB2. These programs are loaded into
SYSDB2 at Predict installation time (see the relevant Predict documentation).
37
Using Natural Tools for DB2 Natural for DB2 Version 3.1.4 for Mainframes
Main commands are entered in the command line of the editor screen. The most important main
commands are:
Command PF Description
Key
BOTTOM (++) Positions to the bottom of the data.
CHANGE Scans for a specified string and replaces each such string found with another
specified string.
CLEAR Clears the editor source area.
DELETE Deletes the line(s) containing a given string according to the specified selection
operands.
DOWN (+) PF 8 Scrolls the specified scroll amount downwards.
FIND Finds a string specified by command operands at the location(s) specified by
selection operands.
LEFT PF 10 Scrolls the specified scroll amount to the left.
LIMIT n Sets a limit for the FIND command; n lines are processed.
PRINT Prints the data displayed.
RESET Resets all pending line commands.
RFIND PF 5 Repeats the last FIND command.
RIGHT PF 11 Scrolls the specified scroll amount to the right.
TOP (--) Positions to the top of the data.
UP (-) PF 7 Scrolls the specified scroll amount upwards.
The scroll amount for the UP, DOWN, LEFT, and RIGHT commands is specified in the SCROLL field at
the top right corner of the list screen. Valid values for the scroll amount are:
Value Explanation
CSR Scroll amount is determined by cursor position
DATA Scroll amount equals the page size less one line
HALF Scroll amount is half the page size
MAX Scroll amount equals the amount of data to the bottom/top
PAGE Scroll amount is equal to the page size
n Scroll amount is equal to n lines
38
Natural for DB2 Version 3.1.4 for Mainframes Using Natural Tools for DB2
Line commands are entered in the editor prefix area of the corresponding statement line. The most
important line commands are:
Command Description
A Inserts line(s) to be moved or copied after the current line.
B Inserts line(s) to be moved or copied before the current line.
C Copies the current line.
CC Marks the beginning and end of a block of lines to be copied.
D Deletes the current line.
DD Marks the beginning and end of a block of lines to be deleted.
Inn Inserts nn new lines after the current line.
M Moves the current line.
MM Marks the beginning and end of a block of lines to be moved.
Both main commands and line commands are described in detail as part of the Natural Tools for DB2
online help facility, which is invoked by pressing PF1 (Help). For further details, please refer to the
Software AG Editor documentation.
39
Using Natural Tools for DB2 Natural for DB2 Version 3.1.4 for Mainframes
Command Description
COPY name Copies the specified member from the current library into the editor, after (A) or
before (B) the current line.
LIBRARY name Specifies the Natural library "name" as current library.
LIST name* Lists all members from the current library whose names start with "name". From the
list, you can select a member by marking it with "S".
PURGE name Purges the specified member from the current library.
READ name Reads the specified member from the current library into the editor. The current name
is set to "name".
SAVE [name] Saves the generated code as the member "name" in the current library. If no name is
specified, the current name is taken. Current library and member names are displayed
above the command line.
Member and library names must correspond to the Natural naming conventions (see the Natural Reference
documentation for details). Members can be JCL members, SQL members, or output members.
40
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Two modes of operation are available: fixed mode and free mode.
In fixed mode, maintenance screens with syntax graphs help you to specify the correct commands.
Complete JCL members can be generated using predefined job profiles. You simply enter the required
data in input maps. The data are checked to ensure that they comply with the correct syntax. Then JCL
members are generated from these data. The members can be submitted directly by pressing PF4 (Submi).
But you can also switch to free mode by pressing PF5 (Free).
Pressing PF5 in fixed mode invokes the free-mode editor, which can be used to modify JCL code
generated in fixed mode, without the syntactical restrictions imposed. In free mode you can submit the
JCL member currently in the source area by pressing PF4 (as in fixed mode).
41
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
If the control field displays an "X", data have already been entered in the corresponding window.
Key Function
PF4 Generates JCL code and submits it.
PF5 Generates JCL code and enters free mode.
PF6 Scrolls to the top of a window.
PF7 Scrolls backwards in windows.
PF8 Scrolls forwards in windows.
PF9 Scrolls to the bottom of a window.
PF10 Shows the previous screen.
PF11 Shows the next screen.
In free mode, JCL code can be edited and submitted. Editing of JCL code is done via edit and line
commands; see Editing within the Natural Tools for DB2.
Apart from being submitted, JCL code can also be copied, listed, purged, retrieved from, or saved in a
Natural library. All this is done via maintenance commands.
42
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Enter function code "A" on the Natural Tools for DB2 Main Menu.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Logn Canc
Code Description
PP Defines job profiles for DBRM creation and plan/package maintenance.
CD Generates JCL to create database request modules.
BI Generates JCL to bind a plan or package.
RB Generates JCL to rebind a plan or package.
FR Generates JCL to free a plan or package.
LJ Invokes the free-mode editor.
JO Displays job output.
This function only applies if the Entire System Server is installed.
43
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
In addition, four parameters are available, which must be specified according to the selected function:
Parameter Description
Object Specifies whether to maintain a plan ("PLAN" or "PL") or a package ("PACKAGE" or
"PK").
Library Specifies the name of a Natural source library.
All existing libraries except the ones beginning with "SYS" can be specified; a library
must be specified for JCL maintenance. The library name is preset with your Natural user
ID.
JCL Member If a valid member name is specified, the corresponding JCL member is displayed.
If a value is specified followed by an asterisk (*), all JCL members in the specified library
whose names begin with this value are listed.
If asterisk notation is specified only, a selection list of all JCL members in the specified
library is displayed.
If the JCL Member field is left blank, the empty free-mode editor screen is displayed.
Node Specifies the number of the node to be used by the Entire System Server. The default
number "148" can be overwritten.
44
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Invoke the Prepare Job Profile function by entering function code "PP" on the Application Plan
Maintenance menu.
Code Function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
Code Description
J Defines user-specific default job cards.
D Defines job profiles for the DBRM creation function.
P Defines job profiles for the plan or package maintenance functions.
In addition, the parameter Profile is available, which is relevant to function codes "D" and "P" only. With
function code "J", Profile corresponds to "USER".
45
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Parameter Description
Profile Specifies the name of an already existing job profile.
If a valid profile name is specified, the free-mode editor with the specified job profile is
invoked, where the profile can be modified and saved.
If a value is specified followed by an asterisk (*), all existing job profiles whose names
begin with this value are listed.
If asterisk notation is specified only, a selection list of all existing job profiles is displayed.
If the field is left blank, the corresponding fixed-mode profile screen is invoked, where a
new job profile can be created. To save the new profile, you have to switch to free mode.
Job profiles can be maintained (that is, copied, listed, purged, retrieved from, or saved in a Natural library)
via maintenance commands.
Note:
Job profiles are saved on the Natural system file (FNAT).
46
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
To define a default job card, invoke the Default Job Cards function by entering function code "J" in the
Prepare Job Profile menu. The Default Job Cards screen is invoked, where you can create and save your
user-specific job cards. To do so, you can also read (directly or from a list) and modify an already existing
default job card. Existing job cards can be purged, too.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
As you will see on the following pages, all function screens used to specify jobs contain the same two
fields - Job Name and Job Cards - as the Default Job Cards screen. Thus, it is possible to override the
default job cards in each of these screens, too.
The Job Name field enables you to change the name of the job.
In the Job Cards field, you can enter an "S" to invoke a window where you can modify all the job cards.
47
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Parameter Description
@JOBCARDS Is replaced by the job cards entered on the create DBRM screen (up to five lines).
You can also code the job cards in the profile and omit the job cards modifier.
@COMMAND Is replaced by the string "CREATE DBRM".
@DBRMNAME Is replaced by the name of the DBRM, which can be up to eight characters long.
@CREATE-DBRM Is replaced by the command input for the static generation step.
This parameter must be placed after the //CMSYNIN card and must comply with
the Assembler naming conventions.
@COMMAN2 Is replaced by the string "MODIFY".
@MODIFY Is replaced by the command input for the static modification step.
@XR-START Both mark the JCL to contain the Natural Assembler XREF data; if no XREF
@XR-END option is specified, the JCL is deleted again.
To define a job profile for DBRM creation, invoke the Profile for Create DBRM Job function by entering
function code "D" on the Prepare Job Profile menu. If you specify a valid profile name, too, the free-mode
editor containing the specified profile is invoked, where you can modify, save, and rename the displayed
profile. If you leave the Profile field blank, the Profile for Create DBRM Job screen is invoked, which
helps you in creating a new profile. To save the newly created job profile, you have to switch to free mode
by pressing PF5 (Free).
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Free Canc
48
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Profiles for DSN jobs consist of JCL which includes the following predefined set of substitution
parameters:
Parameter Description
@JOBCARDS Is replaced by the current job cards; you can also code the job cards in the profile and
omit the job cards modifier.
@DSNCMD Is replaced by the command input for the bind, rebind or free function.
@PLANNAME For the bind function, it is replaced by the name of the plan or package.
For the rebind and free functions, it is set to blank.
@COMMAND Is replaced by the string "BIND", "REBIND" or "FREE" respectively.
To define a profile for DSN jobs, invoke the Profile for DSN Jobs function by entering function code "P"
on the Prepare Job Profile menu. If, in addition, you specify a valid profile name, the free-mode editor
containing the specified profile is invoked, where you can modify, save, and rename the displayed profile.
If you leave the Profile field blank, the Profile for DSN Jobs screen is invoked, which helps you in
creating a new profile for DSN jobs. To save the newly created job profile, you have to switch to free
mode by pressing PF5 (Free).
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Free Canc
49
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Code Function
---- ----------------------------
D Load Profile for Create DBRM
B Load Profile for DSN Jobs
. Exit
---- ----------------------------
Code .. _ Profile .. ________
Replace .. N
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
Code Description
D Serves to load job profiles for DBRM creation.
B Serves to load job profiles for plan or package maintenance.
Parameter Description
Profile Specifies the name of the profile to be loaded.
This parameter must be specified.
Replace Specifies whether it is to be replaced or not if a profile with the specified name already
exists.
50
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Code Function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
Code Description
D Unloads job profiles for DBRM creation.
B Unloads job profiles for plan or package maintenance.
Parameter Description
Profile Specifies the name of the profile to be unloaded.
51
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Create DBRMs
To create a DBRM you have to generate JCL for DBRM creation. To do so, invoke the Create DBRMs
function by entering function code "CD" on the Application Plan Maintenance menu. The Create DBRM
screen is invoked, where, in addition to a job name, your user-specific default job cards, and the desired
job profile, you can specify all necessary information for the CREATE DBRM and MODIFY commands
>-+---------------------+------+----------------------+-----+------------+->
+- With XRef - _____ -+ +- LIBrary - ________ -+ +- FS - ___ -+
( NO, YES, FORCE ) ! ( ON, OFF )
>---------+------------------------------------------------------+----------><
+---- _ --- NAT Library , NAT Member +---------------+-+
+ , excl.Member-+
>>---------------------------- MODify-+------------+------------------------><
+- _ - XRef -+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Canc
In the Job Name field, a valid job name must be specified. If you only want to change the name of the job,
you can do this using the Job Name field, too.
Via the Job Cards field, you can override your default job cards. To do so, enter an "S" in the Job Cards
field. A window containing your job cards is displayed.
An "X" in the Job Cards field indicates that job cards for DBRM creation are defined. A blank Job Cards
field indicates that no job cards are defined.
In the Profile field, you can specify the name of a valid job profile for DBRM creation. If a value is
specified followed by an asterisk (*), all existing job profiles whose names begin with this value are listed.
If asterisk notation is specified only, a selection list of all available job profiles is displayed.
52
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
If you use the INPUT DATA option, a window is displayed, where you have to specify the Natural
libraries and programs (members) to be contained in the DBRM.
>-+---------------------+------+----------------------+-----+------------+->
+- With XRef - _____ -+ +- LIBrary - ________ -+ +- FS - ___ -+
( NO, YES, FORCE ) ! ( ON, OFF )
In the third column of the above window, you can specify a program that is to be excluded from the
DBRM; this is possible only if you specify an asterisk with the program name in the second column.
Within the window, you can scroll using PF6 (--), PF7 (-), PF8 (+), or PF9 (++).
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
53
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Bind Plan
To generate JCL to bind a plan, invoke the Bind function by entering function code "BI" on the
Application Plan Maintenance menu and "PLAN" or "PL" in the Object field. The first Bind Plan screen is
invoked, where all necessary information must be specified.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Next Canc
Apart from the specifications to be made in the Job Name, Job Cards, and Profile fields, to BIND a plan,
you have to specify the name of the plan and all DBRMs and/or packages that are to be bound into the
specified plan.
You invoke the window to specify the DBRM members and/or package lists by entering an "S" in the
MEMBER and/or PKLIST field respectively. Either or both windows must be invoked; otherwise, you are
prompted by the system to do so.
Within the windows for DBRM and package specification, you can scroll using PF6 (--), PF7 (-), PF8 (+),
or PF9 (++).
If Predict is installed and a plan is documented in Predict, the DBRM members and/or package lists
assigned to a plan in Predict can be read by entering "Y" for this option (default is "N"). A maximum of
50 DBRM members and/or 20 package lists can be read.
If you use this option and DBRM members and/or package lists have been successfully read, the
MEMBER and PKLIST selection fields are marked with "X", and "DONE" is displayed next to the
"(Y/N)" input field; "FAILED" is displayed if:
54
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Note:
If Predict is not installed, the field "Read member name / package list from Predict?" does not appear
on the above screen.
Pressing PF11 (Next) takes you to a second Bind Plan screen, where you can specify further options of the
DB2 BIND command. A keyword is generated by entering its first letter in the corresponding input field;
the default values are highlighted.
>---+------------------------+--+---------------+--+--------------------+--->
! ! ! ! ! !
+- _______ --( PREPARE )-+ +- FLAG --( _ )-+ +- EXPLAIN --( ___ )-+
( NODEFER or DEFER) ( I, W, E or C) ( YES or NO )
>---+--------------------+--+-------------------+--+--------------------+--->
! ! ! ! ! !
+- VALIDATE ( ____ )-+ +- ISOLATION ( __ )-+ +- CACHESIZE ( ____ )+
( RUN or BIND ) ( RR, UR or CS ) ( 0 - 4096 )
>---+-------------------------------+---+-------------------------------+--->
! ! ! !
+--- ACQUIRE --( ________ )-----+ +--- RELEASE --( __________ )---+
( USE or ALLOCATE ) ( COMMIT or DEALLOCATE )
>---+--------------------+----------+---+-------------------------------+--->
! ! ! !
+- CURRENTSERVER ( ________________ )-+ +-- CURRENTDATA ( ___ )--+
location-name ( NO or YES )
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Next Canc
Pressing PF11 (Next) takes you to a third Bind Plan screen, where you can again specify further options of
the DB2 BIND command.
>-+---------------------------------------------------------------------+-><
! !
+-+- _ - ENABLE -------- (*) --------+-+------------------------------+-+
! ! +->- DLIBATCH- _ -(con.-names)-+
+- _ - ENABLE --+- _ -(con.-types)-+ +->- CICS ---- _ -(applids)----+
+- _ - DISABLE -+ +->- IMSBMP -- _ -(imsids)-----+
+->- IMSMPP -- _ -(imsids)-----+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Next Canc
55
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Pressing PF11 (Next) takes you to a fourth Bind Plan screen, where you can again specify further options
of the DB2 BIND command.
>----+----------------------+-------+-------------------------+------------->
! ! ! !
+-- DEGREE --- ___ ----+ +-- SQLRULES --- ___ ----+
( 1 or ANY ) ( DB2 or STD )
>----+--------------------------------------------------------+------------->
! !
+-- DISCONNECT ----+--- _ - ( EXPLICIT ) -----+----------+
+--- _ - ( AUTOMATIC ) ----+
+--- _ - ( CONDITIONAL) ---+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Canc
All parameters necessary to bind a plan are entered on these four screens, which show the syntax of the
DB2 BIND PLAN command.
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
56
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Rebind Plan
To generate JCL to rebind a plan, invoke the Rebind function by entering function code "RB" on the
Application Plan Maintenance menu and "PLAN" or "PL" in the Object field. The first Rebind Plan screen
is invoked, where all necessary information must be specified.
>---+-----------------------------------------------------------------+----->
! !
+-- PKLIST ---- _ --(+----------------+collection-id.package-id)--+
! +-location-name.-+ !
+-- NOPKLIST -- _ ------------------------------------------------+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Next Canc
Apart from the specifications to be made in the Job Name, Job Cards, and Profile fields, you have to
specify the names of the plans to be rebound in a window. If you specify asterisk notation (*), all existing
plans are rebound.
Pressing PF11 (Next) takes you to a second Rebind Plan screen, where you can specify further options of
the DB2 REBIND command. A keyword is generated by entering its first letter in the corresponding input
field; the default values are highlighted.
57
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
>---+------------------------+--+---------------+--+--------------------+--->
! ! ! ! ! !
+- _______ --( PREPARE )-+ +- FLAG --( _ )-+ +- EXPLAIN --( ___ )-+
( NODEFER or DEFER) ( I, W, E or C) ( YES or NO )
>---+--------------------+--+-------------------+--+--------------------+--->
! ! ! ! ! !
+- VALIDATE ( ____ )-+ +- ISOLATION ( __ )-+ +- CACHESIZE ( ____ )+
( RUN or BIND ) ( RR, CS or UR ) ( 0 - 4096 )
>---+-------------------------------+---+-------------------------------+--->
! ! ! !
+--- ACQUIRE --( ________ )-----+ +--- RELEASE --( __________ )---+
( USE or ALLOCATE ) ( COMMIT or DEALLOCATE )
>---+--------------------+----------+---+-------------------------------+--->
! ! ! !
+- CURRENTSERVER ( ________________ )-+ +-- CURRENTDATA ( ___ )--+
location-name ( NO or YES )
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Next Canc
Pressing PF11 (Next) takes you to a third Rebind Plan screen, where you can again specify further options
of the DB2 REBIND command.
>-+------------------+---+-------------------+---+------------------------+->
! ! ! ! ! !
+- DEGREE - ___ ---+ +- SQLRULES - ___ --+ +- DYNAMICRULES - ____ --+
( 1 or ANY ) ( DB2 or STD ) ( RUN or BIND )
>-+------------------------------------------+----------------------------+->
+- DISCONNECT --+-- _ --( EXPLICIT ) ------+
+-- _ --( AUTOMATIC ) -----+
+-- _ --( CONDITIONAL ) ---+
>-+-----------------------------------------------------------------------+-><
! !
+-+- _ - ENABLE -------- (*) --------+-+------------------------------+-+
! ! +->- DLIBATCH- _ -(con.-names)-+
+- _ - ENABLE --+- _ -(con.-types)-+ +->- CICS ---- _ -(applids)----+
+- _ - DISABLE -+ +->- IMSBMP -- _ -(imsids)-----+
+->- IMSMPP -- _ -(imsids)-----+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Canc
All parameters necessary to rebind a plan are entered in these three screens, which show the syntax of the
DB2 REBIND PLAN command.
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
58
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Free Plan
To generate JCL to free a plan, invoke the Free function by entering function code "FR" on the
Application Plan Maintenance menu and "PLAN" or "PL" in the Object field. The Free Plan screen is
invoked, where all necessary information must be specified.
>-----------------------+---------------------------+----------------------->
! !
+--- FLAG -----( _ )--------+
(I, W, E or C)
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Canc
Apart from the specifications to be made in the Job Name, Job Cards, and Profile fields, all parameters
necessary to free a plan are entered in a screen showing the syntax of the DB2 FREE PLAN command.
The names of the plans to be freed are entered in a window. If you specify asterisk notation (*), all plans
are freed.
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
59
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Bind Package
To generate JCL to bind a package, invoke the Bind function by entering function code "BI" on the
Application Plan Maintenance menu and "PACKAGE" or "PK" in the Object field. The first Bind
Package screen is invoked, where all necessary information must be specified.
>--------------+-------------------+-+-----------------------+-------------->
+ OWNER ( ________ )+ + QUALIFIER ( ________ )+
auth-id qualifier-name
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Next Canc
Apart from the specifications to be made in the Job Name, Job Cards, and Profile fields, to BIND a
package, you have to specify the collection ID of the package and a DBRM or a further package to be
bound into the specified package.
You specify the DBRM or the second package in the MEMBER or COPY field respectively. Either of the
fields must be selected and the package ID will be either the DBRM name or the package ID of the copied
package.
60
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Pressing PF11 (Next) takes you to a second Bind Package screen, where you can specify further options of
the DB2 BIND command. A keyword is generated by entering its first letter in the corresponding input
field; the default values are highlighted.
>----------+-------------------------+-----------+---------------+---------->
! ! ! !
+- SQLERROR ( _________ )-+ +- FLAG --( _ )-+
( NOPACKAGE or CONTINUE ) ( I, W, E or C)
>----------+-------------+--+---------------+--------------------+---------->
! ! ! ! !
+- EXPLAIN --( ___ )-+ +- VALIDATE ( ____ )-+
( NO or YES ) ( RUN or BIND )
>----------+-------------------+------+--------------------------+---------->
! ! ! !
+- ISOLATION ( __ )-+ +- RELEASE -( __________ )-+
( RR, RS, CS, UR or NC) ( COMMIT or DEALLOCATE )
>----------+----------------------+---+--------------------------+---------->
! ! ! !
+- CURRENTDATA ( ___ )-+ +- DYNAMICRULES --( ____ )-+
( NO or YES ) ( RUN or BIND )
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Next Canc
Pressing PF11 (Next) takes you to a third Bind Package screen, where you can again specify further
options of the DB2 BIND command.
>-+-----------------------------------------------+---+-------------------+->
! ! ! !
+- ACTION -+- _ (REPLACE) -+--------------+--+--+ +- DEGREE - ___ ----+
! + REPLVER - _ -+ ! ( 1 or ANY )
! (version-id) !
+- _ (ADD) -----------------------+
>-+-----------------------------------------------------------------------+-><
! !
+-+- _ - ENABLE -------- (*) --------+-+------------------------------+-+
! ! +->- DLIBATCH- _ -(con.-names)-+
+- _ - ENABLE --+- _ -(con.-types)-+ +->- CICS ---- _ -(applids)----+
+- _ - DISABLE -+ +->- IMSBMP -- _ -(imsids)-----+
+->- IMSMPP -- _ -(imsids)-----+
+->- REMOTE -- _ -(loc/lu-name)+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Canc
61
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
All parameters necessary to bind a package are entered on these three screens, which show the syntax of
the DB2 BIND package command.
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
Rebind Package
To generate JCL to rebind a package, invoke the Rebind function by entering function code "RB" on the
Application Plan Maintenance menu and "PACKAGE" or "PK" in the Object field. The first Rebind
Package screen is invoked, where all necessary information must be specified.
>------------+---------------------+-+-------------------------+----------->
! ! ! !
+- OWNER ( ________ )-+ +- QUALIFIER ( ________ )-+
auth-id qualifier-name
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Next Canc
Apart from the specifications to be made in the Job Name, Job Cards, and Profile fields, you have to
specify the names of the packages to be rebound in a window. If you specify asterisk notation (*), all
locally existing packages are rebound.
Pressing PF11 (Next) takes you to a second Rebind package screen, where you can specify further options
of the DB2 REBIND command. A keyword is generated by entering its first letter in the corresponding
input field; the default values are highlighted.
62
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
>----------+--------------------+-----------+--------------------+--------->
! ! ! !
+- FLAG -----( _ )---+ +- DEGREE --( ___ )--+
( I, W, E or C) ( 1 or ANY )
>----------+--------------------+-----------+--------------------+--------->
! ! ! !
+- EXPLAIN --( ___ )-+ +- VALIDATE ( ____ )-+
( NO or YES ) ( RUN or BIND )
>----------+--------------------+-----+------------------------+----------->
! ! ! !
+- ISOLATION ( __ )--+ +- RELEASE -( __________ )-+
( RR, RS, CS, UR or NC ) ( COMMIT or DEALLOCATE )
>----------+----------------------+---+--------------------------+---------->
! ! ! !
+- CURRENTDATA ( ___ )-+ +- DYNAMICRULES -( ____ )--+
( NO or YES ) ( RUN OR BIND )
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Next Canc
Pressing PF11 (Next) takes you to a third Rebind package screen, where you can again specify further
options of the DB2 REBIND command.
>-+-----------------------------------------------------------------------+-><
! !
+-+- _ - ENABLE -------- (*) --------+-+------------------------------+-+
! ! +->- DLIBATCH- _ -(con.-names)-+
+- _ - ENABLE --+- _ -(con.-types)-+ +->- CICS ---- _ -(applids)----+
+- _ - DISABLE -+ +->- IMSBMP -- _ -(imsids)-----+
+->- IMSMPP -- _ -(imsids)-----+
+->- REMOTE -- _ -(loc/lu-name)+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Prev Canc
All parameters necessary to rebind a package are entered in these two screens, which show the syntax of
the DB2 REBIND PACKAGE command
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
63
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Free Package
To generate JCL to free a package, invoke the Free Package function by entering function code "FR" on
the Application Plan Maintenance menu and "PACKAGE" or "PK" in the Object field. The Free Package
screen is invoked, where all necessary information must be specified.
>-----------------------+---------------------------+-----------------------><
! !
+--- FLAG -----( _ )--------+
( I, W, E or C )
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Free Canc
Apart from the specifications to be made in the Job Name, Job Cards, and Profile fields, all parameters
necessary to free a package are entered in a screen showing the syntax of the DB2 FREE PACKAGE
command. The names of the packages to be freed are entered in a window. If you specify asterisk notation
(*), all local packages are freed.
The generated JCL code can be either edited and/or saved in free mode by pressing PF5 (Free), or
submitted immediately by pressing PF4 (Submi).
64
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Submi Rfind Rchan - + < > Canc
Within the free-mode editor, JCL members can be copied, listed, purged, retrieved from, or saved in a
Natural library. All this is done via maintenance commands.
Press PF4 (Submi) to submit JCL code listed in the editor, press PF5 (Fix) to switch to fixed mode.
65
Application Plan Maintenance Natural for DB2 Version 3.1.4 for Mainframes
If you want to display the output of a JCL member, enter function code "JO" on the Application Plan
Maintenance menu to invoke the Display Job Output function; the default node number (148) for Entire
System Server can be modified. A screen is invoked, where you can specify the desired job name and job
number, as well as the numbers of the SYSOUT types.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Exit Logn Canc
If you specify a value followed by an asterisk, or specify asterisk notation only, a list of job output
members is displayed for selection. In a job output member selection list, you can mark an output member
with either "B" to display the member only, or "L" to display a list of all the job output’s SYSOUTs,
which in turn can be marked with "B" for display.
If you leave the Job Name field blank, you must specify a job number.
In the Job Number field, you can specify a unique job number. Only if a unique job number has been
specified, specifications can be made in the Sysout Type and Sysout Number fields, too.
66
Natural for DB2 Version 3.1.4 for Mainframes Application Plan Maintenance
In the Sysout Type field, you can specify the type of SYSOUT dataset of the job with the specified job
number to be displayed. The following codes apply:
In the Sysout Number field, you can specify a file number to display a specific SYSOUT dataset of the
type specified in the Sysout type field. If you leave the Sysout Number field blank, all SYSOUT datasets
of the specified type are displayed.
67
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Catalog Maintenance
The Catalog Maintenance part of the Natural Tools for DB2 enables you to generate SQL statements to
maintain the DB2 catalog (that is, DB2 tables and other DB2 objects) without leaving your development
environment.
The Catalog Maintenance function incorporates an SQL generator that automatically generates from your
input the SQL code required to maintain the desired DB2 object. You can display, modify, save, and
retrieve the generated SQL code.
Fixed Mode
In fixed mode, input screens with syntax graphs help you to specify correct SQL code. You simply enter
the required data in the input screens, and the data are automatically checked to ensure that they comply
with the DB2 SQL syntax. If the input is incomplete, you are prompted for the missing data. Then, SQL
members are generated from the entered data. The members can be executed directly by pressing PF4. But
you can also switch to free mode, where the generated SQL code can be modified.
After the execution of an SQL statement, a message is returned, which indicates that the statement has
been successfully executed. If an error occurred, the resulting DB2 error message can be displayed by
pressing PF2 (Error), which executes the SQLERR command.
68
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
For each field where a window can be invoked, you can specify an "S". When you press ENTER, the
window appears and you can select or enter the necessary information. If such a selection is required, an
"S" is already preset when the corresponding screen is invoked.
When you press ENTER again, the window closes and if data have been entered, the field is marked with
"X" instead of "S". If not, the field is left blank or marked with "S" again.
This will continue each time you press ENTER until no "S" remains. To redisplay a window where data
have been entered, you change its "X" mark back to "S".
The wrong character is automatically replaced by an "S" and if you press ENTER again, the
corresponding window appears.
In fields where keywords are to be entered, you must enter one of the keywords displayed beneath the
field. Default keywords are highlighted.
Free Mode
When free mode is invoked from fixed mode, the data that were entered in fixed mode are shown as
generated SQL code which can be saved for later use or modification.
If you modify an SQL member in free mode, this has no effect on the fixed-mode version of the member.
You can save your modified code in free mode, but when you return to fixed mode, the original data
appear again. Thus, both original and modified data are available.
In free mode you can execute the member currently in the source area by pressing PF4 (as in fixed mode).
Execution of SQL statements automatically switches to the output screen, which shows the SQL return
code of the executed commands.
See the list of the SQL code maintenance commands available in free mode.
69
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Enter function code "C" on the Natural Tools for DB2 Main Menu.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
In the Code field, the function code assigned to the desired function can be specified, together with the
desired Object, Library, and/or Member name.
If you switch to free mode and enter a valid member name, you can read this member from the Natural
library specified with the Library parameter. The Library parameter is preset with your Natural user ID.
With the CREATE VIEW and EXPLAIN functions, a subselect or an explainable SQL statement must be
entered, respectively. Both can be done in a separate editor session, where previously saved members can
be used. The editor is invoked by entering an "S" in the appropriate field.
With the functions CREATE, ALTER, GRANT, and REVOKE, an object code must be specified, for
example, "TB" for TABLE. If you leave the object field blank, a window is displayed which shows you a
list of all available objects together with their object codes.
70
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
If you enter for example the CREATE function without specifying an object, a window is invoked which
prompts you for the type of object to be created:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
In the following section some examples illustrate how to use the catalog maintenance function in fixed
mode.
71
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free -- - + ++ Next Canc
Note:
Since the specification of any special characters as part of a Natural field or DDM name does not
comply with Natural naming conventions, any special characters allowed within DB2 should be
avoided. The same applies to DB2 delimited identifiers, which are not supported by Natural.
In the top right-hand corner of the screen, the index of the top most column (1), and the total number of
columns specified (9) is displayed. If you want to specify more columns than fit on one terminal screen,
press PF8 to scroll one page forward.
An "S" in the S/M/B field of column 4 means that the FOR SBCS DATA option is selected for this
column. Other possible values for this field are M (FOR MIXED DATA) and B (FOR BIT DATA).
Columns 3, 2, and 5 form the primary key, in the specified order. Primary key columns must be selected
with an "S" or ordered by specifying appropriate numbers between 1 and 16. In the present example, all
primary key columns are defined as "NOT NULL". In addition, column 7 is specified as "NOT NULL
WITH DEFAULT".
For column 6, a field procedure has been entered in a window invoked by "S". The window has been
closed again, and the "fld proc" field is now marked with "X".
72
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
If you enter an "R" in the R/C/D field for a given column and press ENTER, a window is displayed, in
which you can specify a references clause, which identifies this column as a foreign key of a referential
constraint.
+---------------------------------------------------------+
! References-clause for Column: COL1 !
! !
! >--- REFERENCES ---- ________ . __________________ --> !
! <creator.>table-name !
! >-+--------------------------------------------------> !
! +- ON DELETE --+-- _ - RESTRICT -+ !
! +-- _ - CASCADE --+ !
! +-- _ - SET NULL -+ !
! !
! !
+---------------------------------------------------------+
You must specify the name (with an optional creator name) of the parent table to be referenced. In
addition, you must specify the action to be taken when a row in the referenced table is deleted. You have
three options available:
RESTRICT prevents the deletion of the parent row until all dependent rows are deleted (this is the
default value).
CASCADE deletes all dependent rows, too.
SET NULL sets to null all columns of the foreign key in each dependent row that can contain null
values.
A key that consists of more than one column must be defined by a FOREIGN KEY clause.
If you enter a "C" in the R/C/D field for a given column and press ENTER, a window is displayed, in
which you can specify a check constraint for this column.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Exit Canc
73
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
You must specify a column check condition. A check condition is a search condition with various
restrictions which are described in detail in the relevant DB2 literature. In addition, you may specify a
name for the check constraint.
If you enter a "D" in the R/C/D field for a given column and press ENTER, a window is displayed, in
which you can specify a default value other than the system default value for this column.
For further information on default values, refer to the relevant DB2 literature.
74
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
Windows like the one below may help you in making a valid selection. They are invoked by entering the
help character "?" in the appropriate field on the screen:
In the case of complex SQL statements, more than one input screen may be required. If so, you can switch
to the following screen by pressing PF11 (Next), or return to the previous screen by pressing PF10 (Prev).
As you can see on the above screen, the beginning of the syntax specification for an SQL statement is
always indicated by ">>".
75
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Since the syntax of the CREATE TABLE statement is a rather complex one, three more screens are
required. Once all necessary information has been entered on the first screen, you press PF11 (Next) to
display the next Create Table input screen, where you can specify additional optional parameters.
>-+-+-------------------------------------------------------------------+-+-)->
! ! ! !
! +- , - FOREIGN KEY -------- ________ ------- _ --- (column-name) -> ! !
! <constraint-name> ! !
! ! !
! >---- REFERENCES ---> ! !
! >-- ________ . __________________ -- ON DELETE -+- S - RESTRICT -+-+ !
! <creator.>table-name +- _ - CASCADE --+ !
! +- _ - SET NULL -+ !
! !
+----------------------------------<------------------------------------+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free -- - + ++ Prev Next Canc
On this screen, you can specify a referential constraint to another table. To do so, enter an "S" in the
"column-name" field. A list of all columns available in the current table (dependent table) is displayed,
where you can select the column(s) to comprise the foreign key related to another table (parent table). You
can also specify a name for the constraint. If not, the constraint name is derived from the first column of
the foreign key.
A foreign key consists of one or more columns in a dependent table that together must take on a value that
exists in the primary key of the related parent table.
In the REFERENCES part, you must specify the table name (with an optional creator name) of the parent
table which is to be affected by the specified constraint. In addition, you must specify the action to be
taken when a row in the referenced parent table is deleted.
RESTRICT prevents the deletion of the parent row until all dependent rows are deleted (this is the
default value);
CASCADE causes all dependent rows to be deleted, too;
SET NULL sets to null all columns of the foreign key in each dependent row that can contain null
values.
In the top right-hand corner of the screen, the index of the currently displayed referential constraint block
(1) and the total number of referential constraint blocks defined (0) is displayed.
76
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
When all information has been entered, you can press either PF10 (Prev) to return to the previous screen,
or PF11 (Next) to go to the next screen.
On the next screen you have again the possibility to specify columns as unique. This time, however, up to
six groups of unique columns can be defined, with up to 16 columns per group. The individual columns
are specified in a window, which can be invoked for each group.
+-------------------------+
>---+------------------------------------------ ! ! -->
! ! ------ column-name ---- !
+- , - UNIQUE ----------------------------- ! __ CO1 !
! ! __ CO2 !
+- , - UNIQUE ----------------------------- ! __ CO3 !
! +-------------------------+
+- , - UNIQUE ----------------------------- _ -- (column-name) ---+
! !
+- , - UNIQUE ----------------------------- _ -- (column-name) ---+
! !
+- , - UNIQUE ----------------------------- _ -- (column-name) ---+
! !
+- , - UNIQUE ----------------------------- _ -- (column-name) ---+
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Error Exit Exec Free Prev Next Canc
Since unique columns must not contain null values, a further window is invoked automatically, on which
you can define the columns specified as unique also as NOT NULL or NOT NULL WITH DEFAULT
(unless you already defined them as such on the first Create Table input screen).
77
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
When all information has been entered, you can press either PF10 (Prev) to return to the previous screen
or PF11 (Next) to go to the last syntax input screen as shown below:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Error Exit Exec Free Prev Canc
Restrict dropping of the current table (and also of the database and tablespace that contain this table).
Define a check constraint for the current table.
To define a check constraint, you must specify a table check condition. A check condition is a search
condition with various restrictions which are described in the relevant DB2 literature. In addition,
you may specify a name for the check constraint.
If you press PF10 (Prev) on this screen, you return to the previous screen.
As you can see on the above screen, the end of the syntax specification for an SQL statement is always
indicated by "><".
An active help facility that consists of selection lists in windows is available for all fields referencing
existing database objects. Selection lists are invoked by entering either an asterisk (*) or part of an object
name followed by an asterisk in the corresponding input field.
78
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
If, for example, you enter "D*" in the "database-name" field of the above screen, a window appears where
you can check your selection criteria. When you press ENTER, a list of all databases whose names begin
with "D" appears.
Within the selection list, you can scroll up (PF6 / "--" or PF7 / "-") or down (PF8 / "+" or PF9 / "++"), and
select the desired database. The name of the selected database is copied to the corresponding field in your
input screen.
When all information has been entered, you can either switch to free mode (PF5) or submit the created
member directly to DB2 for execution (PF4). If execution is successful, you receive the message:
79
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
In free mode, the following editor screen displays the generated SQL code:
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Setup Exit Exec Rfind Rchan - + Outpu Canc
The free-mode editor is an adapted version of the Software AG Editor. It is almost identical to the
interactive SQL input screen. However, no SELECT statements can be issued from free mode.
For further details, please refer to the relevant Software AG Editor documentation.
80
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
>--- FREEPAGE -------- ___ ----- PCTFREE -- __ ------------ COMPRESS ___ --->
integer integer ( YES or NO )
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Error Exit Exec Free Next Canc
81
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Once you have entered all necessary information, press PF11 (Next) to go to the next screen:
>---+---------------------------------------------------------------------+--><
! !
+--- BUFFERPOOL ------ ______ ----------------------------------------+
! bufferpool-name !
+--- LOCKSIZE -+------ _________ ------------------------+------------+
! !( ANY, TABLE, TABLESPACE ) ! !
! +------ ____ ---+----------------------+--+ !
! ( ROW or PAGE )! ! !
! +- LOCKMAX -- ______ --+ !
! ( SYSTEM or integer ) !
+--- CLOSE ----------- ___ -------------------------------------------+
! ( YES or NO ) !
+--- DSETPASS -------- ________ --------------------------------------+
password
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Error Exit Exec Free Prev Canc
On the second Create Tablespace syntax input screen, you can now specify additional buffer pool names
as well as the LOCKSIZE option with the LOCKMAX clause.
If you enter an "S" in the "bufferpool-name" field and press ENTER, a window is displayed, in which you
can specify additional buffer pool names.
Refer to the relevant DB2 literature for further details on the COMPRESS, LOCKSIZE and LOCKMAX
clauses.
82
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free Next Canc
If you enter an "S" in the "field-proc" input field and press ENTER, a window is displayed, in which you
can specify a field procedure to be executed for this column:
83
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
If you enter an "S" in the "default" field and press ENTER, a window is displayed, in which you can
specify a default value other than the system default value for this column:
For further information on default values, refer to the relevant DB2 literature.
84
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
If you enter an "S" in the "check-constraint" field and press ENTER, a window is displayed, in which you
can specify a check constraint for this column:
+-----------------------------------------------------------------------------+
! >-+-------------------------+- CHECK ( ___________________________________ !
! ! ! ___________________________________ !
! +- CONSTRAINT - ________ -+ ___________________________________ !
! constraint-name ___________________________________ !
! ___________________________________ !
! ___________________________________ !
! !
! !
+-----------------------------------------------------------------------------+
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
You must specify a column check condition. A check condition is a search condition with various
restrictions which are described in detail in the relevant DB2 literature. In addition, you may specify a
name for the check constraint.
85
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
If you enter an "S" in the "reference-constraint" field and press ENTER, a window is displayed, in which
you can specify a references clause, which identifies this column as a foreign key of a referential
constraint:
+---------------------------------------------------------+
>-+- VALID ! >--- REFERENCES ---- _________. __________________ --> ! -----+>
! ! <creator.>table-name ! !
+- AUDIT ! >-+--------------------------------+-----------------> ! -----+
! ! +- ON DELETE --+-- _ _ RESTRICT -+ ! !
+- DATA ! +-- _ - CASCADE --+ ! -----+
! +-- _ - SET NULL -+ !
! !
! !
Command == +---------------------------------------------------------+
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
You must specify the name (with an optional creator name) of the parent table to be referenced. In
addition, you must specify the action to be taken when a row in the referenced table is deleted. You have
three options available:
RESTRICT prevents the deletion of the parent row until all dependent rows are deleted (this is the
default value).
CASCADE deletes all dependent rows, too.
SET NULL sets to null all columns of the foreign key in each dependent row that can contain null
values.
86
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
Once you have entered your column definitions, press PF11 (NEXT).
A screen is invoked in which you can add or drop primary and/or foreign keys:
>--+->- ADD ------ FOREIGN KEY --- ________ ------ _ -- (column-name) -->
! constraint-name
!
! >- REFERENCES ---->
! >--- ________ . _________________ -- ON DELETE -+- S - RESTRICT -+-+-->
! <creator.>table-name +- _ - CASCADE --+ !
! +- _ - SET NULL -+ !
! !
+->- DROP -----FOREIGN KEY --- ________ -----------------------------+
constraint-name
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free Prev Next Canc
Once you have entered the required information for adding and/or dropping primary and/or foreign keys,
press PF11 (NEXT). A screen is invoked, in which you can specify a RESTRICT ON DROP clause, add
or drop a CHECK constraint, and/or drop any constraint:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free Prev Canc
87
Catalog Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free Next Canc
If you enter an "S" in the "bufferpool-name" field and press ENTER, a window is displayed, in which you
can specify additional buffer pool names:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
88
Natural for DB2 Version 3.1.4 for Mainframes Catalog Maintenance
Once you are back in the first Alter Tablespace syntax input screen, press PF11 (Next) to go to the next
screen:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free Prev Canc
On the second Alter Tablespace syntax input screen, you can now specify the LOCKMAX and
LOCKSIZE options.
Refer to the relevant DB2 literature for further details on the COMPRESS, LOCKSIZE and LOCKMAX
clauses.
89
Procedure Maintenance Natural for DB2 Version 3.1.4 for Mainframes
Procedure Maintenance
The Procedure Maintenance part of the Natural Tools for DB2 enables you to insert, modify and delete
stored procedures from the SYSIBM.SYSPROCEDURES table, as well as insert data areas.
Enter function code "P" on the Natural Tools for DB2 Main Menu.
Code Function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Exit Canc
90
Natural for DB2 Version 3.1.4 for Mainframes Procedure Maintenance
Code Description
I Inserts a new DB2 stored procedure into the SYSIBM.SYSPROCEDURES table.
D Deletes one or several DB2 stored procedure(s).
M Modifies a DB2 stored procedure.
L Lists all DB2 stored procedures or a part of them.
Parameter Description
Procedure Name Specifies the name of the procedure.
Authid Specifies the authorization ID.
Luname Specifies the LU name.
91
Procedure Maintenance Natural for DB2 Version 3.1.4 for Mainframes
RUNOPTS = ’ ___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
__________________________________________________ ’
PARMLIST: - define PARMLIST: N (Y/N)
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
Here, you can specify the fields of the new stored procedure. The fields PROCEDURE, LOADMOD,
IBMREQD and LANGUAGE are mandatory.
The first column in the parameter screen is used for editing purposes, possible commands are "I" and "D"
for insertion and deletion. In the second column, the name of the parameter can be entered. The third
column is mandatory and specifies the type of the parameter. Entering "?" displays a list of possible types
from which one type may be selected. In the next column, a length can be entered. The Natural for DB2
checks whether the specified type and length value fit together. The next columns define the subtype and
the in/out value.
When all parameters are specified, press ENTER to return to the Insert Procedure screen.
To actually insert the stored procedure and add it to the catalog, press PF4. If pressing PF4 results in an
error from DB2, press PF2 to display the error information.
92
Natural for DB2 Version 3.1.4 for Mainframes Procedure Maintenance
Enter function code "M" in the Procedure Maintenance menu together with a procedure name as
unique identifier.
RUNOPTS = ’ ___________________________________________________
___________________________________________________
___________________________________________________
___________________________________________________
__________________________________________________ ’
PARMLIST: X display PARMLIST: N (Y/N)
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
Proceed as above but do not enter a procedure name nor use the asterisks"*" notation.
From this list select a specific stored procedure with the line command "MO".
The stored procedure is then displayed for modification. Proceed as described in section Insert a
Stored Procedure above.
93
Procedure Maintenance Natural for DB2 Version 3.1.4 for Mainframes
In the PARMLIST screen (above,) press PF5/Data to display the following window.
94
Natural for DB2 Version 3.1.4 for Mainframes Procedure Maintenance
Enter the library name and the name of the LDA or PDA to be inserted into the PARMLIST definition of
the stored procedure. A maximum of 100 parameters can be inserted.
The parameter STCB will be generated automatically at the top of the PARMLIST.
The individual field names of the LDA or PDA are truncated to the first 8 characters in the PARMLIST
parmnames (DB2 restriction).
95
Procedure Maintenance Natural for DB2 Version 3.1.4 for Mainframes
The field definitions are converted to a Natural object. The Natural object is saved on FUSER in the user
library you specified.
The Natural object can be used as input for the LDA editor after the stow.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
96
Natural for DB2 Version 3.1.4 for Mainframes Procedure Maintenance
Command Description
LI Display the stored procedure in detail
MO Modify the stored procedure
DE Delete the stored procedure
Enter function code "D" in the Procedure Maintenance menu together with a procedure name as
unique identifier.
If you do not enter a procedure name or if you use the "*" notation, a screen with a list of procedures
appears, where you can enter the line command "DE" to delete a procedure.
97
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
Interactive SQL
The Interactive SQL function of the Natural Tools for DB2 enables you to execute SQL statements
dynamically.
Enter function code "I" on the Natural Tools for DB2 Main Menu.
Code Function
---- -------------------------
I SQL Input Member
O Data Output Member
? Help
. Exit
---- -------------------------
Code.. _ Library .. SAG_____
Member ... ________
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
98
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
Code Description
I Displays SQL members in the interactive SQL input screen.
O Displays output members in the interactive SQL output screen.
Parameter Description
Library Specifies the name of the current Natural library which contains the specified input/output
members. Specification of libraries whose names begin with "SYS" is not allowed. The
library name is preset with your Natural user ID.
Member If a valid member name is specified, the corresponding member is displayed.
If a value is specified followed by an asterisk (*), all input/output members in the current
library whose names begin with this value are listed.
If asterisk notation is specified only, a selection list of all input/output members in the
current library is displayed.
If the Member field is left blank, the empty SQL input/output screen is displayed.
99
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Setup Exit Exec Rfind Rchan - + Outpu Canc
The SQL input screen is a free-mode editor which provides a functionality similar to the one of the
Software AG Editor. Using the editor you can enter or edit SQL statements via editor main and line
commands. You can execute the SQL statements immediately from within the editor by pressing PF4
(Exec), or you can save them as an SQL member in a Natural library for later execution.
Note:
The PRINT command is not available in the SQL input screen.
Apart from the editor main and line commands, SQL code maintenance commands are also available to
maintain SQL members in a Natural library. With these maintenance commands, input members can be
listed, retrieved, saved in a Natural library, copied, and purged. They are entered in the command line of
the input screen.
100
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
You can also obtain a list of the available maintenance commands by entering the help character "?" in the
command line of the input screen. A window is displayed from which the desired command can be
selected. The window can be scrolled forwards by pressing PF8, or backwards by pressing PF7.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Setup Exit Exec Rfind Rchan - + Outpu Canc
To assist you in coding your SQL member, exisiting DB2 tables and columns can be listed using the
SELECT command. From the list, you can include table and column names into the editor.
Command Description
SELECT TABLE Selects all tables with the specified creator (optional) and name. For both creator
[creator.]name and name, you can specify a value followed by an asterisk (*), and all tables whose
names begin with this value are selected. If you specify asterisk notation only, all
existing tables are selected. If you specify a table name without a creator, all tables
with the specified name are selected, regardless of their creator.
SELECT COLUMN Selects all columns of the table "creator.name". Since the table must be uniquely
creator.name identified, asterisk notation cannot be used.
101
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
From the table list, you can select a table for display of its columns by marking it with "C" in front of the
table name. The columns of a table are listed together with their type and length.
102
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
If you want to copy table or column names from a selection list into the editor, mark the corresponding
table or column with "M" as shown on the previous screen. The table or column names are copied either
after or before the line marked with "A" or "B" respectively, or to the top of the displayed data.
103
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
If you enter "CREATE TABLE" or "CR TB", the Create Table screen is invoked:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Incl IBack -- - + ++ Next Canc
If you have entered data for a complete SQL statement, you can generate an SQL statement from the
entered data and include it into the SQL input screen. Using PF4 (Incl), you include the generated SQL
code and remain on the Create Table screen. Using PF5 (IBack), you include the generated SQL code and
return to the SQL input screen.
104
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Setup Exit Exec Rfind Rchan - + Outpu Canc
An asterisk (*) in front of a statement line turns this line into a comment line, which means that the
corresponding SQL code is not considered for execution.
105
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
If you specify asterisk notation only, a list of all SQL input members in the current library is displayed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit
From the input screen selection list, SQL members can be selected for display by marking them with an
"S". If the list has been invoked by a PURGE command, members can be purged by marking them with a
"P".
106
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind Rchan - + < > Canc
From the data output screen you have access to output data members only. Output members consist of
data retrieved from the database as a result of executed SQL statements. These data can be browsed and
saved for later use as output members on the Natural system file (FUSER). In addition to the data
retrieved from the database, output members also contain DB2 status information, and the executed SQL
member.
If you execute an SQL statement, the results are automatically shown on the output screen. Thus, you can
enter the interactive SQL output screen also by executing an SQL statement from the input screen. From
the output screen you can return to the input screen by pressing PF3 (Exit).
107
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
The maintenance commands available for output members can be displayed and selected in a window,
too. The window is invoked by entering the help character "?" in the command line of the output screen.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind Rchan - + < > Canc
Apart from the maintenance commands, only browse commands are available, since output members
cannot be modified. Both browse and maintenance commands are entered in the command line of the
output screen.
If an output member is too large to fit on your terminal screen, you can use the FIX ON n command to
keep the first n characters on the screen when scrolling to the left or to the right.
108
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind Rchan - + < > Canc
109
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
If you specify asterisk notation only, a list of all data output members in the current library is displayed.
From the output member selection list, output members can be selected for display by marking them with
an "S". If the list has been invoked by a PURGE command, members can be purged by marking them with
a "P".
110
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
If an SQL member consists of more than one SQL statements, the individual statements must be separated
by a semicolon. They can be executed one by one or all together at the same time. To choose the form of
execution, a window is provided which can be invoked by pressing PF2 (Setup).
111
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
Statements containing cursor names, host variables, or parameter markers cannot be executed with
interactive SQL. Also not executed are statements available as embedded SQL only; that is, statements
whose functions are automatically performed by Natural.
CLOSE
CONNECT
DECLARE
DELETE WHERE CURRENT OF CURSOR
DESCRIBE
EXECUTE
FETCH
INCLUDE
OPEN
PREPARE
SELECT INTO
SET host-variable
SET CURRENT PACKAGESET
UPDATE WHERE CURRENT OF CURSOR
WHENEVER
112
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
Automatic Commit/Rollback
If you select automatic commit/rollback, each modification of the database is automatically either
committed or rolled back, depending on whether all the SQL statements involved execute successfully. If
so, an SQL COMMIT WORK command is executed; if not, an SQL ROLLBACK command backs out all
database modifications since the last commit point.
Optional Commit/Rollback
If you select optional commit/rollback, a window is invoked after each SQL statement, offering you the
option to either commit or roll back the resulting database modifications shown on the screen.
Note:
Since under CICS and IMS/TM each terminal I/O results in a SYNCPOINT, the optional
commit/rollback feature only applies in a TSO environment.
In all environments, you can include SQL COMMIT and ROLLBACK commands in your input member,
too. Under CICS and IMS/TM, however, these commands are translated into the corresponding
TP-monitor calls.
113
Interactive SQL Natural for DB2 Version 3.1.4 for Mainframes
PF-Key Settings
The following PF-key settings apply to the input screen:
Apart from PF2 (Setup), PF4 (Exec), and PF9 (Outpu), the same PF-key settings apply to the output
screen, too. In addition, the following PF-key settings are available:
114
Natural for DB2 Version 3.1.4 for Mainframes Interactive SQL
CMWKF01 should be of variable record format; the record length depends on the size of the SQL output
member and can range from 250 to 4000 bytes.
If UNLDDATA is issued in library SYSDB2, the Unload SQL Results menu is displayed:
Code Function
---- -------------------
U Unload SQL Results
. Exit
---- -------------------
Code .. _ Library .. ________
Member ... ________
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
Code Description
U Unloads results from interactive SQL execution.
Parameter Description
Library Specifies the name of the Natural library from which the specified output members are to be
unloaded. You cannot specify libraries whose names begin with "SYS".
This parameter must be specified.
Member Specifies the name(s) of the output member(s) to be unloaded.
This parameter must be specified.
115
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
The DB2 system tables provide information on the contents of your DB2 system. The Retrieval of System
Tables function enables you to:
The DB2 objects supported by the Retrieval of System Tables function are database, tablespace, table,
index, column, plan, check constraints, statistic tables, package, and DBRM, as well as access rights to
and relationships between these objects.
As selection lists, where all objects are of the same type, and where commands can be issued to
display related objects.
You can list databases, tables, plans, and packages by name. From the database listings, you can
invoke listings of the tablespaces or tables of a database. From the table listing, you can invoke
listings of the columns and indexes of a table. From the plan listing, you can invoke listings of the
DBRMs of a plan, of the package list of a plan, of the tables and indexes used by a plan, and of the
systems which are enabled or disabled for a plan. From the package listing, you can invoke listings of
the tables and indexes used in a package and of the systems which are enabled or disabled for a
package. From the database, table, plan, or package listings, you can also investigate who is
authorized to access a DB2 object. In addition, the User Authorization menu enables you to list all
existing access rights by user ID.
As reports, which merely contain information on different types of DB2 objects, and where only
browse commands can be issued.
Browsing of objects is performed with ISPF-like commands. The most important browse commands can
also be issued via PF keys.
116
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
Enter function code "R" on the Natural Tools for DB2 Main Menu.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
Code Description
D Lists databases defined in the DB2 catalog.
K Lists packages defined in the DB2 catalog.
P Lists plans defined in the DB2 catalog.
S Statistic tables.
T Lists tables defined in the DB2 catalog.
U Provides information on which user(s) can access which DB2 objects.
117
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
Parameter Description
Database Name The name of the database to be listed. Asterisk notation (*) for range specification is
possible. The Database Name parameter is relevant to the List Databases function
only.
Package Collection The collection of the package to be listed. Asterisk notation (*) for range
specification is possible. The Package Collection parameter is relevant to the List
Packages function only.
Package Name The name of the package to be listed. Asterisk notation (*) for range specification is
possible. The Package Name parameter is relevant to the List Packages function
only.
Plan Name The name of the plan to be listed. Asterisk notation (*) for range specification is
possible. The Plan Name parameter is relevant to the List Plans function only.
Table Creator The name of the creator of the table(s) to be listed. Asterisk notation (*) for range
specification is possible. The Table Creator parameter is relevant to the List Tables
function only.
Table Name The name of the table to be listed. Asterisk notation (*) for range specification is
possible. The Table Name parameter is relevant to the List Tables function only.
118
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
List Databases
To invoke the List Databases function
If a value followed by an asterisk is specified, all databases defined in the DB2 catalog whose names
begin with this value are listed.
If asterisk notation is specified only, all databases defined in the DB2 catalog are listed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
Command Description
I Displays information on a database.
S Selects a database to be used with main commands (see below).
U Unselects a database.
AU Displays information on access rights to a database.
TB Displays all tables defined in a database.
TS Displays all tablespaces defined in a database.
119
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
The listings of tables or tablespaces displayed as a result of the "TB" or "TS" command can be used for
further processing, whereas the contents of the screens displayed as a result of the "AU" or "I" command
are for information purposes only.
A list of all line commands available with the List Database function can be invoked as a window by
entering the help character "?" in front of any of the listed databases.
The commands "AU", "TB", and "TS" can also be used as main commands. Main commands are entered
in the command line of the database list screen and apply to all databases previously selected with the "S"
line command.
A further main command is the INFO command, which is the equivalent of the "I" line command, but
displays information on all previously selected databases. Instead of being displayed, all information
resulting from the "I" or INFO commands can also be marked for printing. Even if already displayed,
information can be printed by issuing the PRINT command.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
A list of all main commands available with the List Database function can be invoked as a window by
entering "?" in the command line of the database list screen.
120
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
List Tablespaces
The function to list tablespaces is not part of the Retrieval of System Tables main menu.
To list tablespaces
Command Description
I Displays information on a tablespace.
S Selects a tablespace to be used with main commands.
U Unselects a tablespace.
PT Displays all partitions of a tablespace.
TB Displays all tables defined in a tablespace.
The listings of tables displayed as a result of the "TB" command can be used for further processing,
whereas the listings resulting from the "I" and "PT" commands are for information purposes only.
A list of all line commands available on the tablespace listing screen can be invoked as a window by
entering the help character "?" in front of any of the listed tablespaces.
The commands "PT" and "TB" can also be used as a main commands entered on the command line of the
tablespace listing screen. Main commands apply to all tablespaces previously selected with the "S" line
command.
121
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
A further main command is the INFO command, which is the equivalent of the "I" line command, but
displays information on all previously selected tablespaces. Instead of being displayed, all information
resulting from the "I" or INFO commands can also be marked for printing. Even if already displayed,
information can be printed by issuing the PRINT command.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
A list of all main commands available on the tablespace listing screen can be invoked as a window by
entering the help character "?" in the command line of the screen.
122
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
List Plans
To invoke the List Plans function, enter function code "P" on the Retrieval of System Tables screen. The
name of the plan(s) to be listed must be specified. If a value followed by an asterisk is specified, all plans
defined in the DB2 catalog whose names begin with this value are listed. If asterisk notation is specified
only, all plans defined in the DB2 catalog are listed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
123
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
Command Description
I Displays information on a plan.
S Selects a plan to be used with main commands.
U Unselects a plan.
AU Displays information on access rights to a plan.
DR Displays all DBRMs contained in a plan.
IX Displays all indexes used by a plan.
PK Displays the package list of a plan.
SY Displays the systems enabled or disabled for a plan.
TB Displays tables used in a plan.
The listing displayed as a result of the "DR", "IX", "PK", or "TB" command can be used for further
processing, whereas the contents of the screens displayed as a result of the "I", "AU", or "SY" command
are for information purposes only.
A list of all line commands available with the List Plans function can be invoked as a window by entering
the help character "?" in front of any of the listed plans.
124
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
The commands "AU", "DR", "IX", "PK", "SY", and "TB" can also be used as main commands, which are
entered on the command line of the plan listing screen and apply to all plans previously selected with the
"S" line command.
The INFO main command, which is the equivalent of the "I" line command, displays information on the
DBRMs and their SQL statements contained in the plans previously selected. As with the List Database
function, information resulting from the "I" or INFO commands can be printed, too.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
A list of all main commands available with the List Plans function can be invoked as a window by
entering the help character "?" in the command line of the plan list screen.
DBRMs of Plan
If you issue the "DR" command on the plan listing screen, a list of all DBRMs bound into the selected
plan(s) is displayed.
125
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
The following line commands are available on the DBRM listing screen. Line commands are entered in
front of the desired DBRM(s):
Command Description
I Displays information on a DBRM.
S Selects a DBRM to be used with main commands.
U Unselects a DBRM.
A list of all line commands available on the DBRM listing screen can be invoked as a window by entering
the help character "?" in front of any of the listed DBRMs.
The only main command that applies to DBRMs is the INFO command, which is the equivalent of the "I"
line command, but displays information on all previously selected DBRMs. Instead of being displayed, all
information resulting from the "I" or INFO commands can also be marked for printing. Even if already
displayed, information can be printed by issuing the PRINT command.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
126
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
The following line commands are available on the index listing screen. Line commands are entered in
front of the desired index(es):
Command Description
I Displays information on an index.
S Selects an index to be used with main commands.
U Unselects an index.
CO Displays all columns of an index.
PT Displays the partitions of an index.
The listings of columns displayed as a result of the "CO" or "PT" command cannot be used for further
processing. Like the display resulting from the "I" command, they are for information purposes only.
A list of all line commands available on the index listing screen can be invoked as a window by entering
the help character "?" in front of any of the listed indexes.
The commands "CO" and "PT" can be used as main commands, too, and entered in the command line of
the index listing screen. If so, all columns of all indexes previously selected with the "S" line command
are displayed.
127
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
A further main command is the INFO command, which is the equivalent of the "I" line command, but
displays information on all previously selected indexes. Instead of being displayed, all information
resulting from the "I" or INFO commands can also be marked for printing. Even if already displayed,
information can be printed by issuing the PRINT command.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
A list of all main commands available on the index listing screen can be invoked as a window by entering
the help character "?" in the command line of the screen.
128
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
The following line commands are available on the package list screen. Line commands are entered in front
of the desired package list entry:
Command Description
I Displays information on a package list entry.
S Selects a package list entry to be used with main commands.
U Unselects a package list entry.
PK Displays all packages of a package list entry.
The listing of packages as a result of the "PK" command can be used for further processing, whereas the
display resulting from the "I" command is for information purposes only.
A list of all line commands available with a package list can be invoked as a window by entering the help
character "?" in front of any of the listed entries.
The command "PK" can also be used as main command, which is entered in the command line of the
above screen and applies to all package list entries previously selected with the "S" line command.
129
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
List Packages
To invoke the List Packages function, enter function code "K" on the Retrieval of System Tables screen.
The collection and name of the package(s) to be listed can be specified. If a value followed by an asterisk
is specified, all packages defined in the DB2 catalog whose collections/names begin with this value are
listed. If asterisk notation is specified only, all packages defined in the DB2 catalog are listed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
Command Description
I Displays information on a package.
S Selects a package to be used with main commands.
U Unselects a package.
AU Displays information on access rights to a package.
IX Displays all indexes used by a package.
SY Displays all systems enabled or disabled for a package.
TB Displays all tables used by a package.
The listings of indexes or tables displayed as a result of the "IX" or "TB" command can be used for further
processing, whereas the displays resulting from the "AU", "SY", or "I" command are for information
purposes only.
130
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
A list of all line commands available with the List Packages function can be invoked as a window by
entering the help character "?" in front of any of the listed packages.
The commands "AU", "IX", "SY", and "TB" can also be used as main commands, which are entered in the
command line of the table listing screen and apply to all tables previously selected with the "S" line
command.
The INFO main command, which is the equivalent of the "I" line command, displays information on all
tables previously selected. All information resulting from the "I" or INFO commands can also be printed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
A list of all main commands available with the List Packages function can be invoked as a window by
entering the help character "?" in the command line of the packages list screen.
131
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
List Tables
To invoke the List Tables function
If a value followed by an asterisk is specified, all tables defined in the DB2 catalog whose creator/name
begins with this value are listed.
If asterisk notation is specified only, all tables defined in the DB2 catalog are listed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
132
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
Command Description
I Displays information on a table.
S Selects a table to be used with main commands.
U Unselects a table.
AU Displays information on access rights to a table.
CO Displays all columns of a table.
IX Displays all indexes on a table.
CC Checks constraints.
The listings of indexes displayed as a result of the "IX" command can be used for further processing,
whereas the listings of columns resulting from the "CO" command, as well as the displays resulting from
the "AU" or "I" command, are for information purposes only.
A list of all line commands available with the List Tables function can be invoked as a window by
entering the help character "?" in front of any of the listed tables.
The commands "AU", "CO", and "IX" can also be used as main commands, which are entered in the
command line of the table listing screen and apply to all tables previously selected with the "S" line
command.
133
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
The INFO main command, which is the equivalent of the "I" line command, displays information on all
tables previously selected. All information resulting from the "I" or INFO commands can also be printed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
A list of all main commands available with the List Tables function can be invoked as a window by
entering the help character "?" in the command line of the table listing screen.
134
Natural for DB2 Version 3.1.4 for Mainframes Retrieval of System Tables
User Authorizations
To invoke the User Authorization function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
Code Description
C Displays the columns which can be accessed by the specified grantee.
D Displays the databases which can be accessed by the specified grantee.
K Displays the packages which can be accessed by the specified grantee.
P Displays the plans which can be accessed by the specified grantee.
R Displays the resources which can be accessed by the specified grantee.
T Displays the tables which can be accessed by the specified grantee.
U Displays the system privileges of the specified grantee.
Parameter Description
Grantee A list of all existing DB2 objects of the specified object type to which the specified grantee
has access is displayed.
135
Retrieval of System Tables Natural for DB2 Version 3.1.4 for Mainframes
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12--
Help Exit Canc
Code Description
C Displays the partitioned statistics for columns in a partitioned table space.
D Displays the distribution of the values of the first column of a partitioned index.
I Displays the statistics for a partitioned index.
T Displays the statistics for a partitioned table space.
Parameter Description
Table Creator The name of the creator of the table for which the statistics are to be displayed.
Table Name The name of the table for which the statistics are to be displayed.
Index Owner The name of the owner of the index for which the index statistics are to be displayed.
Index Name The name of the index for which the index statistics are to be displayed.
136
Natural for DB2 Version 3.1.4 for Mainframes Environment Setting
Environment Setting
The Environment Setting facility of the Natural Tools for DB2 allows you to issue interactively special
SQL statements.
In addition, the current values of all supported Special Registers can be displayed.
Entering function code "S" on the Natural Tools for DB2 Main Menu.
The Environment Setting screen is displayed, which offers you the following functions:
137
Environment Setting Natural for DB2 Version 3.1.4 for Mainframes
CONNECT
To invoke the CONNECT function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
The CONNECT statement connects the current application to a designated server. This server is the
current server, which is displayed in the Current Server Version field.
On the Connect screen, you identify the current server by specifying a location name. The identified
server must be known to the local DB2 subsystem.
138
Natural for DB2 Version 3.1.4 for Mainframes Environment Setting
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Free Canc
The SET CURRENT SQLID statement changes the value of the SQL authorization identifier. With SQL
statements that use unqualified table names, DB2 uses the SQLID as an implicit table qualifier. This
enables you to access identical tables with the same table name but with different creator names.
On the Set Current SQLID screen, you can replace the value of CURRENT SQLID by the value of the
special register USER or by a string constant. The string constant can be up to 8 characters long.
In all supported TP-monitor environments, the SQLID can then be kept across terminal I/Os until its
resetting or the end of the session.
139
Environment Setting Natural for DB2 Version 3.1.4 for Mainframes
SET CONNECTION
To invoke the SET CONNECTION function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
On the Set Connection screen, you identify a server by specifying a location name. The identified server
must be known to the local DB2 subsystem.
140
Natural for DB2 Version 3.1.4 for Mainframes Environment Setting
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
The SET CURRENT PACKAGESET statement assigns a value to the special register CURRENT
PACKAGESET.
On the Set Current PACKAGESET screen, you can replace the value of CURRENT PACKAGESET by
the value of the special register USER or by a string constant of up to 18 characters.
141
Environment Setting Natural for DB2 Version 3.1.4 for Mainframes
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
142
Natural for DB2 Version 3.1.4 for Mainframes Environment Setting
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
143
Environment Setting Natural for DB2 Version 3.1.4 for Mainframes
RELEASE
To invoke the RELEASE function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
144
Natural for DB2 Version 3.1.4 for Mainframes Environment Setting
Current Timezone :
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Error Exit Exec Canc
The Display Special Registers screen shows you the current values of the Special Registers of DB2
supported by Natural for DB2.
145
Explain PLAN_TABLE Natural for DB2 Version 3.1.4 for Mainframes
Explain PLAN_TABLE
Important:
Before you use the Explain PLAN_TABLE function, refer to in the section Retrieval and Explain
Functions.
The Explain PLAN_TABLE facility of the Natural Tools for DB2 interprets the results of SQL EXPLAIN
commands from your PLAN_TABLE. The information contained in your PLAN_TABLE is represented
in so-called explanations.
Explanations of a PLAN_TABLE describe the access paths chosen by DB2 to execute SQL statements.
An SQL statement is executed by DB2 in one or more steps. For each execution step, one row is inserted
into the PLAN_TABLE. All rows together describing the access path for one SQL statement are called an
explanation.
The explanations are identified in the PLAN_TABLE by a combination of either plan name, DBRM
name, and query number or collection name, package name, and query number.
EXPLAIN Modes
Invoking the EXPLAIN_TABLE Function
List PLAN_TABLE - Latest Explanations
List PLAN_TABLE - All Explanations
Delete from PLAN_TABLE
Explain PLAN_TABLE - Mass and Batch Processing
EXPLAIN Modes
DB2 provides three ways to explain SQL statements:
Dynamic EXPLAIN
Bind Plan EXPLAIN
Bind Package EXPLAIN
Dynamic EXPLAIN
Executes an SQL EXPLAIN command dynamically, where the explanation is inserted into the
PLAN_TABLE of your current SQLID.
The EXPLAIN command can be issued within the Catalog Maintenance and Interactive SQL facilities of
the Natural Tools for DB2. In addition, the Natural LISTSQL command can be used to extract SQL
statements from cataloged Natural programs, and to issue the SQL EXPLAIN command for the extracted
SQL statements.
146
Natural for DB2 Version 3.1.4 for Mainframes Explain PLAN_TABLE
If you issue the SQL EXPLAIN command dynamically, you should specify a query number to help
identify the explanation in the PLAN_TABLE. The same query number should be used for related
statements.
Depending on the method with which the DBRM used by the dynamic SQL processor is bound into the
plan, DB2 uses two different ways to identify rows in the PLAN_TABLE:
Dynamic mode
Package mode
Dynamic Mode
When an explanation is inserted, the plan name, the DBRM name, and the query number are determined
by DB2 as follows:
Package Mode
When an explanation is inserted, the collection name, the package name, and the query number are
determined by DB2 as follows:
147
Explain PLAN_TABLE Natural for DB2 Version 3.1.4 for Mainframes
collection name is the name of the collection that contains the package;
package name is the name of the package that contains the SQL statement;
query number is equal to the statement number (stmtno), which is generated by the DB2 precompiler.
148
Natural for DB2 Version 3.1.4 for Mainframes Explain PLAN_TABLE
The individual rows of a PLAN_TABLE are displayed one row per line. Rows that describe the same
SQL statement are shown together as one explanation. Different explanations, are separated by empty
lines. You can browse through the list and select a detailed report for individual explanations. If rows have
been inserted into your PLAN_TABLE as a result of a Natural LISTSQL command, the names of the
Natural library and program are also displayed.
Enter function code "X" on the Natural Tools for DB2 Main Menu.
Code Function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
149
Explain PLAN_TABLE Natural for DB2 Version 3.1.4 for Mainframes
Code Description
L The List PLAN_TABLE - Latest Explanations function lists the last explanation for any
combination of the parameters described below.
A The List PLAN_TABLE - All Explanations function lists all explanations for any combination of
the parameters described below.
D The Delete from PLAN_TABLE function deletes the specified explanations from your
PLAN_TABLE.
Parameter Description
Mode Specifies the explanation mode (Dynamic, Plan, or Package).
Plan plan-name Specifies a valid plan name.
In dynamic mode, specifies the DBRM used by the dynamic SQL processor.
If only the first query number is specified, only this query number is displayed;
If only the second query number is specified, all query numbers up to and
including the second query number are displayed;
If both query numbers are specified, all query numbers between and including the
first and the second query number are displayed.
150
Natural for DB2 Version 3.1.4 for Mainframes Explain PLAN_TABLE
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
Commands Available
The following line commands are available within listings of the Explain PLAN_TABLE facility. Line
commands are entered in front of any of the rows of the desired explanation(s).
Command Description
I Displays a window where additional information about an explanation can be selected
S Selects an explanation to be used with the INFO command described below.
U Unselects an explanation for use with the INFO command.
A list of the line commands available can be invoked as a window by entering the help character "?" in
front of any of the listed rows.
151
Explain PLAN_TABLE Natural for DB2 Version 3.1.4 for Mainframes
Apart from the line commands, the INFO command can be specified, too. The INFO command must be
entered in the command line of the listing screen and is the equivalent of the "I" line command. INFO
displays a window where additional information can be selected on all explanations previously selected by
the "S" line command.
In Plan mode, the following window is displayed, where you can select which additional information you
want to be displayed or printed.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Rfind - + < > Canc
152
Natural for DB2 Version 3.1.4 for Mainframes Explain PLAN_TABLE
Browsing of data displayed is performed with browse commands, of which the most important can also be
issued via PF keys.
Option Description
Information on If a plan/package name has been specified, this option includes information from
Plan/Package the DB2 catalog, such as date and time of the bind, as well as several bind options.
In Dynamic mode, this option is not available.
Statements of If a plan/package name has been specified, this option provides information on the
Plan/Package explained SQL statements contained in this package. This information is taken
from the DB2 catalog. In Dynamic mode, this option is not available.
Data from This option provides information from the PLAN_TABLE about the selected rows.
PLAN_TABLE
Evaluation of This option provides a description of the PLAN_TABLE. For each execution step,
PLAN_TABLE it describes:
the locks chosen by DB2,
whether a join operation is performed,
whether the data is sorted and why the sort is performed,
the access path in detail.
Catalog Statistics This option provides statistical information from the DB2 catalog.
Columns of Indexes This option provides the columns of used indexes including catalog statistics on
this columns.
153
Explain PLAN_TABLE Natural for DB2 Version 3.1.4 for Mainframes
The Delete from PLAN_TABLE function is useful to delete old data before either binding or rebinding a
plan, or before executing an SQL EXPLAIN command.
To prevent PLAN_TABLE explanations from being deleted unintentionally, you are prompted for
confirmation:
will be executed.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Del Canc
Apart from the global PF-key settings, with the Delete from PLAN_TABLE function of the Explain
PLAN_TABLE facility, PF5 (Del) is used to confirm the deletion of previously selected explanations.
154
Natural for DB2 Version 3.1.4 for Mainframes Explain PLAN_TABLE
To invoke this facility, LOGON to library SYSDB2 and enter the command EXPLAINB. The following
screen is displayed:
Code Function
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
In addition to function codes "L" (List PLAN_TABLE - Latest Entries function) and "A" (List
PLAN_TABLE - All Entries function), function code "O" (Output Options) is available.
155
Explain PLAN_TABLE Natural for DB2 Version 3.1.4 for Mainframes
The Output Options function enables you to restrict the output of information on PLAN_TABLE entries.
The various options are listed in a window invoked by entering function code "O" on the above Explain
PLAN_TABLE menu. The window is similar to the one invoked by the online "I" or INFO commands.
+---------------------------------------------------------+
! !
! !
! Select what to display !
! !
! _ information about plan/package !
! _ statements of plan/package !
! _ data from PLAN_TABLE !
! _ evaluation of PLAN_TABLE !
! _ catalog statistics !
! _ columns of used indexes ! kage )
! !
! !
+---------------------------------------------------------+
Queryno ....... _____ - _____
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
If the Output Options function has been selected, only information covered by the options marked for
output are printed.
If function code "O" has not been selected, all information on PLAN_TABLE entries covered by the
options listed in the above window are printed.
156
Natural for DB2 Version 3.1.4 for Mainframes File Server Statistics
Enter function code "F" on the Natural Tools for DB2 Main Menu.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Next Canc
This screen provides information on parameters that must be specified when generating the file server.
157
File Server Statistics Natural for DB2 Version 3.1.4 for Mainframes
If the file server storage medium is the Software AG Editor buffer pool, the File Server - Generation
Statistics screen looks as follows:
File Server Dataset Name ......: STORAGE MEDIUM IS EDITOR BUFFER POOL
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Next Canc
If you press PF11 (Next), a second screen is displayed, the File Server - User Statistics screen, showing
statistics that have been kept since the file server was installed - Statistics since Generation -, and statistics
about the current Natural session - Current Session Statistics.
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Prev Canc
158
Natural for DB2 Version 3.1.4 for Mainframes File Server Statistics
If you press PF10 (Prev), you are returned to the File Server - Generation Statistics screen.
Statistics are updated, each time you press ENTER, PF10, or PF11.
If the file server storage medium is the Software AG Editor buffer pool, the user Statistics screen looks as
follows:
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Prev Canc
Note that the section "Statistics since Generation" could not be provided by this display.
159
Issuing DB2 Commands from Natural Natural for DB2 Version 3.1.4 for Mainframes
A file is maintained for each user on the FUSER file. This file is stored under the object name DB2$CMD
in the Natural library of the current user.
You can select a command and submit it, save the command file and save and/or print the output report.
Enter function code "D" on the Natural Tools for DB2 Main Menu.
Code Function
C Display Commands
O Display Output
? Help
. Exit
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
160
Natural for DB2 Version 3.1.4 for Mainframes Issuing DB2 Commands from Natural
Code Decription
C Displays your command file. If you have not saved a command file yet, a default file is displayed.
O If an output file exists, the output report is displayed.
Library: You can enter a user name or library. The default is the currrent user ID.
161
Issuing DB2 Commands from Natural Natural for DB2 Version 3.1.4 for Mainframes
Mark the line of the command you want to execute with ’S’ and press PF4
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Subm Save Next Canc
You can modify the command file. Save your modifications with PF5.
162
Natural for DB2 Version 3.1.4 for Mainframes Issuing DB2 Commands from Natural
To execute a command
DSNT360I - ***********************************
DSNT361I - * DISPLAY DATABASE SUMMARY
* GLOBAL
DSNT360I - ***********************************
DSNT362I - DATABASE = DSNDB04 STATUS = RW
DBD LENGTH = 72674
DSNT397I -
NAME TYPE PART STATUS PHYERRLO PHYERRHI CATALOG PIECE
-------- ---- ---- ------------------ -------- -------- -------- -----
ADRESSE TS RW
ALIASRBY TS RW
ALLDATA0 TS RW
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Save -- - + ++ Canc
To save the command file, use PF5; the output file is stored under the object name DB2$OUT in the
Natural library of the current user.
163
Issuing DB2 Commands from Natural Natural for DB2 Version 3.1.4 for Mainframes
DSNT360I - ***********************************
DSNT361I - * DISPLAY DATABASE SUMMARY *
* GLOBAL *
DSNT360I - ***********************************
DSNT362I - DATABASE = DSNDB01 STATUS = RW
DBD LENGTH = 8000
DSNT397I -
NAME TYPE PART STATUS PHYERRLO PHYERRHI CATALOG PIECE
-------- ---- ---- ------------------ -------- -------- -------- -----
DBD01 TS RW
SPT01 TS RW
SCT02 TS RW
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Print -- - + ++ Canc
164
Natural for DB2 Version 3.1.4 for Mainframes Natural System Commands for DB2
LISTSQL [ object-name ]
The LISTSQL command lists the Natural statements in the source code of a programming object that are
associated with a database access, and the corresponding SQL statements into which they have been
translated. LISTSQL is issued from the Natural NEXT prompt.
Thus, before executing a Natural program which accesses a DB2 table, you can view the generated SQL
code by using the command LISTSQL.
If a valid object name is specified, the object to be displayed must be stored in the library to which you are
currently logged on.
If no object name is specified, LISTSQL refers to the object currently in the Natural source area.
The generated SQL statements contained in the specified object are listed one per page.
165
Natural System Commands for DB2 Natural for DB2 Version 3.1.4 for Mainframes
Within the listed results, you can go from one listed SQL statement to another by pressing PF10 (Prev) or
PF11 (Next). If a single SQL statement does not fit on the screen, you can scroll backwards or forwards
by pressing PF7 or PF8, respectively.
If a static DBRM has been generated, the name of this DBRM is displayed in the DBRM field of the
LISTSQL screen; otherwise, the DBRM field remains empty.
If an error occurs, PF2 (Error), which executes the SQLERR command, can be used to provide
information on DB2 errors.
With PF4 (Expl), a DB2 EXPLAIN command can be executed for the SQL statement currently listed. The
query number (Queryno) for the EXPLAIN command is set to "1" by default, but you can overwrite this
default.
166
Natural for DB2 Version 3.1.4 for Mainframes Natural System Commands for DB2
With PF6 (Parms), a further screen is displayed which lists all parameters from the SQLDA for the
currently displayed SQL statement:
static parms :
SQLDA
Nr Type Length
1. CHAR 18 0728 0000 0012 01C5 0000 0000 0601 0000
2. SMALLINT 2 073A 0000 0002 01F5 0000 0000 0201 0000
3. CHAR 8 073C 0000 0008 01C5 0000 0000 0201 0000
4. SMALLINT 2 0744 0000 0002 01F5 0000 0000 0201 0000
5. SMALLINT 2 0746 0000 0002 01F5 0000 0000 0201 0000
6. CHAR 1 0748 0000 0001 01C5 0000 0000 0201 0000
7. CHAR 1 0749 0000 0001 01C5 0000 0000 0201 0000
8. SMALLINT 2 074A 0000 0002 01F5 0000 0000 0201 0000
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit - + Canc
In static mode, static information is also displayed, which includes the static DBRM name, the DB2
consistency token and some internal static parameters.
167
Natural System Commands for DB2 Natural for DB2 Version 3.1.4 for Mainframes
The EXPLAIN command provides information on the DB2 optimizer’s choice of strategy for executing
SQL statements. For the EXPLAIN command to be executed, a PLAN_TABLE must exist. The
information determined by the DB2 optimizer is written into this table. The corresponding explanation is
read from the PLAN_TABLE and displayed via the EXPLAIN Result screen.
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Info - + Canc
If an explanation does not fit on one screen, you can scroll backwards and forwards by pressing PF7 or
PF8, respectively.
The value in the Estimated cost field is taken from SQLERRD (4) in the SQLCA; it is a rough estimate of
the required resources.
With PF4 (Info), the additional information that is provided with the EXPLAINB command is displayed.
168
Natural for DB2 Version 3.1.4 for Mainframes Natural System Commands for DB2
The command LISTSQLB can be executed in batch mode or issued online from the Natural NEXT line.
Code Function
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Exit Canc
By specifying a valid member name, the explanation of SQL statements can be limited to certain
member(s); an asterisk (*) can be used for range specification:
If you specify a unique member name, all SQL statements contained in this member are explained;
If you specify a value followed by an asterisk, all SQL statements contained in all members with
names beginning with the specified value are explained;
If you specify an asterisk only (or leave the field blank), all SQL statements of all existing SQL
members are explained.
A query number must be specified, so that with each issued EXPLAIN command, the newly created
explanation is added to the appropriate query number. The default query number is 1.
To issue the LISTSQL command, enter function code "X" and specify a valid member name and query
number; all SQL statements contained in the specified member(s) are explained.
169
Natural System Commands for DB2 Natural for DB2 Version 3.1.4 for Mainframes
If LISTSQLB is executed online, the following screen informs you about the processing status of the
command and if any errors have occurred.
Current Object :
Library TEST
Member RTTB--IN
Statistics :
Members read 1
with SQL 1
SQL statements 7
Member Message
RTTB--IN OK
If executed in batch mode, error messages are written to a dataset referred to by DD name CMPRINT
(logical printer 0).
170
Natural for DB2 Version 3.1.4 for Mainframes Natural System Commands for DB2
When a DB2 error occurs, Natural issues an appropriate error message. When you enter the SQLERR
command, the following information on the most recent DB2 error is displayed:
The SQLERR command can be issued either from the Natural NEXT prompt or from within a Natural
program (by using the FETCH statement).
171
Natural System Commands for DB2 Natural for DB2 Version 3.1.4 for Mainframes
Important:
LISTDBRM has to be issued from library SYSDB2, which means you have to LOGON to SYSDB2
first and then enter the command LISTDBRM.
Code Function
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Exit Canc
Code Description
D Displays programs with DB2 access and their corresponding DBRM.
If no DBRM name is shown, the corresponding program uses dynamic SQL.
R Lists all programs that use a given DBRM. If no DBRM name is specified, all programs that use
dynamic SQL are listed.
172
Natural for DB2 Version 3.1.4 for Mainframes Natural System Commands for DB2
Parameter Description
Library Specifies the name of a Natural library.
Library names beginning with "SYS" are not permitted.This parameter must be specified.
Member Specifies the name of the Natural program (member) to be displayed.
This parameter is optional and can be used to limit the output.
If a value is specified followed by an asterisk (*), all members in the specified library with
names beginning with this value are listed.
If the Member field is left blank, or if an asterisk is specified only, all members in the
specified library are listed.
DBRM Specifies a valid DBRM name. If left blank, programs that run dynamically are referenced.
This parameter applies to function code "R" only.
173
Natural Tools for DB2 with Natural Security Natural for DB2 Version 3.1.4 for Mainframes
Module Function
APMENU-P Application plan maintenance.
APENV--P Job Profile menu of application plan maintenance.
CMMENU-P Catalog maintenance.
PC MENU-P Procedure maintenance
ISMENU-P Interactive SQL.
RTMENU-P Retrieval of system tables.
ESMENU-P Environment setting.
XPMENU-P Explain PLAN_TABLE.
SEMENU-P File server statistics.
In addition, the following parameter settings are recommended for the security profile of library SYSDB2:
Parameter Value
Startup MENU
Batch Execution NO
174
Natural for DB2 Version 3.1.4 for Mainframes DDM Generation
DDM Generation
This section covers the following topics:
If you do not have Predict installed, use the SYSDDM function "SQL Services" to generate Natural
DDMs from DB2 tables. This function is invoked from the main menu of SYSDDM and is described on
the following pages.
SQL Services
If you use SYSDDM SQL services in a CICS environment without file server, specify CONVERS=ON in
the NDBPARM module, otherwise you might get SQL code -518.
The SQL Services offer a number of functions related to DB2 tables. If you select "SQL Services" on the
main menu of the SYSDDM utility, a menu is displayed, which offers you the following functions:
To invoke the function, enter function code "S" on the SQL Services Menu.
If you enter the function code only, you obtain a list of all tables defined to the DB2 catalog.
If you do not want a list of all tables but would like only a certain range of tables to be listed, you can, in
addition to the function code, specify a start value in the Table Name and/or Creator fields. You can also
use asterisk notation (*) for the start value.
When you invoke the function, the Select SQL Table From A List screen is invoked displaying a list of all
DB2 tables requested.
On the list, you can mark a DB2 table with either "G" for Generate DDM from an SQL Table or "L" for
List Columns of an SQL Table. Then the corresponding function is invoked for the marked table.
175
DDM Generation Natural for DB2 Version 3.1.4 for Mainframes
To invoke the function, enter function code "G" on the SQL Services Menu along with the name and
creator of the table for which you wish a DDM to be generated.
If you do not know the table name/creator, you can use the function "Select SQL Table from a List" to
choose the table you want.
If you do not want the creator of the table to be part of the DDM name, enter a "N" in the field "DDM
Name with Creator" when you invoke the Generate function (default is "Y").
Important:
Since the specification of any special characters as part of a field or DDM name does not comply
with Natural naming conventions, any special characters allowed within DB2 must be avoided.
DB2 delimited identifiers must be avoided, too.
If you wish to generate a DDM for a table for which a DDM already exists and you want the existing one
to be replaced by the newly generated one, enter a "Y" in the Replace field when you invoke the Generate
function.
By default, Replace is set to "N" to prevent an existing DDM from being replaced accidentally. If Replace
is "N", you cannot generate another DDM for a table for which a DDM has already been generated.
DBID/FNR Assignment
When the "Generate DDM from an SQL Table" function is invoked for a table for which a DDM is to be
generated for the first time, the DBID/FNR Assignment screen is displayed. If a DDM is to be generated
for a table for which a DDM already exists, the existing DBID and FNR are used and the DBID/FNR
Assignment screen is suppressed.
On the DBID/FNR Assignment screen, enter one of the database IDs (DBIDs) chosen at Natural
installation time, and the file number (FNR) to be assigned to the DB2 table. Natural requires these
specifications for identification purposes only.
The range of DBIDs which are reserved for DB2 tables is specified in the NTDB macro of the Natural
parameter module (see the Natural Operations for Mainframes documentation) in combination with the
NDBID macro of the parameter module NDBPARM. Any DBID not within this range is not accepted.
The FNR can be any valid file number within the database (between 1 and 255).
After a valid DBID and FNR have been assigned, a DDM is automatically generated from the specified
table.
176
Natural for DB2 Version 3.1.4 for Mainframes DDM Generation
The maximum field length supported by Natural is 253 bytes. If a DB2 table contains a column which is
longer than 253 bytes, this column has to be redefined as a one-dimensional array; otherwise the column is
truncated and only the first 253 bytes are considered.
When redefined as an array, this array is represented in the DDM as a multiple-value field. Arrays are
defined on the Long Field Redefinition screen, which is automatically invoked for each column over 253
bytes in length.
On the Long Field Redefinition screen you specify the element length of the array; that is, the length of
the occurrences. The number of occurrences depends on the length you specify.
If, for example, a DB2 column has a length of 2000 bytes, you can specify an array element length of 200
bytes, and you receive a multiple-value field with 10 occurrences, each occurrence with a length of 200
bytes.
Since redefined long fields are no multiple-value fields in the sense of Natural, the Natural C* notation
makes no sense here and is therefore not supported.
When such a redefined long field is defined in a Natural view for being referenced by Natural SQL
statements (that is, by host variables which represent multiple-value fields), both when defined and when
referenced, the specified range of occurrences (index range) must always start with occurrence 1. If not, a
Natural syntax error is returned.
Example:
UPDATE table SET varchar = #arr(*)
SELECT ... INTO #arr(1:5)
Note:
When such a redefined long field is updated with the Natural DML UPDATE statement, care must be
taken to update each occurrence appropriately.
For each variable length column, an additional length indicator field (format/length I2) is generated in the
DDM. The length is always measured in number of characters, not in bytes. To obtain the number of bytes
of a VARGRAPHIC or LONG VARGRAPHIC field, the length must be multiplied by 2.
The name of a length indicator field begins with "L@" followed by the name of the corresponding field.
The value of the length indicator field can be checked or updated by a Natural program.
If the length indicator field is not part of the Natural view and if the corresponding field is a redefined
long field, the length of this field with UPDATE and STORE operations is calculated without trailing
blanks.
177
DDM Generation Natural for DB2 Version 3.1.4 for Mainframes
Null Values
With Natural, it is possible to distinguish between a null value and the actual value "0"(or "blank") in a
DB2 column.
When a Natural DDM is generated from the DB2 catalog, an additional null indicator field is generated
for each column which can be NULL; that is, which has neither "NOT NULL" nor "NOT NULL WITH
DEFAULT" specified.
The name of the null indicator field begins with "N@" followed by the name of the corresponding field.
When the column is read from the database, the corresponding indicator field contains either "0" (if the
column contains a value, including the value "0" or "blank") or "-1" (if the column contains no value).
Example:
The column "NULLCOL CHAR(6)" in a DB2 table definition would result in the following view fields:
NULLCOL A 6.0
N@NULLCOL I 2.0
When the field NULLCOL is read from the database, the additional field N@NULLCOL contains:
"0" if NULLCOL contains a value (including the values "0" and "blank"),
"-1" if NULLCOL contains no value.
A null value can be stored in a database field by entering "-1" as input for the corresponding null indicator
field.
Note:
If a column is NULL, an implicit RESET is performed on the corresponding Natural field.
178
Natural for DB2 Version 3.1.4 for Mainframes DDM Generation
To invoke this function, enter function code "L" on the SQL Services Menu along with the name and
creator of the table whose columns you wish to be listed.
The List Columns screen for this table is invoked, which lists all columns of the specified table and
displays the following information for each column:
Variable Content
Name The DB2 name of the column.
Type The column type.
Length The length (or precision if Type is DECIMAL) of the column as defined in the DB2 catalog.
Scale The decimal scale of the column (only applicable if Type is DECIMAL).
Update Y The column can be updated.
Not A column which is of a scale length or type not supported by Natural is marked with an
asterisk (*). For such a column, a view field cannot be generated. The maximum scale length
supported is 7 bytes.
Types supported are:
CHAR, VARCHAR, LONG VARCHAR, GRAPHIC, VARGRAPHIC, LONG
VARGRAPHIC, DECIMAL, INTEGER, SMALLINT, DATE, TIME, TIMESTAMP, and
FLOAT.
The data types DATE, TIME, TIMESTAMP and FLOAT are converted into numeric or alphanumeric
fields of various lengths: DATE is converted into A10, TIME into A8, TIMESTAMP into A26, and
FLOAT into F8.
For DB2, Natural provides a DB2 TIMESTAMP column as an alphanumeric field (A26) of the format
"YYYY-MM-DD-HH.SS.MMMMMM".
Since Natural does not yet support computations with such fields, a Natural subprogram called
NDBSTMP is provided to enable this kind of functionality.
179
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
General Information
Internal Handling of Dynamic Statements
Preparing Natural Programs for Static Execution
Assembler/Natural Cross-References
Execution of Natural in Static Mode
Static SQL with Natural Security
Mixed Dynamic/Static Mode
Messages and Codes
Application Plan Switching in Static SQL
180
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
General Information
The SQL support of Natural combines the flexibility of dynamic SQL support with the high performance
of static SQL support.
In contrast to static SQL support, the Natural dynamic SQL support does not require any special
consideration with regard to the operation of the SQL interface. All SQL statements required to execute an
application request are generated automatically and can be executed immediately with the Natural RUN
command. Before executing a program, you can look at the generated SQL code, using the LISTSQL
command.
Access to DB2 through Natural has the same form whether dynamic or static SQL support is used. Thus,
with static SQL support, the same SQL statements in a Natural program can be executed in either dynamic
or static mode. An SQL statement can be coded within a Natural program and, for testing purposes, it can
be executed using dynamic SQL. If the test is successful, the SQL statement remains unchanged and static
SQL for this program can be generated.
Thus, during application development, the programmer works in dynamic mode and all SQL statements
are executed dynamically, whereas static SQL is only created for applications that have been transferred to
production status.
181
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
NDBIOMO
The Statement Table
Processing of SQL Statements Issued by Natural
NDBIOMO
As each dynamic execution of an SQL statement requires a statically defined DECLARE STATEMENT
and DECLARE CURSOR statement, a special I/O module (NDBIOMO) is provided which contains a
fixed number of these STATEMENTs and CURSORs. This number is specified during the generation of
NDBIOMO.
the name of the Natural program that contains this SQL statement,
the line number of the SQL statement in this program,
the name of the Natural library, into which this program was stowed,
the time stamp when this program was stowed.
Once a statement has been prepared, it can be executed several times with different variable values, using
the dynamic SQL statement EXECUTE USING DESCRIPTOR or OPEN CURSOR USING
DESCRIPTOR respectively.
When the full capacity of the statement table is reached, the entry for the next prepared statement
overwrites the entry for a free statement whose latest execution is the least recent one.
When a new SELECT statement is requested, a free entry in the statement table with the corresponding
cursor is assigned to it and all subsequent FETCH, UPDATE, and DELETE statements referring to this
SELECT statement will use this cursor. Upon completion of the sequential scanning of the table, the
cursor is released and free for another assignment. While the cursor is open, the entry in the statement
table is marked as used and cannot be reused by another statement.
If the number of nested FIND (SELECT) statements reaches the number of entries available in the
statement table, any further SQL statement is rejected at execution time and a Natural error message is
returned.
182
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
The size of the statement table depends on the size specified for NDBIOMO. Since the statement table is
contained in the DB2 buffer area, the DB2SIZE parameter may not be sufficient and may need to be
increased.
1. The typical SELECT statement is prepared by a program flow which contains the following
embedded SQL statements (note that X and SQLOBJ are SQL variables, not program labels):
DECLARE SQLOBJ STATEMENT
DECLARE X CURSOR FOR SQLOBJ
INCLUDE SQLDA (copy SQL control block)
Then, the following statement is moved into SQLSOURCE:
(The question marks above are parameter markers which indicate where values are to be inserted at
execution time.)
PREPARE SQLOBJ FROM SQLSOURCE
183
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
Basic Principles
The Generation Procedure - CMD CREATE Command
Precompilation of the Generated Assembler Program
The Modification Procedure - CMD MODIFY Command
BIND of the Precompiled DBRM
Basic Principles
Static SQL is generated in Natural batch mode for one or more Natural applications which can consist of
one or more Natural object programs. The number of programs that can be modified for static execution in
one run of the generation procedure is limited to 999.
During the generation procedure, the database access statements contained in the specified Natural objects
are extracted, written to work files, and transformed into a temporary Assembler program. If no Natural
program is found that contains SQL access or if any error occurs during static SQL generation, batch
Natural terminates and condition code 40 is returned, which means that all further JCL steps should no
longer be executed.
The Natural modules NDBCHNK and NDBSTAT must reside in a STEPLIB of the generation step. Both
are loaded dynamically during execution of the generation step.
The temporary Assembler program is written to a temporary file (the Natural work file CMWKF06) and
precompiled. During the precompilation step, a Database Request Module (DBRM) is created, and after
the precompilation step, the precompiler output is extracted from the Assembler program and written to
the corresponding Natural objects, which means that the Natural objects are modified (prepared) for static
execution. The temporary Assembler program is no longer used and deleted.
The Natural subprogram NDBDBRM can be used to check whether a Natural program contains SQL
access and whether it has been modified for static execution.
A static DBRM is created by using either the sample job provided on the installation tape or an
appropriate job created with the Create DBRM function.
184
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
Since a new SYSDB2 library has been created when installing Natural for DB2, ensure that it contains all
Predict interface programs necessary to run the static SQL generation. These programs are loaded into
SYSDB2 at Predict installation time (see the relevant Predict documentation).
Then specify the CMD CREATE command and the Natural input necessary for the static SQL generation
process; the CMD CREATE command has the following syntax:
The generation procedure reads but does not modify the specified Natural objects. If one of the specified
programs was not found or had no SQL access, return code 4 is returned at the end of the generation step.
Static Name
If the PREDICT DOCUMENTATION option is to be used, a corresponding Predict static SQL entry must
be available and the static-name must correspond to the name of this entry. In addition, the static-name
must correspond to the name of the DBRM to be created during precompilation. The static-name can be
up to 8 characters long and must conform to Assembler naming conventions.
USING Clause
The using-clause specifies the Natural objects to be contained in the DBRM. These objects can either be
specified explicitly as INPUT DATA in the JCL or obtained as PREDICT DOCUMENTATION from
Predict.
YES
INPUT DATA OFF
WITH XREF NO FS [LIB lib-name]
PREDICT DOCUMENTATION ON
FORCE
If the parameters to be specified do not fit in one line, specify the command identifier (CMD) and the
various parameters in separate lines and use both the input delimiter (as specified with the ID parameter;
default is ",") and the continuation indicator (as specified with the CF parameter; default is "%") as shown
in the following example:
Example:
CMD
CREATE,DBRM,static,USING,PREDICT,DOCUMENTATION,WITH,XREF,NO,%
LIB,library
185
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
Alternatively, you can also use abbreviations as shown in the following example:
Example:
CMD CRE DBRM static US IN DA W XR Y FS OFF LIB library
The sequence of the parameters USING, WITH, FS, and LIB is optional.
INPUT DATA
As input data, the applications and names of the Natural objects to be included in the DBRM must be
specified in the subsequent lines of the job stream (application-name,object-name). A subset of these
objects can also be excluded again (excluded-objects). Objects in libraries whose names begin with "SYS"
can be used for static generation, too.
The applications and names of Natural objects must be separated by the input delimiter (as specified with
the ID parameter; default is ","). If you wish to specify all objects whose names begin with a specific
string of characters, use an object-name or excluded-objects name that ends with asterisk notation (*). To
specify all objects in an application, use asterisk notation only.
Example:
LIB1,ABC*
LIB2,A*,AB*
LIB2,*
:
.
The specification of applications/objects must be terminated by a line that contains a period (.) only.
PREDICT DOCUMENTATION
Since Predict supports static SQL for DB2, you can also have Predict supply the input data for creating
static SQL by using already existing PREDICT DOCUMENTATION.
Since Predict Active References supports static SQL for DB2, the generated static DBRM can be
documented in Predict and the documentation can be used and updated with Natural.
WITH XREF is the option which enables you to store cross-reference data for a static SQL entry in
Predict each time a static DBRM is created (YES). You can instead specify that no cross-reference data
are stored (NO) or that a check is made to determine whether a Predict static SQL entry for this static
DBRM already exists (FORCE). If so, cross-reference data are stored; if not, the creation of the static
DBRM is not allowed. For more detailed information on Predict Active References, refer to the relevant
Predict documentation.
When WITH XREF (YES/FORCE) is specified, XREF data are written for both the Predict static SQL
entry (if defined in Predict) and each generated static Natural program. However, static generation with
WITH XREF (YES/FORCE) is possible only if the corresponding Natural programs have been cataloged
with XREF ON.
186
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
WITH XREF FORCE only applies to the USING INPUT DATA option.
Note:
If you do not use Predict, the XREF option must be omitted or set to NO and the module NATXRF2
need not be linked to the Natural nucleus.
FS Option
If the FS (file server) option is set to ON, a second SELECT is generated for the Natural file server. ON is
the default setting.
If the FS option is set to OFF, no second SELECT is generated, which results in less SQL statements
being generated in your static DBRM and thus in a smaller DBRM.
LIB Option
With the LIB (library) option, a Predict library other than the default library (*SYSSTA*) can be specified
to contain the Predict static SQL entry and XREF data. The name of the library can be up to eight
characters long.
Later, the DBRM serves as input for the BIND step and the Assembler program as input for the
modification step.
187
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
In addition, any existing copies of these objects in the Natural global buffer pool (if available) are deleted
and XREF data are written to Predict (if specified during the generation procedure).
To perform the modification procedure, LOGON to SYSDB2 and specify the CMD MODIFY command
which has the following syntax:
The input for the modify step is the precompiler output which must reside on a dataset defined as the
Natural work file CMWKF01.
The output consists of precompiler information which is written to the corresponding Natural objects. In
addition, a message is returned telling you whether it was the first time an object was modified for static
execution ("modified") or whether it had been modified before ("re-modified").
If the XREF option is specified, the Natural work file CMWKF02 must be defined to contain the resulting
list of cross-reference information concerning the statically generated SQL statements (see also
Assembler/Natural Cross-References).
This step performs the BIND against DB2. One or more DBRMs (as created by the precompiler) are
processed to create a DB2 application plan. In addition to the static DBRMs created above, this
application plan contains the dynamic DBRM NDBIOMO provided by Natural itself.
A DBRM can be bound into any number of application plans where it might be required. A plan is
physically independent of the environment where the program is to be run. However, you can group your
DBRMs logically into plans which are to be used for either batch or online processing, where the same
DBRM can be part of both a batch plan and an online plan.
Unless you are using plan switching, only one plan can be executed per Natural session. Thus, you must
ensure that the plan name specified in the BIND step is the same as the one used to execute Natural.
188
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
Assembler/Natural Cross-References
If you specify the XREF option of the MODIFY command, an output listing is created on the work file
CMWKF02, which contains the DBRM name and the Assembler statement number of each statically
generated SQL statement together with the corresponding Natural source code line number, program
name, library name, database ID and file number.
-------------------------------------------------------------------------....
DBRMNAME STMTNO LINE NATPROG NATLIB DB FNR COMMENT ....
-------------------------------------------------------------------------....
TESTDBRM 000627 0390 TESTPROG SAG 010 042 INSERT ....
000641 0430 INSERT ....
000652 0510 SELECT ....
000674 0570 SELECT ....
000698 0570 SELECT 2ND ....
000728 0650 UPD/DEL ....
000738 0650 UPD/DEL 2ND ....
000751 0700 SELECT ....
000775 0700 SELECT 2ND ....
Column Explanation
DBRMNAME Name of the DBRM which contains the static SQL statement.
STMTNO Assembler statement number of the static SQL statement.
LINE Corresponding Natural source code line number.
NATPROG Name of the Natural program that contains the static SQL statement.
NATLIB Name of the Natural library that contains the Natural program.
DB / FNR Natural database ID and file number.
COMMENT Type of SQL statement, where "2ND" indicates that the corresponding statement is used
for a reselection; see also the Concept of the File Server.
To execute static SQL start Natural and execute the corresponding Natural program. Internally, the
Natural runtime interface evaluates the precompiler data written to the Natural object and then performs
the static accesses.
189
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
If a library is defined in Natural Security and the DBID and FNR of this library are different from the
default specifications, the static generation procedure automatically switches to the DBID and FNR
specifications defined in Natural Security.
The mode in which a program is run is determined by the Natural object program itself. If a static DBRM
is referenced in the executing program, all statements in this program are executed in static mode.
Note:
Natural programs which return a runtime error do not automatically execute in dynamic mode.
Instead, either the error must be corrected or, as a temporary solution, the Natural program must be
recataloged to be able to execute in dynamic mode.
Within the same Natural session, static and dynamic programs can be mixed without any further
specifications. The decision which mode to use is made by each individual Natural program.
190
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
Program NDBCHNK has been invoked to allocate space for Natural object load, but the allocation has
failed; retry or increase the free storage pool.
Program NDBCHNK has been invoked to write a Natural object row into the appropriate buffer, but the
write has failed; this is probably a NDBCHNK program error.
Program NDBSTAT has been invoked to retrieve next DB2 statement information from the Natural object
loaded in main storage, but the retrieval has failed (RC was neither 0 (OK) nor 4 (EOP)); the probable
cause is a Natural object inconsistency.
Program NDBSTAT has been invoked to retrieve next DB2 statement information from the Natural object
loaded in main storage, but the Adabas command code returned was invalid; the probable cause is a
Natural object inconsistency.
Program NDBCHNK has been invoked to free the area allocated for Natural object load, but the release
has failed; this is probably a program error.
Program NDBSTAT has been invoked to know the time stamp associated to the loaded Natural object, but
the call has failed; this is probably a program error.
Program NDBSTAT has been invoked to retrieve the next compilation A-list element, but the retrieval has
failed (RC was neither 0 (OK) nor 20 (EOL)); the probable cause is a Natural object inconsistency.
Program NDBSTAT has been invoked to retrieve the next compilation A-list element, but the DB2 format
code returned is invalid; the probable cause is a Natural object inconsistency.
The table for a second selection logs the statement number of all second SELECT statements. The table is
reset if there are more than 100 entries, which means with many nested program loops. If the table is reset,
no second UPDATE or DELETE statements are generated.
191
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
The versions of the Natural programs used for the static generation (library SYSSQL) must be the same as
one of the dynamically loaded Assembler program NDBSTAT.
A Natural object address was not found and the object cannot be modified. Either the object was not found
or the address was wrong.
STAT9019 *** Warning: Natural terminates abnormally, run may continue. ***
Warning: Natural terminates abnormally with RC=4. A Natural member was explicitly entered which does
not exist or does not have SQL access. The static generation can continue.
The temporary assembler program for the precompiler input was written to a temporary dataset (Natural
work file 6).
None of the programs processed by the CMD command accessed an SQL system.
The module name specified with the CMD CREATE command must be the same as the name of the
DBRM specified in the DBRMLIB job card of the precompilation step.
The number of programs to be generated statically into one DBRM exceeds the maximum number of 999.
The maximum number of 1500 NULL indicators per SQL statement has been exceeded.
STAT9031 XREF option "NO" and Predict DDA default "YES" do not match.
The Predict DDA default setting for static SQL XREF is set to "YES" but the XREF option in the CMD
command is set to "NO".
192
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
With the XREF option FORCE, the static generation continues and writes XREF data only if Predict
documentation exists for a given DBRM. If there is no Predict documentation available, static generation
is not performed.
Either the Natural program which is to be statically generated cannot be cataloged with XREF=ON or the
XREF data are not on the used Predict file.
STAT9034 XREF option "YES" or "NO" but Predict DDA default "FORCE".
The Predict DDA default setting for static SQL XREF is set to "FORCE", but the XREF option in the
CMD command is set to "NO" or "YES.
The library for the DBRM entered with the LIB option is not defined as 3GL application in Predict. Check
the library name in Predict which contains the DBRM.
The commands CAT or STOW are not allowed in your security environment. However, the CAT or
STOW privilege is needed for static generation.
No documentation was found in Predict for the DBRM specified with the CMD command. Either the
DBRM is not documented in the used Predict file or a wrong DBRM name has been specified.
STAT9063 XREF interface not linked. XREF option reset, run continues.
The Predict DDA default setting for static SQL XREF is read, because no XREF option is specified in the
CMD command and the XREF interface and Predict are installed.
193
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
194
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
If a second application plan is to be used, this can be specified by executing the Natural program
NATPLAN. NATPLAN is contained in the library SYSDB2 and can be invoked either from within a
Natural program or dynamically by entering the command NATPLAN in the NEXT line. The only input
value required for NATPLAN is an eight-character plan name. If no plan name is specified, you are
prompted by the system to do so.
Before executing NATPLAN, ensure that any open DB2 recovery units are closed.
Since the NATPLAN program is also provided in source form, user-written plan switching programs can
be created using similar logic.
The actual switch from one plan to another differs in the various environments supported. The feature is
available under Com-plete, CICS, and IMS/TM MPP. When using the CAF interface, it is also available
in TSO and batch environments.
In some of these environments, a transaction ID or code must be specified instead of a plan name.
CMTRNSET is documented in the library SYSEXTP, which is invoked with the SYSEXTP system
command. After calling CMTRNSET, you have to perform a terminal I/O to ensure that a new CICS
transaction is used.
Using plan switching by transaction ID enables you to use existing CICS entry threads for your Natural
transactions, where each transaction ID can have its own entry thread assigned.
195
Dynamic and Static SQL Support Natural for DB2 Version 3.1.4 for Mainframes
NDBPLNA writes a CICS temporary storage record containing the plan name that was supplied to
NATPLAN. The name of the temporary storage queue is PLANXXXX, where XXXX is the CICS
terminal identifier.
When running in a CICSplex environment, the CICS temporary storage queue PLANXXXX containing
the plan name must be defined with TYPE=SHARED or TYPE=REMOTE in a CICS TST.
For each new DB2 unit of recovery, the appropriate plan selection exit routine is automatically invoked.
This exit routine reads the temporary storage record and uses the contained plan name for plan selection.
When no temporary storage record exists for the Natural session, a default plan name, contained in the
plan exit, can be used. If no plan name is specified by the exit, the name of the plan used is the same as the
name of the static program (DBRM) issuing the SQL call. If no such plan name exists, an SQL error
results.
Once the DB2 connection has been established, the same plan name continues to be used until the plan is
explicitly changed using the call attachment language interface (DSNALI). For additional information on
the CAF interface, refer to the relevant IBM literature.
Under Com-plete, the NATPLAN program first issues an END TRANSACTION statement and then
invokes an Assembler module named NDBPLAN by using DB2SERV.
NDBPLAN performs the actual switching. It issues a CLOSE request to DSNALI to terminate the DB2
connection (if one exists). It then issues an OPEN request to re-establish the DB2 connection and to
allocate the resources needed to execute the specified plan.
If NATPLAN has not been executed before the first SQL call, the default plan used is the one defined in
the Com-plete start-up parameters. Once a plan has been changed using NDBPLAN, it remains scheduled
until another plan is scheduled by NDBPLAN or until the end of the Natural session.
196
Natural for DB2 Version 3.1.4 for Mainframes Dynamic and Static SQL Support
Since Natural applications can perform direct or deferred message switches by calling the appropriate
supplied routines, use of the NATPLAN program for plan switching is optional.
NATPLAN calls the Assembler routine CMDEFSW, which sets the new transaction code to be used with
the next following terminal I/O.
If no DB2 connection has been made before the first SQL call, a plan name is implicitly selected by DB2.
If so, the plan name used is the same as the name of the program (DBRM) issuing the SQL call.
Once the DB2 connection has been established, the same plan name continues to be used until the plan is
explicitly changed using the call attachment language interface (DSNALI). For additional information on
the CAF interface, refer to the relevant IBM literature.
Under TSO and in batch mode, the NATPLAN program first issues an END TRANSACTION statement
and then invokes an Assembler module named NDBPLAN by using DB2SERV.
Note:
Modify the NATPLAN program by setting the #SSM field to the current DB2 subsystem name; the
default name is DB2.
NDBPLAN performs the actual switching. It issues a CLOSE request to DSNALI to terminate a possible
DB2 connection. It then issues an OPEN request to re-establish the DB2 connection and to allocate the
resources needed to execute the specified plan.
If NATPLAN has not been executed before the first SQL call, plan selection is done implicitly by
DSNALI. If so, the plan name used is the same as the name of the program issuing the SQL call. The
subsystem ID used is the one specified during the DB2 installation. If no such plan name or subsystem ID
exists, a Natural error message is returned.
If a static DBRM is issuing the SQL call, a plan name must exist with the same name as the one of the
static DBRM.
If dynamic SQL is being used, a plan name of NDBIOMO must exist which must contain a DBRM called
NDBIOMO, too. NDBIOMO is the default plan name.
Note:
To avoid any confusion concerning the chosen plan name and/or subsystem ID, always call NATPLAN
before the first SQL call.
197
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
It mainly consists of information also contained in the Natural documentation set where each Natural
statement and variable is described in detail.
BACKOUT TRANSACTION
DELETE
END TRANSACTION
FIND
GET
HISTOGRAM
READ
STORE
UPDATE
198
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
BACKOUT TRANSACTION
This statement undoes all database modifications made since the beginning of the last logical transaction.
Logical transactions can start either after the beginning of a session or after the last SYNCPOINT, END
TRANSACTION, or BACKOUT TRANSACTION statement.
How the statement is translated and which command is actually issued depends on the TP-monitor
environment:
If this command is executed from a stored procedure in a user written Natural program, Natural for
DB2 executes the underlying rollback operation. This sets the caller into a must-rollback state. If this
command is executed from a stored procedure on behalf of the Natural error processing (implicit
ROLLBACK), Natural for DB2 does not execute the underlying rollback operation, thus allowing the
caller to receive the original Natural error.
Under CICS, the BACKOUT TRANSACTION statement is translated into an EXEC CICS
ROLLBACK command. However, in pseudo-conversational mode, only changes made to the
database since the last terminal I/O are undone. This is due to CICS-specific transaction processing.
Note:
Be aware that with terminal input in database loops, Natural switches to conversational mode if no
file server is used.
In batch mode and under TSO, the BACKOUT TRANSACTION statement is translated into an SQL
ROLLBACK command.
Note:
If running in a DSNMTV01 environment the BACKOUT TRANSACTION statement is ignored if
the used PSB has been generated without the CMPAT=YES option.
Under IMS/TM, the BACKOUT TRANSACTION statement is translated into an IMS Rollback
(ROLB) command. However, only changes made to the database since the last terminal I/O are
undone. This is due to IMS/TM-specific transaction processing.
As all cursors are closed when a logical unit of work ends, a BACKOUT TRANSACTION statement
must not be placed within a database loop; instead, it has to be placed outside such a loop or after the
outermost loop of nested loops.
If an external program written in another standard programming language is called from a Natural
program, this external program should not contain its own ROLLBACK command if the Natural program
issues database calls, too. The calling Natural program should issue the BACKOUT TRANSACTION
statement on behalf of the external program.
If a program tries to backout updates which have already been committed, for example by a terminal I/O,
a corresponding Natural error message (NAT3711) is returned.
199
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
DELETE
The DELETE statement is used to delete a row from a DB2 table which has been read with a preceding
FIND, READ, or SELECT statement. It corresponds to the SQL statement DELETE WHERE CURRENT
OF cursor-name, which means that only the row which was read last can be deleted.
Example:
FIND EMPLOYEES WITH NAME = ’SMITH’
AND FIRST_NAME = ’ROGER’
DELETE
Natural would translate the above Natural statements into SQL and assign a cursor name (for example,
CURSOR1) as follows:
DECLARE CURSOR1 CURSOR FOR
SELECT FROM EMPLOYEES
WHERE NAME = ’SMITH’ AND FIRST_NAME = ’ROGER’
DELETE FROM EMPLOYEES
WHERE CURRENT OF CURSOR1
Both the SELECT and the DELETE statement refer to the same cursor.
Natural translates a DML DELETE statement into an SQL DELETE statement in the same way it
translates a FIND statement into an SQL SELECT statement.
A row read with a FIND SORTED BY cannot be deleted due to DB2 restrictions explained with the FIND
statement. A row read with a READ LOGICAL cannot be deleted either.
If a row rolled out to the file server is to be deleted, Natural re-reads automatically the original row from
the database to compare it with its image stored in the file server. If the original row has not been
modified in the meantime, the DELETE operation is performed. With the next terminal I/O, the
transaction is terminated, and the row is deleted from the actual database. If any modification is detected,
however, the row is not deleted, and an error message is returned.
Since a DELETE statement requires that Natural re-reads a single row, a unique index must be available
for the respective table. All columns which comprise the unique index must be part of the corresponding
Natural view.
200
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
END TRANSACTION
This statement indicates the end of a logical transaction and releases all DB2 data locked during the
transaction. All data modifications are committed and made permanent.
How the statement is translated and which command is actually issued depends on the TP-monitor
environment:
If this command is executed from a stored procedure, Natural for DB2 does not execute the
underlying commit operation. This allows the stored procedure to commit updates against non DB2
databases.
Under CICS, the END TRANSACTION statement is translated into an EXEC CICS SYNCPOINT
command. If the file server is used, an implicit end-of-transaction is issued after each terminal I/O.
This is due to CICS-specific transaction processing in pseudo-conversational mode.
In batch mode and under TSO, the END TRANSACTION statement is translated into an SQL
COMMIT WORK command.
Note:
If running in a DSNMTV01 environment the END TRANSACTION statement is ignored if the used
PSB has been generated without the CMPAT=YES option.
Under IMS/TM, the END TRANSACTION statement is not translated into an IMS CHKP call, but is
ignored. Due to IMS/TM-specific transaction processing, an implicit end-of-transaction is issued
after each terminal I/O.
Except when used in combination with the SQL WITH HOLD clause, an END TRANSACTION
statement must not be placed within a database loop, since all cursors are closed when a logical unit of
work ends. Instead, it has to be placed outside such a loop or after the outermost loop of nested loops.
If an external program written in another standard programming language is called from a Natural
program, this external program should not contain its own COMMIT command if the Natural program
issues database calls, too. The calling Natural program should issue the END TRANSACTION statement
on behalf of the external program.
Note:
With DB2, the END TRANSACTION statement cannot be used to store transaction data.
201
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
FIND
The FIND statement corresponds to the SQL SELECT statement.
Example:
Natural statements:
FIND EMPLOYEES WITH NAME = ’BLACKMORE’
AND AGE EQ 20 THRU 40
OBTAIN PERSONNEL_ID NAME AGE
Natural internally translates a FIND statement into an SQL SELECT statement. The SELECT statement is
executed by an OPEN CURSOR command followed by a FETCH command. The FETCH command is
executed repeatedly until either all records have been read or the program flow exits the FIND processing
loop. A CLOSE CURSOR command ends the SELECT processing.
The WITH clause of a FIND statement is converted to the WHERE clause of the SELECT statement. The
basic search criterion for a DB2 table can be specified in the same way as for an Adabas file. This implies
that only database fields which are defined as descriptors can be used to construct basic search criteria and
that descriptors cannot be compared with other fields of the Natural view (that is, database fields) but only
with program variables or constants.
Note:
As each database field (column) of a DB2 table can be used for searching, any database field can be
defined as a descriptor in a Natural DDM.
The WHERE clause of the FIND statement is evaluated by Natural after the rows have been selected via
the WITH clause. Within the WHERE clause, non-descriptors can be used and database fields can be
compared with other database fields.
Note:
DB2 does not have sub-, super-, or phonetic descriptors.
A FIND NUMBER statement is translated into a SELECT statement containing a COUNT(*) clause. The
number of rows found is returned in the Natural system variable *NUMBER.
The FIND UNIQUE statement can be used to ensure that only one record is selected for processing. If the
FIND UNIQUE statement is referenced by an UPDATE statement, a non-cursor ("searched") UPDATE
operation is generated instead of a cursor-oriented (positioned) UPDATE operation. Therefore, it can be
used if you want to update a DB2 primary key. It is, however, recommended to use Natural SQL
("searched" UPDATE statement) to update a primary key.
In static mode, the FIND NUMBER and FIND UNIQUE statements are translated into a SELECT
SINGLE statement.
202
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
The FIND FIRST statement cannot be used. The PASSWORD, CIPHER, COUPLED and RETAIN
clauses cannot be used either.
The SORTED BY clause of a FIND statement is translated into the SQL SELECT ... ORDER BY clause,
which follows the search criterion. Because this produces a read-only result table, a row read with a FIND
statement that contains a SORTED BY clause cannot be updated or deleted.
A limit on the depth of nested database loops can be specified at installation time. If this limit is exceeded,
a Natural error message is returned.
As far as the file server is concerned, there are no programming restrictions with selection statements. It
is, however, recommended to make yourself familiar with its functionality considering performance and
file server space requirements.
GET
This statement is ISN-based and therefore cannot be used with DB2 tables.
HISTOGRAM
The HISTOGRAM statement returns the number of rows in a table which have the same value in a
specific column. The number of rows is returned in the Natural system variable *NUMBER.
Example:
Natural statements:
HISTOGRAM EMPLOYEES FOR AGE
OBTAIN AGE
Natural translates the HISTOGRAM statement into an SQL SELECT statement, which means that the
control flow is similar to the flow explained for the FIND statement.
203
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
READ
The READ statement can also be used to access DB2 tables. Natural translates a READ statement into an
SQL SELECT statement.
READ PHYSICAL and READ LOGICAL can be used; READ BY ISN, however, cannot be used, as
there is no DB2 equivalent to Adabas ISNs. The PASSWORD and CIPHER clauses cannot be used either.
Since a READ LOGICAL statement is translated into a SELECT ... ORDER BY statement - which
produces a read-only table -, a row read with a READ LOGICAL statement cannot be updated or deleted
(see Example 1). The start value can only be a constant or program variable; any other field of the Natural
view (that is, any database field) cannot be used.
A READ PHYSICAL statement is translated into a SELECT statement without an ORDER BY clause and
can therefore be updated or deleted (see Example 2).
Example 1:
Natural statements:
READ PERSONNEL BY NAME
OBTAIN NAME FIRSTNAME DATEOFBIRTH
Example 2:
Natural statements:
READ PERSONNEL PHYSICAL
OBTAIN NAME
If the READ statement contains a WHERE clause, this clause is evaluated by the Natural processor after
the rows have been selected according to the descriptor value(s) specified in the search criterion.
As far as the file server is concerned there are no programming restrictions with selection statements. It is,
however, recommended to make yourself familiar with its functionality considering performance and file
server space requirements.
204
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
STORE
The STORE statement is used to add a row to a DB2 table. The STORE statement corresponds to the SQL
statement INSERT.
Example:
Natural statement:
STORE RECORD IN EMPLOYEES
WITH PERSONNEL_ID = ’2112’
NAME = ’LIFESON’
FIRST_NAME = ’ALEX’
UPDATE
The Natural DML UPDATE statement updates a row in a DB2 table which has been read with a preceding
FIND, READ, or SELECT statement. It corresponds to the SQL statement UPDATE WHERE CURRENT
OF cursor-name (positioned UPDATE), which means that only the row which was read last can be
updated.
If a row rolled out to the file server is to be updated, Natural automatically re-reads the original row from
the database to compare it with its image stored in the file server. If the original row has not been
modified in the meantime, the UPDATE operation is performed. With the next terminal I/O, the
transaction is terminated and the row is definitely updated on the database. If any modification is detected,
however, the row is not updated and an error message is returned.
Since an UPDATE statement requires re-reading a single row by Natural, a unique index must be
available for this table. All columns which comprise the unique index must be part of the corresponding
Natural view.
205
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
As explained with the FIND statement, Natural translates a FIND statement into an SQL SELECT
statement. When a Natural program contains a DML UPDATE statement, this statement is translated into
an SQL UPDATE statement and a FOR UPDATE OF clause is added to the SELECT statement.
Example:
FIND EMPLOYEES WITH SALARY < 5000
ASSIGN SALARY = 6000
UPDATE
Natural would translate the above Natural statements into SQL and assign a cursor name (for example,
CURSOR1) as follows:
DECLARE CURSOR1 CURSOR FOR
SELECT SALARY FROM EMPLOYEES WHERE SALARY < 5000
FOR UPDATE OF SALARY
UPDATE EMPLOYEES SET SALARY = 6000
WHERE CURRENT OF CURSOR1
Both the SELECT and the UPDATE statement refer to the same cursor.
Due to DB2 logic, a column (field) can only be updated if it is contained in the FOR UPDATE OF clause;
otherwise updating this column (field) is rejected. Natural includes automatically all columns (fields) into
the FOR UPDATE OF clause which have been modified anywhere in the Natural program or which are
input fields as part of a Natural map.
However, a DB2 column is not updated if the column (field) is marked as "not updateable" in the Natural
DDM. Such columns (fields) are removed from the FOR UPDATE OF list without any warning or error
message. The columns (fields) contained in the FOR UPDATE OF list can be checked with the LISTSQL
command.
The Adabas short name in the Natural DDM determines whether a column (field) can be updated.
206
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
Be aware that a primary key field is never part of a FOR UPDATE OF list. A primary key field can only
be updated by using a non-cursor UPDATE operation (see also the section UPDATE).
A row read with a FIND statement that contains a SORTED BY clause cannot be updated (due to DB2
limitations as explained with the FIND statement). A row read with a READ LOGICAL cannot be
updated either (as explained with the READ statement).
The data locked by an UPDATE statement are released when an END TRANSACTION (COMMIT
WORK) or BACKOUT TRANSACTION (ROLLBACK WORK) statement is executed by the program.
Note:
If a length indicator field or null indicator field is updated in a Natural program without updating the field
(column) it refers to, the update of the column is not generated for DB2 and thus no updating takes place.
207
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
In general, the DML UPDATE statement can be used in both structured and reporting mode. However,
after a SELECT statement, only the syntax defined for Natural structured mode is allowed:
This is due to the fact that in combination with the SELECT statement, the DML UPDATE statement is
only allowed in the special case of:
...
SELECT ...
INTO VIEW view-name
...
Thus, only a whole Natural view can be updated; individual columns (fields) cannot.
Example:
DEFINE DATA LOCAL
01 PERS VIEW OF SQL-PERSONNEL
02 NAME
02 AGE
END-DEFINE
SELECT *
INTO VIEW PERS
FROM SQL-PERSONNEL
WHERE NAME LIKE ’S%’
IF NAME = ’SMITH’
ADD 1 TO AGE
UPDATE
END-IF
END-SELECT
...
In combination with the DML UPDATE statement, any other form of the SELECT statement is rejected
and an error message is returned.
In all other respects, the DML UPDATE statement can be used with the SELECT statement in the same
way as with the Natural FIND statement described earlier in this section and in the Natural Statements
documentation.
208
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
atom
An atom can be either a parameter (that is, a Natural program variable or host variable) or a constant.
When running dynamically, however, the use of host variables is restricted by DB2. For further details,
refer to the relevant literature on DB2.
comparison
The following three comparison operators are specific to DB2 and belong to the Natural Extended Set.
¬=
¬>
¬<
209
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
factor
The following three factors are specific to DB2 and belong to the Natural Extended Set:
special-register
scalar-function (scalar-expression, ...)
scalar-expression unit
case-expression
scalar-function
A scalar-function is a built-in function that can be used in the construction of scalar computational
expressions. Scalar functions are specific to DB2 and belong to the Natural Extended Set.
CHAR
COALECE
DATE
DAY
DAYS
DECIMAL
DIGITS
FLOAT
HEX
HOUR
INTEGER
LENGTH
MICROSECOND
MINUTE
MONTH
NULLIF
SECOND
STRIP
SUBSTR
TIME
TIMESTAMP
VALUE
VARGRAPHIC
YEAR
210
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
Each scalar function is followed by one or more scalar expressions in parentheses. The number of scalar
expressions depends upon the scalar function. Multiple scalar expressions must be separated from one
another by commas.
Example:
SELECT NAME
INTO NAME
FROM SQL-PERSONNEL
WHERE SUBSTR ( NAME, 1, 3 ) = ’Fri’
...
scalar-operator
The concatenation operator (CONCAT or "||") does not conform to standard SQL. It is specific to DB2
and belongs to the Natural Extended Set.
special-register
The following special registers do not conform to standard SQL. They are specific to DB2 and belong to
the Natural Extended Set:
CURRENT TIMEZONE
CURRENT DATE
CURRENT TIME
CURRENT_TIMEZONE
CURRENT_DATE
CURRENT_TIME
CURRENT TIMESTAMP
CURRENT SQLID
CURRENT PACKAGESET
CURRENT SERVER
CURRENT DEGREE
CURRENT RULES
Using the command SET CURRENT SQLID, the creator name of a table can be substituted by the current
SQLID. This enables you to access identical tables with the same table name but with different creator
names.
211
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
units
Units, also called "durations", are specific to DB2 and belong to the Natural Extended Set.
YEAR
YEARS
MONTH
MONTHS
DAY
DAYS
HOUR
HOURS
MINUTE
MINUTES
SECOND
SECONDS
MICROSECOND
MICROSECONDS
case-expression
Case-expressions do not conform to standard SQL and are therefore supported by the Natural SQL
Extended Set only.
Example:
DEFINE DATA LOCAL
01 #EMP
02 #EMPNO (A10)
02 #FIRSTNME (A15)
02 #MIDINIT (A5)
02 #LASTNAME (A15)
02 #EDLEVEL (A13)
02 #INCOME (P7)
END-DEFINE
SELECT EMPNO, FIRSTNME, MIDINIT, LASTNAME,
(CASE WHEN EDLEVEL < 15 THEN ’SECONDARY’
WHEN EDLEVEL < 19 THEN ’COLLEGE’
ELSE ’POST GRADUATE’
END ) AS EDUACATION, SALARY + COMM AS INCOME
INTO
#EMPNO, #FIRSTNME, #MIDINIT, #LASTNAME,
#EDLEVEL, #INCOME
FROM DSN8510-EMP
WHERE (CASE WHEN SALARY = 0 THEN NULL
ELSE SALARY / COMM
END ) > 0.25
DISPLAY #EMP
END-SELECT
END
212
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
CALLDBPROC
The CALLDBPROC statement allows you to call DB2 stored procedures. It supports the result set
mechanism of DB2 Version 5 and it enables you to call DB2 stored procedures written in Natural.
For a detailed description of the syntax of the statement, see the Natural Statements documentation.
If the CALLDBPROC statement is executed dynamically, all parameters and constants are mapped to the
variables of the following DB2 SQL statement:
CALL :hv USING DESCRIPTOR :sqlda statement
:hv denotes a host variable containing the name of the procedure to be called and :sqlda is a dynamically
generated sqlda describing the parameters to be passed to the stored procedure.
If the CALLDBPROC statement is executed statically, the constants of the CALLDBPROC statement are
also generated as constants in the generated assembler SQL source for the DB2 precompiler.
If the SQLCODE created by the CALL statement indicates that there are result sets (SQLCODE +466 and
+464), Natural for DB2 runtime executes a
DESCRIBE PROCEDURE :hv INTO :sqlda
statement in order to retrieve the result set locator values of the result sets created by the invoked stored
procedure. These values are put into the RESULT SETS variables specified in the CALLDBPROC
statement. Each RESULT SETS variable specified in a CALLDBPROC for which no result set locator
value is present is reset to zero. The result set locator values can be used to read the result sets by means
of the READ RESULT SET statement as long as the database transaction which created the result set has
not yet issued a COMMIT or ROLLBACK.
If the result set was created by a cursor WITH HOLD, the result set locator value remains valid after a
COMMIT operation.
Unlike other Natural SQL statements, CALLDBPROC enables you (optionally!) to specify a SQLCODE
variable following the GIVING keyword which will contain the SQLCODE of the underlying CALL
statement. If GIVING is specified, it is up to the Natural program to react on the SQLCODE (error
message NAT3700 is not issued by the runtime).
213
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
CALLMODE=NATURAL
This parameter allows DB2 stored procedures written in Natural to be invoked Stored procedures written
in Natural are Natural subprograms which execute in the stored procedure address space.
From the viewpoint of the caller, i.e. the Natural program, and from the viewpoint of the stored procedure,
i.e. Natural subprogram, this additional parameter is invisible. It is passed as first parameter by the Natural
for DB2 runtime and it is used as on the server side to build the copy of the passed data in the Natural
thread and the corresponding CALLNAT statement. Additionally, this parameter serves as a container for
error information created during execution of the Natural stored procedure by the Natural runtime. It also
contains information on the library where you are logged on and the Natural subprogram to be invoked.
214
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
The following table describes the first parameter passed between the caller and the stored procedure if
CALLMODE = NATURAL is specified.
215
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
The FORMAT_DESCRIPTION contains a description for each parameter passed to the stored procedure
consisting of parameter type, format specification and length. Parameter type is the AD attribute of the
CALLNAT statement as described in the Natural Statements documentation.
Each parameter has the following format description element in the FORMAT_DESC string
atl,p[,d1]....
where
O non-modifiable AD=O IN
A Alphanumeric
N Numeric unpacked
P Packed numeric
I Integer
F Floating point
B Binary
D Date (unsupported)
T Time (unsupported)
L Logical (unsupported)
This descriptive/control parameter is invisible to the calling Natural program and to the called Natural
stored procedure, but it has to be defined in the parameter definition of the stored procedure row in the
SYSIBM.SYSPROCEDURES table for the stored procedure.
216
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
The following table shows the number of parameters which have to be defined in the
SYSIBM.SYSPROCEDURES table depending on the number of user parameters and whether the client
(i.e. the caller of a stored procedure for DB2 for OS/390) and the server (i.e. the stored procedure for DB2
for OS/390) is written in Natural or in a different host language. n denotes the number of ’user’
parameters.
n+1 (CALLMODE=NATURAL)
not Natural n+1 N
217
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
218
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
COMMIT
The SQL COMMIT statement indicates the end of a logical transaction and releases all DB2 data locked
during the transaction. All data modifications are made permanent.
If this command is executed from a stored procedure, Natural for DB2 does not execute the underlying
commit operation. This allows the stored procedure to commit updates against non DB2 databases.
Under CICS, the COMMIT statement is translated into an EXEC CICS SYNCPOINT command. If the
file server is used, an implicit end-of-transaction is issued after each terminal I/O. This is due to
CICS-specific transaction processing in pseudo-conversational mode.
Under IMS/TM, the COMMIT statement is not translated into an IMS Checkpoint command, but is
ignored. An implicit end-of-transaction is issued after each terminal I/O. This is due to IMS/TM-specific
transaction processing.
Unless when used in combination with the WITH HOLD clause, a COMMIT statement must not be
placed within a database loop, since all cursors are closed when a logical unit of work ends. Instead, it has
to be placed outside such a loop or after the outermost loop of nested loops.
If an external program written in another standard programming language is called from a Natural
program, this external program should not contain its own COMMIT command if the Natural program
issues database calls, too. The calling Natural program should issue the COMMIT statement on behalf of
the external program.
DELETE
Both the "cursor-oriented" or "positioned" and the "non-cursor" or ""searched"" SQL DELETE statement
are supported as part of Natural SQL; the functionality of the "positioned" DELETE statement
corresponds to that of the Natural DML DELETE statement.
With DB2, a table name in the FROM clause of a "searched" DELETE statement can be assigned a
correlation-name. This does not correspond to the standard SQL syntax definition and therefore belongs
to the Natural Extended Set.
The "searched" DELETE statement must be used, for example, to delete a row from a self-referencing
table, since with self-referencing tables a positioned DELETE is not allowed by DB2.
INSERT
The INSERT statement is used to add one or more new rows to a table.
Since the INSERT statement can contain a select expression, all the DB2-specific syntactical items
described above apply.
219
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
PROCESS SQL
The PROCESS SQL statement is used to issue SQL statements to the underlying database. The statements
are specified in a statement-string, which can also include constants and parameters.
The set of statements which can be issued is also referred to as Flexible SQL and comprises those
statements which can be issued with the SQL statement "EXECUTE".
In addition, Flexible SQL includes the DB2-specific statements CONNECT, SET CURRENT
PACKAGESET, SET CURRENT DEGREE, SET CURRENT RULES, SET CURRENT SQLID, SET
host-variable= special-register RELEASE, SET CONNECTION, and CALL.
Note:
To avoid transaction synchronization problems between the Natural environment and DB2, the COMMIT
and ROLLBACK statements must not be used within PROCESS SQL.
CALL
Natural for DB2 now supports the DB2 Version 4 CALL statement by means of the PROCESS SQL
statement. However, the syntax of the CALL statement is restricted as shown below.
[:U:] host-variable
procedure-name
CALL { host-variable }[ { ( constant },... ) ]
NULL
The using descriptor parameter list format of the CALL statement is not supported.
Every host variable specified in the CALL parameter list should be prefixed with :U or the prefix should
be omitted, regardless how the parameters are defined in the SYSIBM.SYSPROCEDURES tables. To use
:G as host-variable prefix is strictly forbidden.
Example:
PROCESS SQL DB2-DDM
<<CALL DB2PROC
(:U:#USER,
:U:#DATE,
’ALPHA’,
NULL
)
>>
’ALPHA’ is a literal.
220
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
Whether data are returned by the called procedure is only determined by the definition of call parameter
list in the SYSIBM.SYSPROCEDURE table for the called procedure.
ROLLBACK
The SQL ROLLBACK statement undoes all database modifications made since the beginning of the last
logical transaction. Logical transactions can start either after the beginning of a session or after the last
COMMIT/END TRANSACTION or ROLLBACK/BACKOUT TRANSACTION statement. All records
held during the transaction are released.
If this command is executed from a stored procedure in a user written Natural program, Natural for DB2
executes the underlying rollback operation. This sets the caller into a must-rollback state. If this command
is executed from a stored procedure on behalf of the Natural error processing (implicit ROLLBACK),
Natural for DB2 does not execute the underlying rollback operation, thus allowing the caller to receive the
original Natural error.
Under CICS, the ROLLBACK statement is translated into an EXEC CICS ROLLBACK command.
However, if the file server is used, only changes made to the database since the last terminal I/O are
undone. This is due to CICS-specific transaction processing in pseudo-conversational mode.
Under IMS/TM, the ROLLBACK statement is translated into an IMS Rollback (ROLB) command.
However, only changes made to the database since the last terminal I/O are undone. This is due to
IMS/TM-specific transaction processing.
As all cursors are closed when a logical unit of work ends, a ROLLBACK statement must not be placed
within a database loop; instead, it has to be placed outside such a loop or after the outermost loop of
nested loops.
If an external program written in another standard programming language is called from a Natural
program, this external program should not contain its own ROLLBACK command if the Natural program
issues database calls, too. The calling Natural program should issue the ROLLBACK statement on behalf
of the external program.
221
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
SELECT
Cursor-Oriented Selection
Like the Natural FIND statement, the cursor-oriented SELECT statement is used to select a set of rows
(records) from one or more DB2 tables, based on a search criterion. Since a database loop is initiated, the
loop must be closed by a LOOP (reporting mode) or END-SELECT statement. With this construction,
Natural uses the same loop processing as with the FIND statement.
In addition, no cursor management is required from the application program; it is automatically handled
by Natural.
The OPTIMIZE FOR integer ROWS clause is used to inform DB2 in advance of the number (integer) of
rows to be retrieved from the result table. Without this clause, DB2 assumes that all rows of the result
table are to be retrieved and optimizes accordingly.
This optional clause is useful if you know how many rows are likely to be selected, because optimizing
for integer rows can improve performance if the number of actually selected rows does not exceed the
integer value (which can be in the range from 0 to 2147483647).
Example:
SELECT name INTO #name FROM table
WHERE AGE = 2 OPTIMIZE FOR 100 ROWS
WITH Clauses
Isolation Level
[ WITH { CS | RR | UR } ]
This option allows you to specify an explicit isolation level with which the statement is to be executed.
WITH UR can only be specified within a SELECT statement and when the table is read-only. The default
isolation level is determined by the isolation of the package or plan into which the statement is bound. The
default isolation level also depends on whether the result table is read-only or not. To find out the default
isolation level, refer to the IBM documentation.
Note:
This option also works for non-cursor selection.
222
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
[ WITH HOLD ]
The WITH HOLD clause is used to prevent cursors from being closed by a commit operation within
database loops. If WITH HOLD is specified, a commit operation commits all the modifications of the
current logical unit of work, but releases only locks that are not required to maintain the cursor. This
optional clause is mainly useful in batch mode; it is ignored in CICS pseudo-conversational mode and in
IMS message-driven programs.
Example:
SELECT name INTO #name FROM table
WHERE AGE = 2 WITH HOLD
WITH RETURN
[ WITH RETURN ]
The WITH RETURN clause is used to create result sets. Therefore it should only be used in programs
which operate as stored procedure. If the WITH RETURN clause is specified in a SELECT statement, the
underlying cursor remains open when the associated processing loop is left, except when the processing
loop had read all rows of the result set itself. During first execution of the processing loop, only the cursor
is opened. The first row is not yet fetched. This allows the Natural program to return a full result set to the
caller of the stored procedure. It is up to the Natural program to decide how many rows are processed by
the program itself and how many unprocessed rows are returned to the caller of the stored procedure. If it
wants to process rows of the select operation itself, it should code
IF *counter =1 ESCAPE TOP END-IF
in order to avoid processing of the first "empty row" in the processing loop. If it decides by some criteria
of its own to terminate its own processing of rows, it should code
If criterium ESCAPE BOTTOM END-IF
If the program reads all rows of the result set, the cursor is closed and no result set is returned for this
SELECT WITH RETURN to the caller of the stored procedure.
223
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
The following programs are examples for retrieving full result sets (Example 1) and partial result sets
(Example 2).
Example 1:
DEFINE DATA LOCAL
. . .
END DEFINE
*
* Return all rows of the result set
*
SELECT * INTO VIEW V2
FROM SYSIBM-SYSPROCEDURES
WHERE RESULT_SETS > 0
WITH RETURN
ESCAPE BOTTOM
END-SELECT
END
Example 2:
DEFINE DATA LOCAL
. . .
END DEFINE
*
* Read the first two rows and return the rest as result set
*
SELECT * INTO VIEW V2
FROM SYSIBM-SYSPROCEDURES
WHERE RESULT_SETS > 0
WITH RETURN
WRITE PROCEDURE *COUNTER
IF *COUNTER = 1 ESCAPE TOP END-IF
IF *COUNTER =3 ESCAPE BOTTOM END-IF
END-SELECT
END
The Natural statement SELECT SINGLE provides the functionality of a non-cursor selection (singleton
SELECT); that is, a select expression that retrieves at most one row without using a cursor.
Since DB2 supports the singleton SELECT command in static SQL only, in dynamic mode, the Natural
SELECT SINGLE statement is executed like a set-level SELECT statement, which results in a cursor
operation. However, Natural checks the number of rows returned by DB2. If more than one row is
selected, a corresponding error message is returned.
224
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
UPDATE
Both the "cursor-oriented" or "positioned" and the "non-cursor" or ""searched"" SQL UPDATE statement
are supported as part of Natural SQL. Both of them reference either a table or a Natural view.
With DB2, the name of a table or Natural view to be referenced by a "searched" UPDATE can be assigned
a correlation-name. This does not correspond to the standard SQL syntax definition and therefore belongs
to the Natural Extended Set.
The "searched" UPDATE statement must be used, for example, to update a primary key field, since DB2
does not allow updating of columns of a primary key by using a positioned UPDATE statement.
Note:
If you use the SET * notation, all fields of the referenced Natural view are added to the FOR UPDATE
OF and SET lists. Therefore, ensure that your view contains only fields which can be updated; otherwise,
a negative SQLCODE is returned by DB2.
225
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
*ISN
*NUMBER
*ISN
As there is no DB2 equivalent of Adabas ISNs, the system variable *ISN is not applicable to DB2 tables.
*NUMBER
When used with a FIND NUMBER or HISTOGRAM statement, *NUMBER contains the number of rows
actually found.
When applied to data from a DB2 table in any other case, the system variable *NUMBER only indicates
whether any rows have been found. If no rows have been found, *NUMBER is "0". Any value other than
"0" indicates that at least one row has been found; however, the value contained in *NUMBER has no
relation to the number of rows actually found.
The reason is that if *NUMBER were to produce a valid number, Natural would have to translate the
corresponding FIND statement into an SQL SELECT statement including the special function
COUNT(*); however, a SELECT containing a COUNT function would produce a read-only result table,
which would not be available for updating. In other words, the option to update selected data was given
priority in Natural over obtaining the number of rows that meet the search criteria.
To obtain the number of rows affected by the Natural SQL statements ""searched" UPDATE",
""searched" DELETE" and INSERT, the Natural subprogram NDBNROW is provided. Alternatively, you
can use the Natural system variable *ROWCOUNT as described in the Natural Reference documentation.
226
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
Error Handling
In contrast to the normal Natural error handling, where either an ON ERROR statement is used to
intercept execution time errors or standard error message processing is performed and program execution
is terminated, the enhanced error handling of Natural for DB2 provides an application controlled reaction
to the encountered SQL error.
Two Natural subprograms, NDBERR and NDBNOERR, are provided to disable the usual Natural error
handling and to check the encountered SQL error for the returned SQL code. This functionality replaces
the "E" function of the DB2SERV interface, which is still provided but no longer documented.
For further information on Natural subprograms provided for DB2, see the section Natural Subprograms.
Example:
DEFINE DATA LOCAL
01 #SQLCODE (I4)
01 #SQLSTATE (A5)
01 #SQLCA (A136)
01 #DBMS (B1)
END-DEFINE
*
* Ignore error from next statement
*
CALLNAT ’NDBNOERR’
*
* This SQL statement produces an SQL error
*
INSERT INTO SYSIBH-SYSTABLES (CREATOR, NAME, COLCOUNT)
VALUES (’SAG’, ’MYTABLE’, ’3’)
*
* Investigate error
*
CALLNAT ’NDBERR’ #SQLCODE #SQLSTATE #SQLCA #DBMS
*
IF #DBMS NE 2 /* not DB2
MOVE 3700 TO *ERROR-NR
END-IF
*
DECIDE ON FIRST VALUE OF #SQLCODE
VALUE 0, 100 /* successful execution
IGNORE
VALUE -803 /* duplicate row
/* UPDATE existing record
/*
IGNORE
NONE VALUE
MOVE 3700 TO *ERROR-NR
END-DECIDE
*
END
227
Statements and System Variables Natural for DB2 Version 3.1.4 for Mainframes
1. Determine the format and attributes of the parameters which are passed between the caller and the
stored procedure.
Consider creating a Natural parameter data area.
stored procedures do not support data groups and redefinitions within their parameters.
2. Decide the linkage of the stored procedure (simple or simple with NULL).
If you have decided to use simple with NULL linkage, you have to append the parameter data area
within the Natural stored procedure by the NULL indicator area, which contains a NULL indicator
(I2) for each other parameter. See also the DB2 literature by IBM.
3. Decide which and how many result sets the stored procedure will return to the caller.
4. Code your stored procedure as a Natural subprogram.
Returning result sets
To return result sets code a SELECT statement with the WITH RETURN option.
To return the whole result set code an ESCAPE BOTTOM immediately after the SELECT.
To return part of the result set code an IF *COUNTER = 1 ESCAPE TOP END-IF immediately
following the SELECT statement. This ensures that you do not process the first empty row that
is returned by the SELECT WITH RETURN statement. To stop row processing execute an
ESCAPE BOTTOM statement.
If you do not leave the processing loop initiated by the SELECT WITH RETURN via ESCAPE
BOTTOM, the result set created is closed and nothing is returned to the caller.
Attention when accessing other databases
You can access other databases (for instance Adabas) within a DB2 stored procedure written in
Natural. But you should keep in mind that your access to other databases is neither synchronized
with the updates done by the caller of the stored procedure, nor with the updates done against
DB2 within the stored procedure.
NDB handling of COMMIT and ROLLBACK statements
DB2 does not allow a stored procedure to issue COMMIT or ROLLBACK statements (the
execution of those statements puts the caller into a must-rollback state). Therefore, the NDB
runtime handles those statements as follows when they are issued from a Stored Procedure:
COMMIT against DB2 will be skipped.
This allows the stored procedure to commit Adabas updates without getting a must-rollback
state from DB2.
ROLLBACK against DB2 will be skipped if it is created by Natural itself.
ROLLBACK against DB2 will be executed if it is user-programmed.
Thus, after a Natural error, the caller receives the Natural error information and not the
unqualified must-rollback state. Additionally, this function ensures that, if the user program
backs out the transaction, every database transaction of the stored procedure is backed out.
5. Enter a row describing your stored procedure into the SYSIBM.SYSPROCEDURES table.
This can be done by SYSDB2 Procedure Maintenance. In order to define a stored procedure written
in Natural, the following data has to be entered:
228
Natural for DB2 Version 3.1.4 for Mainframes Statements and System Variables
Column Data
PROCEDURE The name of your Natural subprogram representing your stored procedure.
LOADMOD The name of your Natural for DB2 server stub module.
LINKAGE Either blank or N as you decided at 2.
IBMREQD N
PGM_TYPE Depending on the specification of the MAIN parameter of the Natural for DB2
server stub module.
RESULT_SETS As you decided at 3.
LANGUAGE ASSEMBLER
PARMLIST The description of the parameters you determined at 1.
The first field of the PARMLIST must be defined as Natural internal parameter
description STCB. It must be specified as a VARCHAR field with DATA INOUT
and the following size:
247 + 13*N
where N is the number of parameters passed to the stored procedured (STCB not
counted).
If you have created a Natural parameter data area for the stored procedure, you
can easily derive the PARMLIST from your PDA by pressing PF5 on your
PARMLIST screen of SYSDB2 and entering the library and the name of the
PDA. In this case, the VARCHAR field for the parameter description is generated
automatically.
6. Code your Natural program invoking the stored procedure via the CALLDBPROC statement.
Code the parameters in the CALLDBPROC statement in the same sequence as they are specified in
the stored procedure. Define the parameters in the calling program in a format that is compatible with
the format defined in the stored procedure.
If you use result sets, specify a RESULT SETS clause in the CALLDBPROC statement followed by
a number of result set locator variables of FORMAT (I4). The number of result set locator variables
should be the same as the number or result sets created by the stored procedure. If you specify less
than are created, some result sets are lost. If you specify more than are created, the remaining result
set locator variables are lost. The sequence of locator variables corresponds to the sequence in which
the result sets are created by the stored procedure.
Keep in mind that the fields into which the result set rows are read have to correspond to the fields
used in the Select WITH RETURN statement, which created the result set.
Security
A Natural stored procedure is executed with the authorization of the user ID provided by DB2, i.e., the
user authorization of the address space the stored procedure is running in, or with the authorization of the
caller of the procedure if External Security is set to Yes.
229
Statement Logging Natural for DB2 Version 3.1.4 for Mainframes
Statement Logging
The Natural Database Log utility DBLOG allows you to ascertain which SQL statements are issued by a
Natural program.
Invoking DBLOG
The DBLOG Menu for DB2
The Trace Function
The Snapshot Function
Invoking DBLOG
The Natural DBLOG utility is used to log SQL statements issued to DB2.
Parameter Explanation
Q Starts logging of SQL statements.
ON Starts the trace function for non-selective logging.
OFF Terminates logging.
SHOW Terminates logging and displays the current log.
CONT Continues logging if a log already exists and displays the current log.
MENU / ? / * Selective logging of SQL statements. The DBLOG menu is displayed for selection. Any
existing log is deleted.
The statements are logged in the Natural debug buffer, which has to be specified via the DSIZE profile
parameter, as described in the Natural Operations for Mainframes documentation.
230
Natural for DB2 Version 3.1.4 for Mainframes Statement Logging
If the Natural debug buffer is too small to contain all statements to be logged, only the most recent
statements are held in the debug buffer.
If you enter the TEST DBLOG Q command without any parameters, logging of SQL statements is
activated, or - if it has already been activated - the current log is displayed.
Code Function
---- ------------------------------------
B Begin Logging of SQL Statements
E End and Display Log Records
S Snapshot of Specific SQL Statement
. Exit
---- ------------------------------------
Code .. _
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Print Exit Begin End Snap Canc
On the DBLOG Menu for DB2, you can specify which SQL statements are to be logged. Each statement
is logged after it has been processed by DB2.
Code Explanation
B Corresponds to the command TEST DBLOG Q ON, which means that the trace function for
selective logging is started and all SQL statements matching the selection criteria are logged.
E Corresponds to the commands TEST DBLOG Q OFF/SHOW, which means that logging of SQL
statements is stopped and the resulting log records are displayed.
S Is used to log and display a specific SQL statement only.
231
Statement Logging Natural for DB2 Version 3.1.4 for Mainframes
Parameter Explanation
Statement Only statements with the specified statement code are to be logged (for example SELECT).
Skip Number of statements to be skipped before logging is to start (only applicable with
function code "S").
Program Only statements issued by the specified program are to be logged.
Line from/ Only statements within the range of the specified line numbers are to be logged.
Line to
Low SQLC/ Only statements which result in an SQL return code within the specified range are to be
High SQLC logged.
232
Natural for DB2 Version 3.1.4 for Mainframes Statement Logging
Enter function code "B" and corresponding selection criteria on the DBLOG Menu, or enter the
TEST DBLOG Q command without parameters or with parameter "ON".
The trace function is active until you enter the TEST DBLOG Q command again (or TEST DBLOG
Q OFF respectively), or enter function code "E" on the DBLOG Menu.
Once you have entered function code "E" (or the command TEST DBLOG Q SHOW), the DBLOG
Trace screen is displayed as shown in the following example.
1.
Write the following program:
DEFINE DATA
LOCAL USING SQL-AUTO
LOCAL USING SQL-EMPL
END-DEFINE
FIND (1) SQL-AUTO WITH OWNER > ’ID----01’
FIND (1) SQL-EMPL WITH PERS_ID = OWNER(0050)
MOVE ’NAME333333333333347’ TO NAME
UPDATE
END-FIND
MOVE ’MAKE333333334’ TO MAKE
UPDATE
END-FIND
END TRANSACTION
FIND (1) SQL-AUTO WITH MAKE = ’MAKE333333334’
FIND (1) SQL-EMPL WITH PERS_ID = OWNER(0140)
DISPLAY PERS_ID NAME MAKE
END-FIND
END-FIND
END
233
Statement Logging Natural for DB2 Version 3.1.4 for Mainframes
234
Natural for DB2 Version 3.1.4 for Mainframes Statement Logging
On the DBLOG Trace screen for DB2, the following information is displayed:
Item Explanation
M Executes the commands EXPLAIN (function code "E") or LISTSQL (function code
"L") for the corresponding SQL statement, which is identified by the library name,
program name, and line number taken fromthe debug buffer.
Important:
Since both commands obtain their information from the Natural system file, unwanted
results may occur if the corresponding Natural program has been recataloged after the
trace was performed.
See the commands LISTSQL and EXPLAIN.
No Sequence number; the statements are displayed in the sequence in which they were
executed.
R Indicates by an asterisk in front of the corresponding statement that a reselection has
been performed; if not, the column is left blank; see also the Concept of the File Server.
SQL Statement The first 29 characters of the logged SQL statement.
CU Cursor number.
SN Internal statement number.
SREF Statement reference number.
M Mode ("D" for dynamic or "S" for static).
Typ Database type (in this case: DB2).
SQLC/W Either the SQL return code in the SQLCODE field of the SQLCA, or the warning in the
SQLWARN0 field of the SQLCA if SQLCODE is 0.
Pgm Natural program name.
Line Source code line number.
LV Program level.
235
Statement Logging Natural for DB2 Version 3.1.4 for Mainframes
A snapshot does not interrupt the program flow. The snapped data are displayed only if logging is
terminated by the user.
In contrast to the statements displayed with the Trace function, the snapshot statement is shown in its
entirety (limited to 13 lines).
Once you have entered function code "E" on the DBLOG menu (or the command TEST DBLOG Q
SHOW in the Natural NEXT line), the Snapshot Report screen is displayed as shown in the following
example:
SQL Statement
SELECT MAKE,MODEL,BODY_TYPE,HORSEPOWER,COLOR,SERIAL_NO,OWNER FROM SAG.AUTOMOBIL
ES WHERE OWNER > ’ID----01’ FOR UPDATE OF MAKE
Command ===>
Enter-PF1---PF2---PF3---PF4---PF5---PF6---PF7---PF8---PF9---PF10--PF11--PF12---
Help Print Exit Canc
236
Natural for DB2 Version 3.1.4 for Mainframes Statement Logging
On the DBLOG Snapshot Report screen for DB2, the following information is displayed:
Item Explanation
CU Cursor number.
SN Internal statement number.
M Mode ("D" for dynamic or "S" for static).
Typ Database type (in this case: DB2).
R Indicates by an asterisk in front of the corresponding statement that a reselection has
been performed; if not, the column is left blank; see also the Concept of the File
Server.
SQLC/W Either the SQL return code in the SQLCODE field of the SQLCA, or the warning in
the SQLWARN0 field of theSQLCA if SQLCODE is 0.
Library The library where the Natural program with the logged statement was cataloged.
Program The name of the Natural program which contains the logged statement.
Store Clock Value The time stamp of the Natural program which contains the logged statement.
Line The source code line number of the logged statement.
LV The call level of the Natural program which contains the logged statement.
CID (hex) The command ID of the logged statement (in hexadecimal format)
237
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
Interface Subprograms
Several Natural and non-Natural subprograms are available to provide you with either internal information
from the Natural interface to DB2 or specific functions that are not available within the interface itself.
From within a Natural program, Natural subprograms are invoked with the CALLNAT statement and
non-Natural subprograms are invoked with the CALL statement.
Natural Subprograms
The DB2SERV Interface
Natural Subprograms
The following Natural subprograms are provided:
Subprogram Function
NDBDBRM Checks whether a Natural program contains SQL access and whether it has been modified
for static execution.
NDBDBR2 Checks whether a Natural program contains SQL access and whether it has been modified
for static execution.
NDBERR Provides diagnostic information on the most recently executed SQL call.
NDBISQL Executes SQL statements in dynamic mode.
NDBNOERR Suppresses normal Natural error handling.
NDBNROW Obtains the number of rows affected by a Natural SQL statement.
NDBSTMP Provides a DB2 TIMESTAMP column as an alphanumeric field and vice versa.
All these subprograms are provided in the library SYSDB2 and should be copied to the SYSTEM or
steplib library, or to any library where they are needed. In addition, the subprogram DBTLIB2N and the
subroutine DBDL219S have to be copied from SYSDB2. They are used by NDBDBRM and NDBDBR2.
The corresponding parameters must be defined in a DEFINE DATA statement.
238
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
A sample program called CALLDBRM is provided on the installation tape; it demonstrates how to invoke
NDBDBRM. A description of the call format and of the parameters is provided in the text member
NDBDBRMT.
Code Explanation
0 The member #MEM in library #LIB has SQL access; it is static if #DBRM contains a value.
-1 The member #MEM in library #LIB has no SQL access.
-2 The member #MEM in library #LIB does not exist.
-3 No library name has been specified.
-4 No member name has been specified.
-5 The library name must start with a letter.
<-5 Further negative response codes correspond to error numbers of Natural error messages.
>0 Positive response codes correspond to error numbers of Natural Security messages.
239
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
A sample program called CALLDBR2 is provided on the installation tape; it demonstrates how to invoke
NDBDBR2. A description of the call format and of the parameters is provided in the text member
NDBDBR2T.
Code Explanation
0 The member #MEM in library #LIB has SQL access; it is static if #DBRM contains a value.
-1 The member #MEM in library #LIB has no SQL access.
-2 The member #MEM in library #LIB does not exist.
-3 No library name has been specified.
-4 No member name has been specified.
-5 The library name must start with a letter.
<-5 Further negative response codes correspond to error numbers of Natural error messages.
>0 Positive response codes correspond to error numbers of Natural Security messages.
240
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
A sample program called CALLERR is provided on the installation tape; it demonstrates how to invoke
NDBERR. A description of the call format and of the parameters is provided in the text member
NDBERRT.
241
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
A sample program called CALLISQL is provided on the installation tape; it demonstrates how to invoke
NDBISQL. A description of the call format and of the parameters is provided in the text member
NDBISQLT.
242
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
Call Sequence
The first call must be an EXECUTE call. If the statement is a SELECT statement (that is, response code 5
is returned), any sequence of TITLE and FETCH calls can be used to retrieve the data. A response code of
100 indicates the end of the data.
Function code EXECUTE implicitly closes a cursor which has been opened by a previous EXECUTE call
for a SELECT statement.
In TP environments, no terminal I/O can be performed between an EXECUTE call and any TITLE,
FETCH or CLOSE call that refers to the same statement.
243
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
A sample program called CALLNOER is provided on the installation tape; it demonstrates how to invoke
NDBNOERR. A description of the call format and of the parameters is provided in the text member
NDBNOERT.
Note:
Only NAT3700 errors (that is, non-zero SQL response codes) are suppressed, and also only errors caused
by the next following SQL call.
If NDBNOERR is called before a statement that initiates a database loop and an initialization error
occurs, no processing loop will be initiated, unless the IF NO RECORDS FOUND clause has been
specified.
If NDBNOERR is called within a database loop, it does not apply to the processing loop itself, but
only to the SQL statement subsequently executed inside this loop.
A sample program called CALLNROW is provided on the installation tape; it demonstrates how to invoke
NDBNROW. A description of the call format and of the parameters is provided in the text member
NDBNROWT.
244
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
Since Natural does not yet support computation with such fields, the Natural subprogram NDBSTMP is
provided to enable this kind of functionality. It converts Natural time variables to DB2 time stamps and
vice versa and performs DB2 time stamp arithmetics.
A sample program called CALLSTMP is provided on the installation tape; it demonstrates how to invoke
NDBSTMP. A description of the call format and of the parameters is provided in the text member
NDBSTMPT.
Code Explanation
ADD Adds time units (labeled durations) to a given DB2 time stamp and returns a Natural time
variable and a new DB2 time stamp.
CNT2 Converts a Natural time variable (format T) into a DB2 time stamp (column type TIMESTAMP)
and labeled durations.
C2TN Converts a DB2 time stamp (column type TIMESTAMP) into a Natural time variable (format T)
and labeled durations.
DIFF Builds the difference between two given DB2 time stamps and returns labeled durations.
GEN Generates a DB2 time stamp from the current date and time values of the Natural system variable
*TIMX and returns a new DB2 time stamp.
SUB Subtracts labeled durations from a given DB2 time stamp and returns a Natural time variable and
a new DB2 time stamp.
TEST Tests a given DB2 time stamp for valid format and returns "TRUE" or "FALSE".
Note:
Labeled durations are units of year, month, day, hour, minute, second and microsecond.
245
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
The parameter or variable values returned by each of these functions are checked for their format, length,
and number.
Function "D"
Function "D" performs the SQL statement EXECUTE IMMEDIATE. This allows SQL statements to be
issued from within a Natural program.
The SQL statement string that follows the EXECUTE IMMEDIATE statement must be assigned to the
Natural program variable STMT. It must contain valid SQL statements allowed with the EXECUTE
IMMEDIATE statement as described in the relevant IBM documentation. Examples can be found below
and in the demonstration programs DEM2* in library SYSDB2.
Note:
The conditions that apply to issuing the Natural END TRANSACTION or BACKOUT TRANSACTION
statements also apply when issuing the SQL COMMIT or ROLLBACK statements.
246
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
Command Syntax
CALL ’DB2SERV’ ’D’ STMT STMTL SQLCA RETCODE
The variables used in this command are described in the following table:
The current contents of the SQLCA and an interface return code (RETCODE) are returned. The SQLCA
is a collection of variables that are used by DB2 to provide an application program with information on
the execution of its SQL statements.
247
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
The following two examples show you how to use DB2SERV with function "D":
Note:
The functionality of the DB2SERV function "D" is also provided with the PROCESS SQL statement (see
also SQL Statements in the Natural Statements documentation).
248
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
When using SET CURRENT SQLID, the creator name of a table can be substituted by the current
SQLID. This enables you to access identical tables with the same table name but with different creator
names. Thus, table names should not be qualified by a creator name if this is to be substituted by the
SQLID.
In all supported TP-monitor environments, the SQLID can then be kept across terminal I/Os until either
the end of the session or its resetting via DB2SERV.
249
Interface Subprograms Natural for DB2 Version 3.1.4 for Mainframes
Function "P"
Function "P" invokes an Assembler module named NDBPLAN, which is used to establish and/or
terminate the DB2 connection under TSO and in batch mode. This allows a Natural application to perform
plan switching under TSO and in batch mode.
The program DEM2PLAN is an example for the use of DB2SERV with function "P".
The name of the current DB2 subsystem (#SSM) and the name of the new application plan (#PLAN) must
be specified. In addition, an interface return code (#RETCODE) and the DB2 reason code (#REASON)
are returned.
Command Syntax
CALL ’DB2SERV’ ’P’ #SSM #PLAN #RETCODE #REASON
#REASON I4 Returns the reason code of the CAF interface (see also the relevant DB2
literature).
250
Natural for DB2 Version 3.1.4 for Mainframes Interface Subprograms
Important:
Plan switching under TSO and in batch mode is possible with the CAF interface only; see also the section
Plan Switching under TSO and in Batch Mode.
251
The Natural File Server for DB2 Natural for DB2 Version 3.1.4 for Mainframes
All rows of all open cursors are rolled out to the file server before the first terminal I/O operation.
Subsequently, all data is retrieved from this file if Natural refers to one of the cursors which were
previously rolled out.
If a row is to be updated or deleted, the row is first checked to see if it has been updated in the meantime
by some other process. This is done by reselecting and fetching the row from the DB2 database, and then
comparing it with the original version as retrieved from the file server. If the row is still unchanged, the
update or delete operation can be executed. If not, a corresponding error message is returned. The
reselection required when updating or deleting a row is possible in both dynamic mode and static mode.
Only the fields which are stored in the file server are checked for consistency against the record retrieved
from DB2.
As the row must be uniquely identified, the Natural view must contain a field for which a unique row has
been created. This field must be defined as a unique key in DB2. In a Natural DDM, it will then be
indicated as a unique key via the corresponding Natural-specific short name.
252
Natural for DB2 Version 3.1.4 for Mainframes The Natural File Server for DB2
The File Server can use either a VSAM RRDS file or the Software AG Editor buffer pool as storage
medium to save selected rows of DB2 tables.
The file server is created by defining an RRDS VSAM file using AMS (Access Method Services). Its
physical size and its name must be specified.
The file server is formatted by a batch job, which requires five input parameters specified by the user, and
which formats the file server according to these parameters. The parameters specify:
1. The number of blocks to be formatted (logical size of the VSAM file); this value is taken from the
first parameter of the RECORD subcommand of the AMS DEFINE CLUSTER command.
2. The number of users that can log on to Natural concurrently.
3. The number of formatted blocks to be defined as primary allocation per user.
4. The number of formatted blocks to be used as secondary allocation per user.
5. The maximum number of file server blocks to be allocated by each user. If this number is exceeded, a
corresponding Natural error message is returned.
Immediately before the first access to the file server, a file server directory entry is allocated to the Natural
session and the amount of blocks specified as primary allocation is allocated to the Natural session.
The primary allocation is used as intermediate storage for the result of a database selection and should be
large enough to accommodate all rows of an ordinary database selection. Should more space in the file
server be required for a large database selection, the file server modules allocate a secondary allocation
equal to the amount that was specified for secondary allocation when the file server was formatted.
Thus, a secondary area is allocated only when your current primary allocation is not large enough to
contain all of the data which must be written to the intermediate file. The number of secondary allocations
allowed depends upon the maximum number of blocks you are allowed to allocate. This parameter is also
specified when formatting the file server.
The number of blocks defined as the secondary allocation is allocated repeatedly, until either all selected
data has been written to the file or the maximum number of blocks you are allowed to allocate is
exceeded. If so, a corresponding Natural error message is returned. When the blocks received as a
253
The Natural File Server for DB2 Natural for DB2 Version 3.1.4 for Mainframes
secondary allocation are no longer needed (that is, once the Natural loop associated with this allocation is
closed), they are returned to the free blocks pool of the file server.
Your primary allocation of blocks, however, is always allocated to you, until the end of your Natural
session.
To minimize channel contention or bottlenecks that can be caused by placing a large and heavily used file
server on a single DASD volume, you can create a file server that spans several DASD volumes.
To create and format such a file server, two changes are needed in the job that is used to define the VSAM
cluster:
This means that in the file server format job, the value of the first parameter is the result of multiplying
two parameters taken from the DEFINE CLUSTER command: RECORDS and VOLUMES.
The operation of the file server is in this case depending on the definition of the Software AG Editor
buffer pool as described in the Natural Operations for Mainframes documentation.
The number of logical files for the buffer pool limits the number of users concurrently accessing the file
server. The number of work file blocks limits the amount of data to be saved at a specific moment. (You
also have to consider that there are other users than NDB of the Software AG Editor.)
However, using the Software AG Editor buffer pool as storage medium for the file server enables NDB to
run in a Sysplex environment.
If you like to use the file server in a sysplex environment, it is recommended to use the Software AG
Editor buffer pool as storage medium.
254
Natural for DB2 Version 3.1.4 for Mainframes The Natural File Server for DB2
Generally, the file server is only used when a terminal I/O occurs within an active READ, FIND, or
SELECT loop, where database selection results would be lost. Before each terminal I/O operation, Natural
checks for any open cursors. If any open cursors are found, all remaining rows are retrieved from DB2 and
written to the intermediate file. For each open cursor, a logical file is opened to hold all the rows fetched
from this cursor. The space for this logical file is managed within the space allocated to your session.
Subsequent requests for these data are then satisfied by reading the rows directly from the logical file. The
database is no longer involved, and DB2 is only used for update, delete or store operations.
Once all data in the logical file have been retrieved by Natural, the file is no longer needed and the blocks
it occupies are returned to your pool of free blocks. From here, the blocks are returned to the free blocks
pool of the file server, so that you are left with your primary allocation only.
In the following example, the space allocated to the first selection is not released until all rows selected
during the third selection have been retrieved. The same applies to the space allocated to the third
selection.
The space allocated to the second selection, however, is released immediately after the last row of the
corresponding selection result has been retrieved.
Therefore, the space allocated to the second selection can be used for the selection results of the third
selection.
255
The Natural File Server for DB2 Natural for DB2 Version 3.1.4 for Mainframes
If the primary allocation area is not large enough, for example, if the third selection is nested within the
second selection, the secondary allocation area is used.
256
Natural for DB2 Version 3.1.4 for Mainframes The Natural File Server for DB2
When a session is terminated, all of a user’s blocks are returned to the free blocks pool. If a session ends
abnormally, Natural checks, where possible, whether a file server directory entry for the corresponding
user exists. If so, all resources held by this user are released.
If Natural is unable to free the resources of an abnormally-ended user session, these resources are not
released until the same user ID logs on from the same logical terminal again.
If the same user ID and/or logical terminal are not used again for Natural, the existing directory entry and
the allocated space remain until the file server is formatted again. A new run of the formatting job deletes
all existing data and recreates the directory.
257
Environment-Specific Considerations Natural for DB2 Version 3.1.4 for Mainframes
Environment-Specific Considerations
Natural for DB2 can be run in the TP-monitor environments Com-plete, CICS, IMS/TM and TSO as well
as in batch mode.
Under CICS, IMS/TM MPP and TSO, the Natural file server for DB2 is provided. The usage of the file
server depends on the FSERV parameter in the NDBPARM parameter module.
If the DB2 plan created during the installation process is not specified in your DB2 SERVER parameter
list for Com-plete, you must explicitly call NATPLAN before the first SQL call to allocate this plan.
In IMS/TM transaction processing environments, DB2 closes all cursors and thereby loses all selection
results whenever the program returns to the terminal to send a reply message. This operation mode is
different from the way DB2 works in CICS conversational mode or TSO environments, where cursors can
remain open across terminal communication and therefore selected rows can be retained for a longer time.
For a detailed description of the file server, refer to the section The Natural File Server for DB2.
258
Natural for DB2 Version 3.1.4 for Mainframes Environment-Specific Considerations
If your transaction ID is not assigned to any DB2 plan in the RCT, you must explicitly call NATPLAN
before the first SQL call to specify the required DB2 plan. The actual plan allocation is performed by the
dynamic plan selection exit.
Under CICS, a Natural program which accesses a DB2 table can also be run in pseudo-conversational
mode. Then, at the end of a CICS task, all DB2 cursors are closed, and there is no way to reposition a DB2
cursor when the task is resumed.
If the file server is not used, Natural switches to conversational mode whenever a terminal I/O takes place
during an open database loop.
To enable multiple Natural sessions to run concurrently, all Natural areas are written to the threads just
before a terminal I/O operation is executed. When the terminal input is received, storage is acquired again,
and all Natural areas are read from the threads.
For a detailed description of the file server, refer to the section The Natural File Server for DB2.
259
Environment-Specific Considerations Natural for DB2 Version 3.1.4 for Mainframes
Apart from OS/390 Batch, the batch environment for Natural can also be the TSO background, which
invokes the TSO terminal monitor program by an "EXEC PGM=IKJEFT01" statement in a JCL stream.
Both TSO online or batch programs can be executed either under the control of the DSN command or by
using the Call Attachment Facility (CAF); the CAF interface is required if plan switching is to be used.
With each terminal I/O, Natural issues a COMMIT WORK command to simulate CICS or IMS/TM
syncpoints. Therefore, database modifications made before a terminal I/O can no longer be backed out.
For a detailed description of the file server, refer to the section The Natural File Server for DB2.
If you want to use this facility, you must execute the DLIBATCH procedure to run the DSNMTV01
module as the application program. DSNMTV01 in turn executes the Natural batch nucleus which must be
linked with the DB2 interface DFSLI000.
Since DB2 does not allow syncpoints when running in an DSNMTV01 environment, the Natural interface
to DB2 cannot execute these syncpoints by itself. These syncpoints are therefore routed to the Natural
interface to DL/I. Only one checkpoint is written for the corresponding END TRANSACTION statement,
even if both database systems are involved.
If your PSB is generated with CMPAT=YES, all syncpoints are executed by Natural for DL/I. Therefore,
you must issue a END TRANSACTION statement before you end your Natural session; otherwise all
your database modifications are lost, because Natural implicitly issues a BACKOUT TRANSACTION
statement at the end of the session.
260