VSAM To DB2 Conversion
VSAM To DB2 Conversion
1
Version 1.0
Preface
Scope and audience
This document is intended to assist in converting online programs using COBOL CICS
and batch programs using COBOL which access VSAM files to access DB2 tables.
.
Objectives
VSAM to DB2 conversion
Structure of this document
Document discusses schema translation strategy initially. Translation of batch COBOL
access calls for VSAM to DB2 is discussed. Translation of CICS access calls to DB2
access calls is detailed out next for each of the CICS commands for KSDS files. The
document ends with the performance tuning issues to be considered.
Related documents
VSAM to DB2 error handling document
Table of contents
1
OVERVIEW............................................................................................................................................6
SCHEMA TRANSLATION...................................................................................................................6
CONVERSION STRATEGY................................................................................................................7
3.1
BATCH PROGRAM TRANSLATION.......................................................................................................11
3.1.1
Specific Translation Rules......................................................................................................11
3.1.2
Sequential Organization Sequential Access...........................................................................12
3.1.2.1
3.1.2.2
3.1.2.3
3.1.3
3.1.3.1
3.1.3.2
3.1.3.3
3.1.4
3.1.4.1
3.1.4.2
3.1.4.3
3.1.5
3.1.5.1
3.1.5.2
3.1.5.3
INPUT.............................................................................................................................................12
I-O...................................................................................................................................................13
OUTPUT/EXTEND.......................................................................................................................13
3.2
ONLINE PROGRAM TRANSLATION.....................................................................................................27
3.2.1
READ......................................................................................................................................29
3.2.1.1
3.2.1.2
3.2.1.3
3.2.2
3.2.2.1
3.2.2.2
3.2.2.3
3.2.3
3.2.3.1
3.2.3.2
3.2.3.3
3.2.4
3.2.4.1
3.2.4.2
3.2.4.3
3.2.5
3.2.5.1
3.2.5.2
3.2.5.3
3.2.6
3.2.6.1
3.2.6.2
3.2.6.3
3.2.7
3.2.7.1
3.2.7.2
3.2.7.3
3.2.8
3.2.8.1
3.2.8.2
3.2.8.3
3.2.9
Function..........................................................................................................................................29
CICS Syntax...................................................................................................................................29
Translation of Syntax....................................................................................................................29
STARTBR................................................................................................................................31
Function..........................................................................................................................................31
CICS Syntax...................................................................................................................................31
Translation of Syntax......................................................................................................................31
READNEXT / READPREV.....................................................................................................34
Function..........................................................................................................................................34
CICS Syntax...................................................................................................................................34
Translation of Syntax.....................................................................................................................35
WRITE....................................................................................................................................38
Function..........................................................................................................................................38
CICS Syntax...................................................................................................................................38
Translation of Syntax.....................................................................................................................38
REWRITE...............................................................................................................................39
Function..........................................................................................................................................39
CICS Syntax...................................................................................................................................39
Translation of Syntax.....................................................................................................................39
DELETE.................................................................................................................................40
Function...........................................................................................................................................40
CICS Syntax...................................................................................................................................40
Translation Of Syntax....................................................................................................................40
UNLOCK................................................................................................................................42
Function..........................................................................................................................................42
CICS Syntax...................................................................................................................................42
Translation of Syntax....................................................................................................................42
ENDBR...................................................................................................................................43
Function..........................................................................................................................................43
CICS Syntax...................................................................................................................................43
Translation Of Syntax....................................................................................................................43
RESETBR...............................................................................................................................44
3.2.9.1
3.2.9.2
3.2.9.3
Function..........................................................................................................................................44
CICS Syntax...................................................................................................................................44
Translation Of Syntax....................................................................................................................44
APPENDIX...........................................................................................................................................49
5.1.1
5.1.2
5.1.3
5.1.4
5.1.5
5.1.6
5.1.7
5.1.8
5.1.9
5.1.10
5.1.11
5.1.12
5.1.13
5.1.14
5.1.15
5.1.16
5.1.17
5.1.18
5.1.19
5.1.20
1 Overview
This document discusses translation strategy for VSAM access calls appearing in online COBOL CICS and
batch COBOL programs by SQLs to access DB2 table.
Emphasis is on one to one translation of each VSAM access call to DB2 access SQLs.
2 Schema Translation
During this phase of the migration, VSAM file schema needs to be translated to relational schema.
For this a complete mapping document needs to be prepared for the VSAM files being converted to DB2
tables. This document has the VSAM file name, the record name, copybook name for this file, the field
names of the record, with the corresponding DB2 table names, column names, data description for the
columns, indicators to identify whether nulls are allowed, the column is an index and mapping exceptions
of any kind. It is understood that in such conversion there are cases of multiple mapping, like one VSAM
file mapped to many tables, many VSAM files mapped to one table, different record types of a VSAM file
mapped to different tables, one field of a VSAM record mapped to multiple columns of a table, many
fields of a VSAM record mapped to one table column.
3 Conversion Strategy
The conversion is based on the following translation rules :
1.
COBOL source code will remain same except for the introduction of new code and commenting of
existing code as part of translation. New code will be either embedded SQL statements or COBOL
constructs or INCLUDE copybooks, to support translation. Comments will be added to indicate the
program changes done.
2.
DCLGEN variables will be used as host variables. These values will be moved into the VSAM file
structure for the program processing.
3.
VSAM sequential operations will be translated using cursors on the associated tables.
4.
I/O operations on array fields of the record will be translated using cursors for normalised cases. In
denormalised cases the array fields will be translated to the corresponding columns on the DB2 table.
5.
6.
Any supported COBOL construct related to VSAM file, which is translated to relational equivalent or
not needed any more will be commented.
7.
In case of commenting OPEN statements, if the same statement opens some other non-VSAM files or
VSAM files which will not be converted, an OPEN statement to open those files will be added in the
program and the original OPEN statement will be commented.
8.
In case of commenting CLOSE statements, if the same statement closes some other non-VSAM files or
VSAM files which will not be converted, an CLOSE statement to close those files will be added in the
program and the original CLOSE statement will be commented.
9.
At any point of time, there will be only one cursor opened per table. Cursors will be defined and
opened with various conditions based on organization, access mode and file operation.
if the keylength is a constant known at conversion time, the START will be translated to
DECLARE CURSOR using the table columns corresponding to this key length specified.
b.
If the key length is calculated at run time, it needs to be analysed and suitable WHERE clause
should be used in the DECLARE CURSOR clause.
13. Any column corresponding to key fields of the VSAM file needs to be used as an index on the table.
Alternate record keys can be considered as index on tables. This needs table to be indexed on columns
corresponding to alternate record keys.
b.
c.
b.
c.
d.
18. In the case of one-to-many mapping, the following scenarios are possible :
a.
One VSAM file having different record types mapped to different tables
Sequential Operation on the VSAM file
Example of this is header and detail records in a VSAM file. In DB2 there can be table
defined for header records and another table defined for detail records. Any sequential read of
this VSAM file will be translated to opening a cursor on the header table, then fetch cursor
on the header table. Using the key retrieved from the header table open a cursor on the
detail table and continue fetch using this cursor until end-of-cursor, then close the cursor on
the detail table. Again fetch the cursor on the header table and continue the process of open
cursor and fetch cursor on the detail table.
For any sequential update or delete operations on this VSAM file, the same translation
strategy will be used but with the cursor option FOR UPDATE.
Random Operation on the VSAM file
If the VSAM file is being read randomly using a key value moved within the program, then
the program flow needs to be analysed to determine which table needs to be accessed.
b.
d.
19. While populating default values for any NOT NULL fields in the DB2 table, assume 0 for numeric and
SPACES for CHAR fields as default.
Any NULL fetched from the table will be interpreted as a 0 if the receiving field is numeric or as
SPACES if the receiving field is alphanumeric.
20. Before updating or inserting into any column which has a numeric data type in DB2, perform a
numeric-check. If the value is non-numeric, assign the null indicator for nullable fields and
0 for non-nullable fields.
10
21. For groups containing numeric items mapped to a single numeric column, the group will be treated as
an alphanumeric and moved into the numeric column. Such translation will hold good only if the
numeric values in the sub-fields can be treated as an alphanumeric value from the business point of
view. For example it is ok to map a group item having sub-items as account and sub-account, both
numeric, into a single numeric table column as account. But if the same translation is performed for
items like amounts, then the result will be unpredictable.
22. In many situations a field defined in the VSAM layout and the corresponding DB2 table column will
have different lengths, this is because the datatypes in VSAM and DB2 are different and have their
own field length restrictions.
23. For variable length VSAM files being used in the program, the table will have columns corresponding
to the OCCURS fields. The number of columns will be the maximum possible value of the OCCURS
clause. After conversion to tables there will be a column for each occurance of the variable occurance
field, although all the columns may not be used or not have values populated in them. Within the
program the logic will be to use all the occurances of the field, but this may not be in tune with the
existing program logic.
24. New fields defined in the tables for any future use will be populated with the default values.
25. In case of CICS programs a record can be read into an area within the program, or into the CICS
buffer. In the later situation a pointer is used for accessing the buffer area where the record is read into.
After translation the use of this pointer will be avoided for data read from tables. Define a 01 level
item with length equal to the record length for the file for which the pointer was used. After accessing
data from the tables, format and move this data to the record layout as well as to this newly defined
data item. Any use of the data stored in the buffer identified by the pointer will be replaced by using
the newly defined data item.
26. Translate a START browse, READNEXT operation into OPEN cursor and FETCH cursor. After
each fetch, the key values retrieved will be saved and will be compared with the key value before the
next fetch. If the key values match continue with the fetch, else close the cursor and then open a new
cursor using the current key values and continue the fetch operation. This feature will allow the skip
sequential processing to be converted correctly.
27. Any VSAM files used in internal program sorting will also be translated to SQL statements.
28. After conversion, many file OPEN statements will have been commented because they are not required
for an indexed file which is converted to DB2 table. In such cases the file status for these commented
files have to be set up properly so that program processing continues normally. This can be done by
setting the file status to 00 for the file OPEN which was commented out.
11
3.1
3.1.1
Following sections specify the translation strategy for each of the valid file I/O operation for VSAM files.
The rules are organized as follows:
Description
Dependant-cursor-1
Dependant-cursor-n
Array-1
Db2-array-1
Newly defined structure similar to the first array but scalar, to be used
in moving data between tables and the array
Array-1-table-1
array-1-table-1-col-1
db2-array-1-table-1-col-1-fld-1
Field in the newly defined record corresponding to the first field of the
first array, which has mapping column in the first table
array-1-table-1-col-n
db2-array-1-table-1-col-n-fld-n
Field in the newly defined record corresponding to the nth field of the
first array, which has mapping column in the first table
array-1-table-n
array-1-table-n-col-1
db2-array-1-table-n-col-1-fld-1
Field in the newly defined record corresponding to the first field of the
first array, which has mapping column in the nth table
array-1-table-n-col-n
db2-array-1-table-n-col-n-fld-n
Field in the newly defined record corresponding to the nth field of the
first array, which has mapping column in the nth table
Db2-array-1-size
Newly generated data item to store the size of the first array. This data
item will be used in determining the number of times
fetch/select/insert/update to be done on the tables corresponding to the
array
Array-n
Db2-array-n
array-n-table-1
12
array-n-table-1-col-1
db2-array-n-table-1-col-1-fld-1
Field in the newly defined record corresponding to the first field of the
nth array, which has mapping column in the first table
array-n-table-1-col-n
db2-array-n-table-1-col-n-fld-n
Field in the newly defined record corresponding to the nth field of the
nth array, which has mapping column in the first table
array-n-table-n
array-n-table-n-col-1
db2-array-n-table-n-col-1-fld-1
Field in the newly defined record corresponding to the first field of the
nth array, which has mapping column in the nth table
array-n-table-n-col-n
db2-array-n-table-n-col-n-fld-n
Field in the newly defined record corresponding to the nth field of the
nth array, which has mapping column in the nth table
Db2-array-n-size
Newly generated data item to store the size of the nth array. This data
item will be used in determining the number of times
fetch/select/insert/update to be done on the tables corresponding to the
array
table-1-key-col-1
table-1-key-col-n
at-end-statements
not-at-end-statements
Invalid-key-statements
Not-invalid-key-statements
Db2-count
3.1.2
All the I/O operations in files with sequential organization and sequential access mode are sequential.
3.1.2.1 INPUT
Cursor Definition :
OPEN-CURSOR
Operation
OPEN
READ
CLOSE
Description
Open the defined cursor.
Translated Code
EXEC SQL
OPEN <file1>-OPEN-CURSOR
END-EXEC.
Sequential-Read-OPEN-CURSOR
EXEC SQL
CLOSE <file1>-OPEN-CURSOR
END-EXEC
13
3.1.2.2 I-O
Cursor Definition :
OPEN-CURSOR
Operation
OPEN
Description
Open the defined cursor.
READ
REWRITE
CLOSE
Translated Code
EXEC SQL
OPEN <file1>-OPEN-CURSOR
END-EXEC.
Sequential-Read-OPEN-CURSOR
Random-Rewrite
EXEC SQL
CLOSE <file1>-OPEN-CURSOR
END-EXEC
3.1.2.3 OUTPUT/EXTEND
Operation
OPEN
WRITE
CLOSE
3.1.3
Description
Comment CLOSE statement
Insert new rows into respective tables.
Comment the CLOSE statement.
Translated Code
None
Insert
None
All the I/O operations in a file with index organization and sequential access are in the ascending order of
the value of the record key. File positioning is achieved using either OPEN or START. For files opened in
INPUT or I-O mode, query translation varies based on the existence of START on the file. In each of the
above two open modes, there are two sections, START EXISTS and START DOES NOT EXIST,
specifying the corresponding translation strategies.
3.1.3.1 INPUT
3.1.3.1.1 START EXISTS
This section specifies the translation strategy for VSAM files with indexed organization, sequential access
mode opened in INPUT mode where START is used.
Define a cursor for each VSAM file, to select all the rows in the corresponding tables.
If START is used and if it uses full record key in key comparison, define a cursor to select all the rows in
the corresponding tables where key columns have values greater than or equal to the record key values.
Define the above cursors to be ORDER BY primary key columns of one of the tables.
Define a condition name in the working storage section, to be set and reset by START and OPEN
statements when they open and close the cursor. This condition name will indicate the current opened
cursor to be used by other operations.
Definition of the condition name will be
01 <file1>-CURSOR PIC 9 VALUE 0.
88 <file1>-OPEN
88 <file1>-START-RK
value 1.
value 2.
Where <file1>-OPEN will be set when the cursor corresponding to OPEN is opened
<file1>-START-RK will be set when the cursor corresponding to START is opened.
Cursor definition for OPEN :
14
START
READ or
READ
NEXT
CLOSE
Description
Open the cursor <file1>-OPEN-CURSOR. This
will select all the rows in the table. Set this cursor
to be the current valid cursor, which can then be
used by successive I/O operations till START
repositions the file position indicator or CLOSE
closes the file.
Start repositions the file position indicator by
populating record key fields with appropriate
values. If the corresponding cursor is already
opened, close the cursor and open it again.
Reopening the cursor will select the rows based on
the current value of the host variables used in the
WHERE clause. Set <file1>-START-RKCURSOR to be the current valid cursor which can
be used by successive I/O operations till another
START repositions the file position indicator or
CLOSE closes the file.
Translated Code
EXEC SQL
OPEN <file1>-OPENCURSOR
END-EXEC.
MOVE 1 TO <file1>-CURSOR.
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
Sequential-Read-OPENCURSOR
WHEN <file1>-START-RK
Sequential-Read-STARTCURSOR
END-EVALUATE
IF <file1>-START-RK
THEN
EXEC SQL
CLOSE <file1>-STARTRK-CURSOR
END-EXEC
END-IF.
EXEC SQL
OPEN <file1>-START-RKCURSOR
END-EXEC.
MOVE 2 TO <file1>-CURSOR.
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
EXEC SQL
CLOSE <file1>-STARTRK-CURSOR
END-EXEC
MOVE 0 TO <file1>-CURSOR.
15
Operation
OPEN
Description
Open the cursor <file1>-OPEN-CURSOR.
READ or
READ
NEXT
CLOSE
Translated Code
EXEC SQL
OPEN <file1>-OPENCURSOR
END-EXEC.
Sequential-Read-OPEN-CURSOR
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
3.1.3.2 I-O
3.1.3.2.1 START-EXISTS
This section specifies the translation strategy for VSAM files with indexed organization, sequential access
mode opened in I-O mode where START is used.
Define a cursor for each VSAM file, to select all the rows in the corresponding table.
If start is used and if start uses full record key in key comparison, define a cursor to select all the rows in
the corresponding tables where key columns have values greater than or equal to the record key values.
Define the above cursors to be ORDER BY primary key columns.
Define a condition name in the working storage section, to be set and reset by START and OPEN
statements when they open and close the cursor. This condition name will indicate the current opened
cursor to be used by other operations.
Definition of the condition name will be
01 <file1>-CURSOR PIC 9 VALUE 0.
88 <file1>-OPEN
88 <file1>-START-RK
value 1.
value 2.
Where <file1>-OPEN will be set when the cursor corresponding to OPEN is opened
<file1>-START-RK will be set when the cursor corresponding to START is opened.
Cursor definition for OPEN :
OPEN-CURSOR
Cursor definition for START :
START-CURSOR
Operation
OPEN
START
Description
Open the cursor <file1>-OPEN-CURSOR.
This will select all the rows in the table. Set
<file1>-OPEN-CURSOR to be the current
valid cursor which can then be used by
successive I/O operations till START
repositions the file position indicator or
CLOSE closes the file.
Start repositions the file position indicator
by populating record key fields with
appropriate values. If the corresponding
cursor is already opened, close the cursor
and open it again. Reopening the cursor will
Translated Code
EXEC SQL
OPEN <file1>-OPEN-CURSOR
END-EXEC.
MOVE 1 TO <file1>-CURSOR.
IF <file1>-START-RK
THEN
EXEC SQL
CLOSE <file1>-START-RKCURSOR
16
READ
REWRITE
WRITE
DELETE
CLOSE
END-EXEC
END-IF.
EXEC SQL
OPEN <file1>-START-RKCURSOR
END-EXEC.
MOVE 2 TO <file1>-CURSOR.
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
Sequential-Read-OPEN-CURSOR
WHEN <file1>-START-RK
Sequential-Read-START-CURSOR
END-EVALUATE
Random-Rewrite
Insert
Delete
EXEC SQL
CLOSE <file1>-OPEN-CURSOR
END-EXEC
EXEC SQL
CLOSE <file1>-START-RKCURSOR
END-EXEC
MOVE 0 TO <file1>-CURSOR
Description
Open the cursor defined for the
corresponding file.
READ
REWRITE
WRITE
Translated Code
EXEC SQL
OPEN <file1>-OPEN-CURSOR
END-EXEC.
Sequential-Read-OPEN-CURSOR
Random-Rewrite
Insert
17
DELETE
CLOSE
Delete
EXEC SQL
CLOSE <file1>-OPEN-CURSOR
END-EXEC
3.1.4
Description
Comment OPEN statement.
Insert the new row into the corresponding
table.
Multiple INSERT
Comment CLOSE statement
Translated Code
None
Insert
None
All the I/O operations in a file with index organization and random access mode, are random i.e., will use
key values to insert or retrieve records. All the queries will be translated using WHERE condition.
3.1.4.1 INPUT
Operation
OPEN
READ
CLOSE
Description
Comment the OPEN statement.
Select the record with primary key
columns having values equal to record key
values.
Comment the CLOSE statement
Translated Code
None
Random-Read
None
3.1.4.2 I-O
Operation
OPEN
READ
REWRITE
INSERT
DELETE
CLOSE
Description
Comment the OPEN statement
Select the row with primary key columns
having values equal to record key values.
Update the row with primary key columns
having values equal to record key values.
Multiple UPDATE
Insert the new row into the table
corresponding to the file.
Delete the row with primary key columns
having values equal to record key values.
Comment CLOSE statement.
Translated Code
None
Random-Read
Random-Rewrite
Insert
Delete
None
3.1.4.3 OUTPUT
Operation
OPEN
WRITE
CLOSE
3.1.5
Description
Comment the OPEN statement
Insert the new row into the table
corresponding to the file.
Comment the CLOSE statement
Translated Code
None
Insert
None
I/O operations in files with indexed organization and dynamic access, can be either sequential or random or
both. OPEN opens the file with file position indicator pointing to first record. File position indicator can be
18
READ
NEXT
Yes
Yes
Yes
Yes
No
No
RANDOM READ
START
Operation
No
Yes
No
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
Sequential
Sequential and Random
Sequential and Random
Sequential and Random
Random
Random
3.1.5.1 INPUT
3.1.5.1.1 Case 2
This section specifies the translation strategy for VSAM files with indexed organization, dynamic access
mode opened in INPUT mode where READ exists, RANDOM READ exists and START does not exist.
Define a cursor for each VSAM file, to select all the rows in the corresponding table.
If RANDOM READ is used and if it uses record key in key comparison, define a cursor to select all the
rows in the corresponding table where key columns have values greater than record key values.
Define the above cursors to be ORDER BY primary key columns.
Define a condition name in the working storage section, to be set and reset by RANDOM READ and
OPEN statements when they open and close the cursor. This condition name will indicate the current
opened cursor to be used by other operations.
Definition of the condition name will be
01 <file1>-CURSOR PIC 9 VALUE 0.
88 <file1>-OPEN
88 <file1>-READ-RK
value 1.
value 2.
Where <file1>-OPEN will be set when the cursor corresponding to OPEN is opened
<file2>-READ-RK will be set when the cursor corresponding to READ is opened.
Cursor definition for OPEN :
OPEN-CURSOR
Cursor definition for READ :
READ-CURSOR
Operation
Description
Translated Code
19
OPEN
RANDOM
READ
READ
NEXT
CLOSE
EXEC SQL
OPEN <file1>-OPENCURSOR
END-EXEC.
MOVE 1 TO <file1>-CURSOR.
Random-Read
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
WHEN <file1>-READ-RK
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
END-EVALUATE
MOVE 0 TO <file1>-CURSOR
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
Sequential-Read-OPENCURSOR
WHEN <file1>-READ-RK
Sequential-Read-READCURSOR
WHEN 0
EXEC SQL
OPEN <file1>-READ-RKCURSOR.
END-EXEC
Sequential-Read-READ-CURSOR
MOVE 2 TO <file1>-CURSOR
END-EVALUATE
IF <file1>-OPEN-CURSOR
THEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
END-IF.
IF <file1>-READ-RK-CURSOR
THEN
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
END-IF.
20
3.1.5.1.2 Case 4
This section specifies the translation strategy for VSAM files with indexed organization, dynamic access
mode opened in INPUT mode where READ exists, RANDOM READ exists and START exists.
Define a cursor for each VSAM file, to select all the rows in the corresponding table.
If RANDOM READ is used and if it uses record key in key comparison, define a cursor to select all the
rows in the corresponding table where key columns have values greater than the record key values.
If START is used and if it uses record key in key comparison, define a cursor to select all the rows in the
corresponding table where key columns have values greater than or equal to the record key values.
Define the above cursors to be ORDER BY primary key columns.
Define a condition name in the working storage section, to be set and reset by RANDOM READ, START
and OPEN statements when they open and close the cursor. This condition name will indicate the current
opened cursor to be used by other operations.
Definition of the condition name will be
01 <file1>-CURSOR PIC 9 VALUE 0.
88 <file1>-OPEN
88 <file1>-READ-RK
88 <file1>-START-RK
value 1.
value 2.
value 3.
Where <file1>-OPEN will be set when the cursor corresponding to OPEN is opened,
<file1>-READ-RK will be set when the cursor corresponding to READ is opened,
<file1>-START-RK will be set when the cursor corresponding to START is opened.
Cursor definition for OPEN :
OPEN-CURSOR
Cursor definition for START :
START-CURSOR
Cursor definition for READ :
READ-CURSOR
Operation
OPEN
Description
Open the cursor defined corresponding to OPEN
statement.
START
RANDOM
READ
Translated Code
EXEC SQL
OPEN <file1>-OPENCURSOR
END-EXEC.
MOVE 1 TO <file1>-CURSOR.
IF <file1>-START-RK
THEN
EXEC SQL
CLOSE <file1>-START-RKCURSOR
END-EXEC
END-IF.
EXEC SQL
OPEN <file1>-START-RKCURSOR
END-EXEC.
MOVE 3 TO <file1>-CURSOR.
Random-Read
EVALUATE <file1>-CURSOR
21
READ
NEXT
CLOSE
WHEN <file1>-OPEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
WHEN <file1>-READ-RK
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
WHEN <file1>-START-RK
EXEC SQL
CLOSE <file1>-START-RKCURSOR
END-EXEC
END-EVALUATE
MOVE 0 TO <file1>-CURSOR
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
Sequential-Read-OPENCURSOR
WHEN <file1>-READ-RK
Sequential-Read-READCURSOR
WHEN <file1>-START-RK
Sequential-Read-STARTCURSOR
WHEN 0
EXEC SQL
OPEN <file1>-READ-RKCURSOR.
END-EXEC
Sequential-Read-READ-CURSOR
MOVE 2 TO <file1>-CURSOR
END-EVALUATE
IF <file1>-OPEN-CURSOR
THEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
END-IF.
IF <file1>-READ-RK-CURSOR
THEN
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
END-IF.
IF <file1>-START-RK-CURSOR
THEN
EXEC SQL
CLOSE <file1>-START-RK-
22
CURSOR
END-EXEC
END-IF.
MOVE 0 TO <file1>-CURSOR
3.1.5.2 I-O
3.1.5.2.1
Case 2
This section specifies the translation strategy for VSAM files with indexed organization, dynamic access
mode opened in I-O mode where READ exists, RANDOM READ exists and START does not exist.
Define a cursor for each VSAM file, to select all the rows in the corresponding table.
If RANDOM READ is used and if it uses record key in key comparison, define a cursor to select all the
rows in the corresponding table where key columns have values greater than record key values.
Define the above cursors to be ORDER BY primary key columns.
Define a condition name in the working storage section, to be set and reset by RANDOM READ and
OPEN statements when they open and close the cursor. This condition name will indicate the current
opened cursor to be used by other operations.
Definition of the condition name will be
01 <file1>-CURSOR PIC 9 VALUE 0.
88 <file1>-OPEN
88 <file1>-READ-RK
value 1.
value 2.
Where <file1>-OPEN will be set when the cursor corresponding to OPEN is opened
<file2>-READ-RK will be set when the cursor corresponding to READ is opened.
Cursor definition for OPEN :
OPEN-CURSOR
Cursor definition for READ :
READ-CURSOR
Operation
OPEN
Description
Open the cursor <file1>-OPEN-CURSOR
defined corresponding to OPEN statement.
RANDOM
READ
Translated Code
EXEC SQL
OPEN <file1>-OPENCURSOR
END-EXEC.
MOVE 1 TO <file1>-CURSOR.
Random-Read
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
WHEN <file1>-READ-RK
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
END-EVALUATE
23
READ
NEXT
REWRITE
DELETE
WRITE
CLOSE
MOVE 0 TO <file1>-CURSOR
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
Sequential-Read-OPENCURSOR
WHEN <file1>-READ-RK
Sequential-Read-READCURSOR
WHEN 0
EXEC SQL
OPEN <file1>-READ-RKCURSOR.
END-EXEC
Sequential-Read-READ-CURSOR
MOVE 2 TO <file1>-CURSOR
END-EVALUATE
Random-Rewrite
Delete
Insert
IF <file1>-OPEN-CURSOR
THEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
END-IF.
IF <file1>-READ-RK-CURSOR
THEN
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
END-IF.
MOVE 0 TO <file1>-CURSOR
3.1.5.2.1 Case 4
Define a cursor for each VSAM file, to select all the rows in the corresponding table.
If RANDOM READ is used and if it uses record key in key comparison, define a cursor to select all the
rows in the corresponding table where key columns have values greater than record key values.
24
value 1.
value 2.
value 3.
Where <file1>-OPEN will be set when the cursor corresponding to OPEN is opened,
<file1>-READ-RK will be set when the cursor corresponding to READ is opened,
<file1>-START-RK will be set when the cursor corresponding to START is opened.
Cursor definition for OPEN :
OPEN-CURSOR
Cursor definition for READ :
READ-CURSOR
Cursor definition for START :
START-CURSOR
Operation
OPEN
Description
Open the cursor <file1>-OPEN-CURSOR,
defined corresponding to OPEN statement.
START
RANDO
M READ
Translated Code
EXEC SQL
OPEN <file1>-OPENCURSOR
END-EXEC.
MOVE 1 TO <file1>-CURSOR.
IF <file1>-START-RK
THEN
EXEC SQL
CLOSE <file1>-START-RKCURSOR
END-EXEC
END-IF.
EXEC SQL
OPEN <file1>-START-RKCURSOR
END-EXEC.
MOVE 3 TO <file1>-CURSOR.
Random-Read
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
WHEN <file1>-READ-RK
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
25
READ
NEXT
REWRIT
E
DELETE
WRITE
CLOSE
END-EXEC
WHEN <file1>-START-RK
EXEC SQL
CLOSE <file1>-START-RKCURSOR
END-EXEC
END-EVALUATE
MOVE 0 TO <file1>-CURSOR
EVALUATE <file1>-CURSOR
WHEN <file1>-OPEN
Sequential-Read-OPENCURSOR
WHEN <file1>-READ-RK
Sequential-Read-READCURSOR
WHEN <file1>-START-RK
Sequential-Read-STARTCURSOR
WHEN 0
EXEC SQL
OPEN <file1>-READ-RKCURSOR.
END-EXEC
Sequential-Read-READ-CURSOR
MOVE 2 TO <file1>-CURSOR
END-EVALUATE
Random-Rewrite
Delete
Insert
IF <file1>-OPEN-CURSOR
THEN
EXEC SQL
CLOSE <file1>-OPENCURSOR
END-EXEC
END-IF.
IF <file1>-READ-RK-CURSOR
THEN
EXEC SQL
CLOSE <file1>-READ-RKCURSOR
END-EXEC
END-IF.
IF <file1>-START-RK-CURSOR
THEN
26
EXEC SQL
CLOSE <file1>-START-RKCURSOR
END-EXEC
END-IF.
MOVE 0 TO <file1>-CURSOR
3.1.6.3 OUTPUT
In this mode, there will be no READ / READ NEXT / START statements. Only allowed operations are
OPEN, WRITE and CLOSE.
Operation
OPEN
WRITE
CLOSE
Description
Comment OPEN statement.
Insert the record into the corresponding
table.
Comment CLOSE statement
Translated Code
None
Insert
None
27
3.2
Each original program with embedded VSAM access call is assumed to have following template structure.
Template also identifies some record structures that will be added to the working storage section of the
program.
IDENTIFICATION DIVISION.
PROGRAM-ID. Cicsprgm.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01
DATA-RECORD.
05 DATA-FIELD-1 .
05 DATA-FIELD-2 .
.
.
01
KEY-RECORD.
05 KEY-FIELD-1 .
05 KEY-FIELD-2 .
01
1
1
1
1
01
DATA-REC-LENGTH.
KEY-REC-LENGTH.
TOKEN-FIELD.
REQID-FILED
COUNT-FIELD
NUMERIC-COUNT
**** record structures below needs to be added in the new code ****
1
DCLGEN-RECORD.
5
DCLGEN-KEY.
10
DCLGEN-KEY-FIELD1
10
DCLGEN-KEY-FIELD2
.
.
5
DCLGEN-DATA.
10
DCLGEN-DATA-FIELD1
10
DCLGEN-DATA-FIELD2
.
.
28
****
WS-FUNCTION-CURSOR-1
88
WS-NEXT-CURSOR-1
88
WS-PREV-CURSOR-1
88
WS-NO-CURSOR-1
PIC X(01)
VALUE .
VALUE N.
VALUE P.
VALUE .
****
PROCEDURE DIVISION.
.
.
EXEC CICS
Vsam access call
END-EXEC.
.
.
Discussion below will assume this program template and will identify necessary changes to the code
corresponding to translation of each command.
29
3.2.1
READ
3.2.1.1 Function
Read a record from a file.
file to be read
INTO ( DATA-RECORD )
LENGTH ( DATA-REC-LENGTH)
RIDFLD ( KEY-RECORD)
KEYLENGTH ( KEY-REC-LENGTH)
GENERIC
GTEQ / EQUAL
RBA
RRN
UPDATE
TOKEN ( TOKEN-FIELD )
END-EXEC
30
EXEC SQL
SELECT
INTO
FROM
WHERE
*
{ :DCLGEN-RECORD fields. }
{ db2-tablename corresponding to vsam-filename }
{
If ( KEYLENGTH is specified )
{
identify exact fields from KEY-RECORD;
corresponding to these fields identify DCLGEN-KEY fields
}
else
{
all fields of DCLGEN-KEY will participate in WHERE clause
}
using DB2 column names and corresponding DCLGEN-KEY fields as
identified before and by using relational operator form the WHERE
clause
}
EXEC SQL
OPEN cursor-name
END-EXEC.
EXEC SQL
FETCH cursor-name
INTO : dclgen-record fields
END-EXEC.
EXEC SQL
OPEN cursor-name
END-EXEC.
For all the above cases:
31
3.2.2
STARTBR
3.2.2.1 Function
Start browse of a file. This is used to position the file position indicator at the desired record so that
VSAM read can be done from this record onwards.
file to be read
RIDFLD ( KEY-RECORD)
KEYLENGTH ( KEY-REC-LENGTH)
GENERIC
GTEQ / EQUAL
RBA
RRN
REQID ( REQID-FIELD )
END-EXEC
32
33
The STARTBR is translated to a OPEN CURSOR assuming that the next function will be READNEXT.
This is due to the fact that the same STARTBR command can be used either for a READNEXT or
READPREV function, and this will not be known at the time of translating the STARTBR to the OPEN
CURSOR.
IF SQLCODE = +0
{
Move the VSAM key values to the dclgen-record fields to use in the WHERE clause
SET WS-NEXT-CURSOR TO TRUE
EXEC SQL
OPEN NEXT-CURSORNAME
END-EXEC
}
34
3.2.3
READNEXT / READPREV
3.2.3.1 Function
Read next record or previous record during a browse of a file.
file to be read
INTO ( DATA-RECORD )
LENGTH ( DATA-REC-LENGTH)
RIDFLD ( KEY-RECORD)
KEYLENGTH ( KEY-REC-LENGTH)
RBA
RRN
REQID ( REQID-FIELD )
END-EXEC
35
36
:DCLGEN-RECORD
)
END-IF
FOR READPREV COMMAND
IF WS-PREV-CURSOR
(
EXEC SQL
FETCH PREV-CURSORNAME
INTO :DCLGEN-RECORD
END-EXEC
)
ELSE
IF WS-NEXT-CURSOR
(
EXEC SQL
CLOSE NEXT-CURSORNAME
END-EXEC
Move the VSAM key values to the dclgen-record fields to use in the WHERE clause
SET WS-PREV-CURSOR-1 TO TRUE
EXEC SQL
OPEN PREV-CURSORNAME
END-EXEC
EXEC SQL
FETCH PREV-CURSORNAME
INTO :DCLGEN-RECORD
END-EXEC
)
END-IF
* this logic is to take care of the RESETBR done on the file, with different criteria than the STARTBR
IF WS-PREV-CURSOR-1
(
EXEC SQL
FETCH PREV-CURSORNAME-1
INTO :DCLGEN-RECORD
END-EXEC
)
ELSE
IF WS-NEXT-CURSOR-1
(
EXEC SQL
CLOSE NEXT-CURSORNAME-1
END-EXEC
Move the VSAM key values to the dclgen-record fields to use in the WHERE clause
SET WS-PREV-CURSOR-1 TO TRUE
EXEC SQL
OPEN PREV-CURSORNAME-1
END-EXEC
EXEC SQL
37
MOVE DCLGEN-RECORD
.
.
TO
DATA-RECORD.
38
3.2.4
WRITE
3.2.4.1 Function
Write a record using the key values specified.
FROM ( DATA-RECORD )
LENGTH ( DATA-REC-LENGTH)
file to be read
RIDFLD ( KEY-RECORD)
KEYLENGTH ( KEY-REC-LENGTH)
RBA
RRN
END-EXEC
TO
INTO
ARE
DCLGEN-RECORD.
39
3.2.5
REWRITE
3.2.5.1 Function
Update a record in a file for the key values specified. REWRITE can be done after executing a READ FOR
UPDATE or it can be a random REWRITE also.
file to be read
FROM ( DATA-RECORD )
LENGTH ( DATA-REC-LENGTH)
TOKEN ( TOKEN-FIELD )
END-EXEC
TO
DCLGEN-RECORD
40
3.2.6
DELETE
3.2.6.1 Function
Delete a record from a file
RIDFLD ( KEY-RECORD)
KEYLENGTH ( KEY-REC-LENGTH)
GENERIC
RBA
RRN
TOKEN ( TOKEN-FIELD )
NUMERIC ( NUMERIC-COUNT )
END-EXEC
DCLGEN-KEY.
IF ( RIDFLD is specified )
{
MOVE KEY-RECORD to DCLGEN-KEY ;
41
If ( KEYLENGTH is specified )
{
identify exact fields from KEY-RECORD;
corresponding to these fields identify DCLGEN-KEY fields
}
else
{
all fields of DCLGEN-KEY will participate in WHERE clause
}
}
Relational Operator is =
using DB2 columnnames and corresponding DCLGEN-KEY fields as identified before and by using
relational operator , form the WHERE clause ;
EXEC SQL
DELETE (db2-tablename corresponding to vsam-filename )
WHERE ( where clause as formated before )
END-EXEC
MOVE SQLERRD(3)
TO
NUMERIC-COUNT
42
3.2.7
UNLOCK
3.2.7.1 Function
Release exclusive control of the file. UNLOCK file is usually done after a READ FOR UPDATE is
executed on the file and it is decided that no update needs to be done to the record. UNLOCK also needs to
be performed after VSAM MASSINSERT.
file to be unlocked
TOKEN ( TOKEN-FIELD )
END-EXEC
43
3.2.8
ENDBR
3.2.8.1 Function
End browse of a file.
file to be read
REQID ( REQID-FIELD )
END-EXEC
44
3.2.9
RESETBR
3.2.9.1 Function
Reset start of browse. The file position indicator is set to the position at the record with the new key values
specified.
file to be read
RIDFLD ( KEY-RECORD)
KEYLENGTH ( KEY-REC-LENGTH)
GENERIC
GTEQ / EQUAL
RBA
RRN
REQID ( REQID-FIELD )
END-EXEC
45
46
The WHERE EXISTS clause is used first to do a SELECT on the table. If any rows are found with
matching condition then only the cursor is opened. For this purpose the Standard Dummy table
SYSIBM.SYSDUMMY1 is used.
The translated code will look as given below :
EXEC SQL SELECT IBMREQD FROM SYSIBM.SYSDUMMY1
INTO :WS-IBMREQD
WHERE EXISTS
(SELECT * FROM db2-table-name
WHERE db2-column-name = (or >= ) : dclgen-record fields)
END-EXEC.
47
The RESETBR is translated to a OPEN CURSOR assuming that the next function will be READNEXT.
This is due to the fact that the same RESETBR command can be used either for a READNEXT or
READPREV function, and this will not be known at the time of translating the RESETBR to the OPEN
CURSOR.
IF SQLCODE = +0
{
Move the VSAM key values to the dclgen-record fields to use in the WHERE clause
SET WS-NEXT-CURSOR-1 TO TRUE
EXEC SQL
OPEN NEXT-CURSORNAME
END-EXEC
}
48
It is preferred that the only the required columns are selected in the query.
4.2
Batch programs which handle large volume of data and do updates, inserts or deletes on the DB2 tables will
have better performance if commit logic is added to commit the changes after the number of rows
processed reaches a predetermined value. However for any cursor operations for which the commit logic is
used should have the cursor defined with option WITH HOLD, otherwise the cursor position is lost after
the commit.
4.3
Only columns required to be updated should be retained in the update statements. This is especially true if
the column is indexed and is being updated unnecessarily.
49
5 Appendix
5.1.1
EXEC SQL
FETCH <file1>-OPEN-CURSOR
INTO <respective-fields>
END-EXEC
IF SQLCODE = 100
THEN
<at-end-imperative-stmts> | NEXT SENTENCE
ELSE
IF SQLCODE = 0
THEN
EXEC SQL
OPEN CURSOR dependant-cursor-1
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-1 UNTIL <db2-count> > <db2-array-1-size> AND
SQLCODE = 100
EXEC SQL
CLOSE CURSOR dependant-cursor-1
END-EXEC
...
EXEC SQL
OPEN CURSOR dependant-cursor-n
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-n UNTIL <db2-count> > <db2-array-n-size> AND
SQLCODE =100
EXEC SQL
CLOSE CURSOR dependant-cursor-n
END-EXEC
<not-at-end-imperative-stmts>
ELSE
DISPLAY ERROR IN FETCH
END-IF
END-IF.
50
5.1.2
EXEC SQL
FETCH <file1>-START-CURSOR
INTO <respective-fields>
END-EXEC
IF SQLCODE = 100
THEN
<at-end-imperative-stmts> | NEXT SENTENCE
ELSE
IF SQLCODE = 0
THEN
EXEC SQL
OPEN CURSOR dependant-cursor-1
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-1 UNTIL <db2-count> > <db2-array-1-size> AND
SQLCODE = 100
EXEC SQL
CLOSE CURSOR dependant-cursor-1
END-EXEC
...
EXEC SQL
OPEN CURSOR dependant-cursor-n
END-EXEC
MOVE 1 TO <db2-count>
MOVE <array-n-size> TO <DB2-ARRAY-n-SIZE>
PERFORM FETCH-PARA-n UNTIL <db2-count> <= <db2-array-n-size> AND
SQLCODE = 100
EXEC SQL
CLOSE CURSOR dependant-cursor-n
END-EXEC
<not-at-end-imperative-stmts>
ELSE
DISPLAY ERROR IN FETCH
END-IF
END-IF.
51
5.1.3
EXEC SQL
FETCH <file1>-READ-CURSOR
INTO <respective-fields>
END-EXEC
IF SQLCODE = 100
THEN
<at-end-imperative-stmts> | NEXT SENTENCE
ELSE
IF SQLCODE = 0
THEN
EXEC SQL
OPEN CURSOR dependant-cursor-1
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-1 UNTIL <db2-count> > <db2-array-1-size> AND
SQLCODE = 100
EXEC SQL
CLOSE CURSOR dependant-cursor-1
END-EXEC
...
EXEC SQL
OPEN CURSOR dependant-cursor-n
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-n UNTIL <db2-count> > <db2-array-n-size> AND
SQLCODE = 100
EXEC SQL
CLOSE CURSOR dependant-cursor-n
END-EXEC
<not-at-end-imperative-stmts>
ELSE
DISPLAY ERROR IN FETCH
END-IF
END-IF.
52
5.1.4
Random Read
EXEC SQL
SELECT <table-1-col-1> ... <table-1-col-n>,
...,
<table-n-col-1>...<table-n-col-n>
FROM <table-1> ...<table-n>
INTO <respective-fields>
END-EXEC
IF SQLCODE = 0
THEN
EXEC SQL
OPEN CURSOR dependant-cursor-1
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-1 UNTIL <db2-count> > <db2-array-1-size> AND SQLCODE =
100
EXEC SQL
CLOSE CURSOR dependant-cursor-1
END-EXEC
...
EXEC SQL
OPEN CURSOR dependant-cursor-n
END-EXEC
MOVE 1 TO <db2-count>
PERFORM FETCH-PARA-n UNTIL <db2-count> > <db2-array-n-size> AND SQLCODE = 100
EXEC SQL
CLOSE CURSOR dependant-cursor-n
END-EXEC
<not-invalid-key-imperative-stmts>
ELSE
<invalid-key-imperative-statements> | NEXT SENTENCE
END-IF.
53
5.1.5
Insert
EXEC SQL
INSERT INTO <table-1>(<table-1-col-1> ... <table-1-col-n>)
VALUES (<respective-fields>)
END-EXEC.
IF SQLCODE = 0
THEN
EXEC SQL
INSERT INTO <table-2>(<table-2-col-1> ... <table-2-col-n>)
VALUES (<respective-fields>)
END-EXEC
END-IF
...
IF SQLCODE = 0
THEN
EXEC SQL
INSERT INTO <table-n>(<table-n-col-1> ... <table-n-col-n>)
VALUES (<respective-fields>)
END-EXEC
END-IF
IF SQLCODE = 0
THEN
MOVE 1 TO <db2-count>
PERFORM INSERT-PARA-1 UNTIL <db2-count> > <db2-array-1-size> AND SQLCODE = 0
...
MOVE 1 TO <db2-count>
PERFORM INSERT-PARA-n UNTIL <db2-count> > <db2-array-n-size> AND SQLCODE = 0
END-IF
IF SQLCODE = 0
THEN
<not-invalid-key-statements> | NEXT SENTENCE
ELSE
<invalid-key-statements> | DISPLAY Error In Insert
END-IF
54
5.1.6
Random Rewrite
EXEC SQL
UPDATE <table-1>
SET
<table-1-col-1> = <table-1-col-1-fld-1>,
...
<table-1-col-n> = <table-1-col-n-fld-n>
WHERE <table-1-key-col-1> = <table-1-key-col-1-key-fld-1>,
...
<table-1-key-col-n> = <table-1-key-col-n-key-fld-n>
END-EXEC
IF SQLCODE = 0
THEN
EXEC SQL
UPDATE <table-2>
SET
<table-2-col-1> = <table-2-col-1-fld-1>,
...
<table-2-col-n> = <table-2-col-n-fld-n>
WHERE<table-2-key-col-1> = <table-2-key-col-1-key-fld-1>,
...
<table-2-key-col-n> = <table-2-key-col-n-key-fld-n>
END-EXEC
END-IF
...
IF SQLCODE = 0
THEN
EXEC SQL
UPDATE <table-n>
SET
<table-n-col-1> = <table-n-col-1-fld-1>,
...
<table-n-col-n> = <table-n-col-n-fld-n>
WHERE<table-n-key-col-1> = <table-n-key-col-1-key-fld-1>,
...
<table-n-key-col-n> = <table-n-key-col-n-key-fld-n>
END-EXEC
END-IF
IF SQLCODE = 0
THEN
EXEC SQL
OPEN CURSOR dependant-updatable-cursor-1
END-EXEC
MOVE 1 TO <db2-count>
PERFORM UPDATE-PARA-1 UNTIL <db2-count> > <db2-array-1-size> AND SQLCODE = 0
EXEC SQL
CLOSE CURSOR dependant-updatable-cursor-1
END-EXEC
...
EXEC SQL
OPEN CURSOR dependant-updatable-cursor-n
END-EXEC
MOVE 1 TO <db2-count>.
PERFORM UPDATE-PARA-n UNTIL <db2-count> > <db2-array-n-size> AND SQLCODE = 0
EXEC SQL
CLOSE CURSOR dependant-updatable-cursor-n
END-EXEC
55
56
5.1.7
Delete
EXEC SQL
DELETE <table-1>
WHERE<table-1-key-col-1> = <table-1-key-col-1-key-fld-1>,
...
<table-1-key-col-n> = <table-1-key-col-n-key-fld-n>
END-EXEC.
IF SQLCODE = 0
THEN
EXEC SQL
DELETE <table-2>
WHERE<table-2-key-col-1> = <table-2-key-col-1-key-fld-1>,
...
<table-2-key-col-n> = <table-2-key-col-n-key-fld-n>
END-EXEC.
END-IF
...
IF SQLCODE = 0
THEN
EXEC SQL
DELETE <table-n>
WHERE<table-n-key-col-1> = <table-n-key-col-1-key-fld-1>,
...
<table-n-key-col-n> = <table-n-key-col-n-key-fld-n>
END-EXEC.
END-IF
IF SQLCODE = 0
THEN
<not-invalid-key-statements> | NEXT SENTENCE
ELSE
<invalid-key-statements> | DISPLAY Error In Delete
END-IF
57
5.1.8
OPEN-CURSOR
58
5.1.9
START-CURSOR
EXEC SQL
DECLARE <file1>-START-RK-CURSOR CURSOR FOR
SELECT <table-1-col-1> ... <table-1-col-n>,
...,
<table-n-col-1>...<table-n-col-n>
FROM <table-1> ...<table-n>
WHERE <table-1-key-col-1> >= <rec-key-fld-1>,
<table-1-key-col-n> >= <rec-key-fld-n>,
<table-2-key-col-n> = <table-1-key-col-1>
<table-2-key-col-n> = <table-1-key-col-n>
... ,
<table-n-key-col-n> = <table-1-key-col-1>
<table-n-key-col-n> = <table-1-key-col-n>
ORDER BY <table-1-key-col-1> ... <table-1-key-col-n>
END-EXEC
59
5.1.10 READ-CURSOR
EXEC SQL
DECLARE <file1>-READ-RK-CURSOR CURSOR FOR
SELECT <table-1-col-1> ... <table-n-col-n>,
...,
<table-n-col-1>...<table-n-col-n>
FROM <table-1> ...<table-n>
WHERE <table-1-key-col-1> >= <rec-key-fld-1>,
<table-1-key-col-n> >= <rec-key-fld-n>,
<table-2-key-col-n> = <table-1-key-col-1>
<table-2-key-col-n> = <table-1-key-col-n>
... ,
<table-n-key-col-n> = <table-1-key-col-1>
<table-n-key-col-n> = <table-1-key-col-n>
ORDER BY <table-1-key-col-1> ... <table-1-key-col-n>
END-EXEC
60
5.1.11 Dependant-Cursor-1
EXEC SQL
DECLARE <dependant-cursor-1> CURSOR FOR
SELECT <array-1-table-1-col-1> ... <array-1-table-n-col-n>,
...,
<array-1-table-n-col-1>...<array-1-table-n-col-n>
FROM <array-1-table-1> ...<array-1-table-n>
END-EXEC
5.1.12 Dependant-Cursor-n
EXEC SQL
DECLARE <dependant-cursor-n> CURSOR FOR
SELECT <array-n-table-1-col-1> ... <array-n-table-n-col-n>,
...,
<array-n-table-n-col-1>...<array-n-table-n-col-n>
FROM <array-n-table-1> ...<array-n-table-n>
END-EXEC
5.1.13 Dependant-Updatable-Cursor-1
EXEC SQL
DECLARE <dependant-updatable-cursor-1> CURSOR FOR
SELECT <array-1-table-1-col-1> ... <array-1-table-1-col-n>
FROM <array-1-table-1> FOR UPDATE OF <columns>
END-EXEC
5.1.14 Dependant-Updatable-Cursor-n
EXEC SQL
DECLARE <dependant-updatable-cursor-n> CURSOR FOR
SELECT <array-n-table-1-col-1> ... <array-n-table-1-col-n>
FROM <array-n-table-1> FOR UPDATE OF <columns>
END-EXEC
61
5.1.15 FETCH-PARA-1
EXEC-SQL
FETCH dependant-cursor-1
INTO <db2-array-1-table-1-col-1-fld-1>, .. <db2-array-1-table-1-col-n-fld-n>
...
<db2-array-1-table-n-col-1-fld-1>, .. <db2-array-1-table-n-col-n-fld-n>
END-EXEC
MOVE <db2-array-1> TO <array-1>(<db2-count>)
COMPUTE <db2-count> = <db2-count> + 1
5.1.16 FETCH-PARA-n
EXEC-SQL
FETCH dependant-cursor-n
INTO <db2-array-1-table-1-col-1-fld-1>, .. <db2-array-1-table-1-col-n-fld-n>
...
<db2-array-1-table-n-col-1-fld-1>, .. <db2-array-1-table-n-col-n-fld-n>
END-EXEC.
MOVE <db2-array-1> TO <array-n>(<db2-count>)
COMPUTE <db2-count> = <db2-count> + 1
62
5.1.17 INSERT-PARA-1
MOVE <ARRAY-1>(<db2-count>) TO <DB2-ARRAY-1>.
EXEC SQL
INSERT INTO <array-1-table-1>(<array-1-table-1-col-1>... <array-1-table-1-col-n>)
VALUES (<db2-array-1-table-1-col-1-fld-1>, .. <db2-array-1-table-1-col-n-fld-n>)
END-EXEC
IF SQLCODE = 0
THEN
EXEC SQL
INSERT INTO <array-1-table-2>(<array-1-table-2-col-1> ... <array-1-table2-col-n>)
VALUES (<db2-array-1-table-2-col-1-fld-1>, .. <db2-array-1-table-2-col-nfld-n>)
END-EXEC
END-IF
...
IF SQLCODE = 0
THEN
EXEC SQL
INSERT INTO <array-1-table-n>(<array-1-table-n-col-1> ... <array-1-tablen-col-n>)
VALUES (<db2-array-1-table-n-col-1-fld-1>, .. <db2-array-1-table-n-col-nfld-n>)
END-EXEC
END-IF
COMPUTE <db2-count> = <db2-count> + 1
5.1.18 INSERT-PARA-n.
MOVE <array-n>(<db2-count>) TO <db2-array-n>.
EXEC SQL
INSERT INTO <array-n-table-1>(<array-n-table-1-col-1>... <array-n-table-1-col-n>)
VALUES (<db2-array-1-table-1-col-1-fld-1>, .. <db2-array-1-table-1-col-n-fld-n>)
END-EXEC.
IF SQLCODE = 0
THEN
EXEC SQL
INSERT INTO <array-n-table-2>(<array-n-table-2-col-1> ... <array-n-table2-col-n>)
VALUES (<db2-array-1-table-2-col-1-fld-1>, .. <db2-array-1-table-2-col-nfld-n>)
END-EXEC
END-IF
...
IF SQLCODE = 0
THEN
EXEC SQL
INSERT INTO <array-n-table-n>(<array-n-table-n-col-1> ... <array-n-tablen-col-n>)
VALUES (<db2-array-1-table-n-col-1-fld-1>, .. <db2-array-1-table-n-col-nfld-n>)
END-EXEC
END-IF
COMPUTE <db2-count> = <db2-count> + 1
63
5.1.19 UPDATE-PARA-1
EXEC-SQL
FETCH
INTO <db2-array-1-table-1-col-1-fld-1>, .. <db2-array-1-table-1-col-n-fld-n>
...
<db2-array-1-table-n-col-1-fld-1>, .. <db2-array-1-table-n-col-n-fld-n>
END-EXEC
MOVE <array-1>(<db2-count>) TO <db2-array-1>
EXEC SQL
UPDATE <array-1-table-1>
SET
<array-1-table-1-col-1> = <db2-array-1-table-1-col-1-fld-1>,
...
<array-1-table-1-col-n> = <db2-array-1-table-1-col-n-fld-n>
WHERE CURRENT OF
END-EXEC
COMPUTE <db2-count> = <db2-count> + 1
5.1.20 UPDATE-PARA-n
EXEC-SQL
FETCH
INTO <db2-array-1-table-1-col-1-fld-1>, .. <db2-array-1-table-1-col-n-fld-n>
...
<db2-array-1-table-n-col-1-fld-1>, .. <db2-array-1-table-n-col-n-fld-n>
END-EXEC
MOVE <array-1>(<db2-count>) TO <db2-array-1>
EXEC SQL
UPDATE <array-1-table-1>
SET
<array-1-table-1-col-1> = <db2-array-1-table-1-col-1-fld-1>,
...
<array-1-table-1-col-n> = <db2-array-1-table-1-col-n-fld-n>
WHERE CURRENT OF
END-EXEC
COMPUTE <db2-count> = <db2-count> + 1
64
65