home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
viscobv6.zip
/
vac22os2
/
ibmcobol
/
samples
/
purpt
/
y2kx2pg.sqb
< prev
next >
Wrap
Text File
|
1997-03-13
|
19KB
|
467 lines
Identification Division.
Program-ID. Y2KX2PG.
Author. TE
******************************************************************
* *
* Licensed Material - Property of IBM *
* *
* 5622-793 (C) Copyright IBM Corp., 1997 *
* All rights reserved *
* *
* US Government Users Restricted Rights - Use, *
* duplication or disclosure restricted by GSA ADP *
* Schedule Contract with IBM Corp. *
* *
******************************************************************
* *
* Y2KX2PG is an example program that can be called from *
* the DCZY2KR program using the Y2KEXIT capability. This *
* program takes the information passed to it from the DCZY2KR *
* program and then updates a set of DB2 tables with the *
* information. *
* *
* You will have to do the following things to use this *
* exit: *
* *
* 1) Install OS/2 DB2. *
* 2) Run the command file Y2KX2CD.CMD to create the DB2 *
* database and tables. You may need to modify this *
* command file to allocate the database on the drive you *
* want. *
* 3) Run the command file Y2KX2PR.CMD to create the *
* exit Y2KX2PG.DLL. *
* 4) Change the source in DCZY2KR to enable the exit. *
* Set the VALUE clause for the Y2K-Exit-Flag data item to 'Y'.*
* Set the VALUE clause for the Y2K-Exit-Program data item *
* to 'Y2KX2PG'. *
* 5) Compile and link the modified DCZY2KR program. *
* *
* Associated files: *
* * Y2KX2DC.CMD - Command file that creates the DB2 database *
* and tables used by this program. *
* * Y2KX2DC.DEF - DEF file for this program. *
* * Y2KX2PR.CMD - command file to create a DLL for this program. *
* *
*================================================================*
Environment Division.
*================================================================*
Configuration Section.
Input-Output Section.
File-Control.
I-O-Control.
*================================================================*
Data Division.
*================================================================*
*================================================================*
File Section.
*================================================================*
*================================================================*
Working-Storage Section.
*================================================================*
COPY "sql.cbl".
COPY "sqlcodes.cbl".
COPY "sqlenv.cbl".
COPY "sqlstate.cbl".
COPY "sqlutil.cbl".
COPY "sqlaprep.cbl".
EXEC SQL INCLUDE SQLCA END-EXEC.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 program-name pic x(30).
01 source-file-name pic x(56).
01 data-item-name pic x(30).
* Data item qid is a timestamp. When grouped with
* data-item-name we have a unique key.
01 data-item-qid pic x(18).
* Data item qualified flag.
01 data-item-qaul-flag pic x(1).
* Line where the data item was defined.
01 data-item-def-line pic X(6).
* Data item name with full qualification.
01 data-item-qname.
49 data-item-qname-len pic s9(4) comp-5.
49 data-item-qname-str pic x(1500).
* Cause data.
01 cause-data pic x(11).
EXEC SQL END DECLARE SECTION END-EXEC.
* turn off SQL EXCEPTION processing
EXEC SQL WHENEVER SQLWARNING CONTINUE END-EXEC.
EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.
EXEC SQL WHENEVER NOT FOUND CONTINUE END-EXEC.
* Data items for DISPLAY
01 PN PIC X(9) VALUE 'Y2KX2PG: '.
01 BN PIC X(9) VALUE ' '.
01 DB-func PIC X(60) value spaces.
* Misc items.
77 WORKFLAG PIC X(1).
77 J2 PIC 9(2).
77 error-code Pic 9(4).
*----------------------------------------------------------------*
* Data items used for the Y2K-EXIT. *
*----------------------------------------------------------------*
* Function code values. *
77 Y2K-EXIT-func-init Pic 9(4) Value 0.
77 Y2K-EXIT-func-pgm-name Pic 9(4) Value 1.
77 Y2K-EXIT-func-dataitem-def Pic 9(4) Value 2.
77 Y2K-EXIT-func-dataitem-rsn Pic 9(4) Value 3.
77 Y2K-EXIT-func-source Pic 9(4) Value 4.
77 Y2K-EXIT-func-term Pic 9(4) Value 9000.
77 Y2K-EXIT-func-term-error Pic 9(4) Value 9001.
*================================================================*
Linkage Section.
*================================================================*
* Function code. *
01 Y2K-EXIT-func Pic 9(4).
01 Y2k-exit-pgm-name Pic X(30).
01 y2k-exit-file-name.
03 y2k-File-Name-CharZ Pic X
Occurs 1 to 256 Times
Depending on
y2k-exit-file-name-len.
01 y2k-exit-file-Name-Len Pic 9(3).
01 y2k-exit-item-name Pic x(30).
01 y2k-exit-item-q Pic x(01).
01 Y2K-EXIT-item-line Pic 9(6).
01 y2k-exit-cause Pic x(11).
01 y2k-exit-kind Pic x(03).
01 y2k-Qualified-Name-Struct.
02 y2k-Qualified-Name-Size Pic 9999.
02 y2k-Qualified-Name.
03 y2k-Qualified-Name-Char
Occurs 1 to 1500 Times
Depending on y2k-Qualified-Name-Size
Pic X.
* Place holder linkage section items for parameters
* that change from call to call.
01 y2k-exit-data1 Pic X(1).
01 y2k-exit-data2 Pic X(1).
01 y2k-exit-data3 Pic X(1).
01 y2k-exit-data4 Pic X(1).
01 y2k-exit-data5 Pic X(1).
*================================================================*
Procedure Division Using Y2K-EXIT-func
y2k-exit-pgm-name
y2k-exit-file-name
y2k-exit-file-name-len
y2k-exit-data1
y2k-exit-data2
y2k-exit-data3
y2k-exit-data4
y2k-exit-data5
.
*================================================================*
*==============================================================*
* Main processing section starts *
*==============================================================*
Main-processing Section.
move 0 to error-code
evaluate Y2K-Exit-func
* If initialize, connect to the database.
when Y2K-EXIT-func-init
Perform Connect-to-DB
* If terminate normally, commit the database updates.
when Y2K-EXIT-func-term
Perform Commit-DB-Update
* If terminate with error, rollback the database updates.
when Y2K-EXIT-func-term-error
Perform Rollback-DB-Update
* For a new program, remove any existing rows for this
* program.
when Y2K-EXIT-func-pgm-name
move y2k-exit-pgm-name to program-name
Perform Remove-pgm-from-tables
* For a data item definition call, add a row to the
* data item table.
when Y2K-EXIT-func-dataitem-def
* Set addressability to incoming data.
set address of y2k-exit-item-name to
address of y2k-exit-data1
set address of y2k-exit-item-q to
address of y2k-exit-data2
set address of y2k-Qualified-Name-Struct to
address of y2k-exit-data3
set address of y2k-exit-item-line to
address of y2k-exit-data4
* Move data into host variables.
move y2k-exit-pgm-name to program-name
move y2k-exit-file-name to source-file-name
move y2k-exit-item-name to data-item-name
move y2k-exit-item-q to data-item-qaul-flag
move y2k-exit-item-line to data-item-def-line
move y2k-Qualified-Name-Size to
data-item-qname-len
move y2k-Qualified-Name to
data-item-qname-str
* Add the row to the item table.
Perform Add-row-to-item-tbl
* For a reason call, add a row to the reason table.
when Y2K-EXIT-func-dataitem-rsn
* Set addressability to incoming data.
set address of y2k-exit-item-name to
address of y2k-exit-data1
set address of y2k-exit-cause to
address of y2k-exit-data3
* Move interesting data into host variables.
* No need to move the other data since it was already
* moved on the data item definition call.
move y2k-exit-cause to cause-data
Perform Add-row-to-reason-tbl
* For a source file call, add a row to the source table.
when Y2K-EXIT-func-source
move y2k-exit-pgm-name to program-name
move y2k-exit-file-name to source-file-name
Perform Add-row-to-source-tbl
when other
continue
end-evaluate
* Set the return code for the caller so it will know if
* processing went well or not.
move error-code to return-code
goback
.
******************************************************************
* Connect to the database.
******************************************************************
Connect-to-DB.
Move 'CONNECT to PURPT' to DB-func
EXEC SQL CONNECT TO PURPT END-EXEC
if sqlcode not equal to 0 then
Perform DB-ERROR
end-if
.
******************************************************************
* Commit the DB updates.
******************************************************************
Commit-DB-Update.
Move 'COMMIT' to DB-func
EXEC SQL COMMIT WORK END-EXEC
if sqlcode not equal to 0 then
Perform DB-ERROR
end-if
.
******************************************************************
* Rollback the DB Updates.
******************************************************************
Rollback-DB-Update.
Move 'ROLLBACK' to DB-func
EXEC SQL ROLLBACK WORK END-EXEC
if sqlcode not equal to 0 then
Perform DB-ERROR
end-if
.
******************************************************************
* Before adding the rows for the program, delete any
* existing rows for the program.
******************************************************************
Remove-pgm-from-tables.
Move 'DELETE program from RSNTBL' to DB-func
EXEC SQL DELETE FROM RSNTBL
where progname = :program-name
END-EXEC
if sqlcode not equal to 0
and sqlcode not equal to 100 then
Perform DB-ERROR
end-if.
Move 'DELETE program from DITEMTBL' to DB-func
EXEC SQL DELETE FROM DITEMTBL
where progname = :program-name
END-EXEC
if sqlcode not equal to 0
and sqlcode not equal to 100 then
Perform DB-ERROR
end-if.
Move 'DELETE program from SRCTBL' to DB-func
EXEC SQL DELETE FROM SRCTBL
where progname = :program-name
END-EXEC
if sqlcode not equal to 0
and sqlcode not equal to 100 then
Perform DB-ERROR
end-if
.
******************************************************************
* Add a row for the program and source to the SRCTBL.
******************************************************************
Add-row-to-source-tbl.
EXEC SQL INSERT INTO SRCTBL
VALUES(:program-name,
:source-file-name)
END-EXEC
if sqlcode not equal to 0
Perform DB-ERROR
end-if
.
******************************************************************
* Add a row for the data item to the DITEMTBL.
******************************************************************
Add-row-to-item-tbl.
* Initialize the items that are used to build a unique id
* for a data item.
move function current-date(1:16) to data-item-qid(1:16)
move 0 to j2
* Initialize the flag that controls the perform loop.
move '0' to workflag
* Loop until the insert works, or there is an error.
perform with test after until workflag = '1'
* Append a value on to the unique item id.
move j2 to data-item-qid(17:2)
EXEC SQL INSERT INTO
DITEMTBL(ITEMNAME,
ITEMQID,
PROGNAME,
SRCNAME,
ITEMQTYP,
ITEMDLIN,
ITEMQNAM)
VALUES(:data-item-name,
:data-item-qid,
:program-name,
:source-file-name,
:data-item-qaul-flag,
:data-item-def-line,
:data-item-qname)
END-EXEC
evaluate sqlcode
* If the insert went OK, set flag to get out of the loop.
when 0
move '1' to workflag
* If the row already exists, bump the counter and try
* again.
when 100
add 1 to j2
on size error
Display pn 'Unable to add variable.'
move '1' to workflag
end-add
when other
* Some unexpected SQL error, get out.
Perform DB-ERROR
move '1' to workflag
end-evaluate
end-perform
.
******************************************************************
* Add a row for the reason why a data item was chosen to the
* RSNTBL.
******************************************************************
Add-row-to-reason-tbl.
Move 'INSERT reason into RSNTBL' to DB-func
EXEC SQL INSERT INTO
RSNTBL(ITEMNAME,
ITEMQID,
PROGNAME,
SRCNAME,
CAUSE)
VALUES(:data-item-name,
:data-item-qid,
:program-name,
:source-file-name,
:cause-data)
END-EXEC
* No problem if row already exists.
if sqlcode not equal to 0
and sqlcode not equal to SQLA-RC-INV-INSERT
Perform DB-ERROR
end-if
.
******************************************************************
* DB-ERROR: Come here for unexpected DB errors and DISPLAY
* diagnostic info.
******************************************************************
DB-ERROR.
EXEC SQL WHENEVER SQLWARNING CONTINUE END-EXEC.
EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.
DISPLAY pn "DB ERROR!! " sqlcode
DISPLAY bn "DB function = " DB-func
DISPLAY bn "sqlcode = " sqlcode
EXEC SQL ROLLBACK WORK END-EXEC
if sqlcode not equal to 0 then
DISPLAY pn "ROLLBACK FAILED!"
DISPLAY bn "sqlcode = " sqlcode
end-if
move 1 to error-code
.
*================================================================*
End Program Y2KX2PG.
*================================================================*
*================================================================*
* End of Y2KX2PG exit *
*================================================================*
*================================================================*