Insert 1 Call COBOL stored procedure A Insert 2 Call COBOL routine B Commit Insert 3 Rollback Insert 4 Insert 5 Commit
DB2 inserts records 1,2,4 and 5.
However, with SQL Server, when an application calls a stored procedure flow of any kind, it forms a nested transaction. The outermost transaction of this nested transaction ultimately determines whether to commit or rollback the work of all the transactions contained therein, regardless of what those transactions did. In the above example, because the COBOL client application starts the nested transaction and ends it with a COMMIT, all 5 records are inserted; if the COBOL client application ends with a ROLLBACK instead, none of the 5 records are inserted.
This behavior is not acceptable if you want your migrated SQL Server application to mimic DB2 transaction chaining.
With SQL Server, you can use a combination of implicit_transactions and savepoints. When implicit_transactions are set to OFF or to ON, this positions the lead transaction that commits the workload to SQL Server and releases locks. Savepoints ensure that serially chained COMMIT and ROLLBACK transactions behave as you intend them to.
HCOSS offers three solutions to mimic mainframe DB2 transaction behavior with COBOL stored procedures. The first two begin with implicit_transactions set to OFF, and the third begins with implicit_transactions set to ON. Here, we provide a description of each solution and a summary of the advantages and disadvantages for each.
HCOSS does the following:
ON ENTRY | EXEC SQL COMMIT | EXEC SQL ROLLBACK | ON EXIT (return) | |
---|---|---|---|---|
Lead (called) Stored Procedure |
start transaction set savepoint |
commit reset savepoint |
roll back to savepoint commit reset savepoint |
Option 1:
Option 2: Use SQL(OPTION=SPCOMMITONRETURN) |
Nested Stored Proceduress |
reset savepoint |
roll back to savepoint |
||
Called COBOL Routines |
commit reset savepoint |
roll back to savepoint commit reset savepoint |
HCOSS does the following:
ON ENTRY | EXEC SQL COMMIT | EXEC SQL ROLLBACK | ON EXIT (return) | |
---|---|---|---|---|
Lead (called) SP |
reset savepoint |
roll back to savepoint |
||
Nested SPs |
reset savepoint |
roll back to savepoint |