For each data file on which you want transaction processing active, use the WITH ROLLBACK clause when you define the data file using the SELECT statement in your COBOL program.
For example:
select test-file assign to "test.dat" organization indexed record key prime-key lock mode manual with rollback ...
This sample code specifies that transaction processing is active on the file test.dat.
In your program, use the COMMIT verb to make the updates in a transaction permanent. Use the ROLLBACK verb to remove the updates in a transaction from the data files.
The COMMIT and ROLLBACK verbs work on all data files involved in a transaction. This means that you cannot check the status of the COMMIT or ROLLBACK operation using the file status of any one data file. Instead, you must call the File Handling Redirector module to check the status of the COMMIT or ROLLBACK. The entry point to call in the File Handling Redirector module module is fs_status. The format of the call is:
call "fs_status" returning t-status end-call
where t-status is defined as:
01 t-status pic x(2) comp-x.
A non-zero value returned in t-status indicates that the COMMIT or ROLLBACK operation failed.
For example:
1 SELECT test-file ASSIGN TO "test.dat" 2 LOCK MODE MANUAL WITH ROLLBACK 3 ... 4 OPEN I-O test-file 5 ... 6 move 1 to prime-key 7 WRITE test-file-record 8 ... 9 COMMIT 10 call "fs_status" 11 returning t-status 12 end-call 13 if t-status < > 0 14 display "Warning - Commit operation failed" 15 end-if 16 move 2 to prime-key 17 WRITE test-file-record 18 ... 19 ROLLBACK 20 call "fs_status" 21 returning t-status 22 end-call 23 if t-status < > 0 24 display "Warning - Rollback operation failed" 25 end-if 26 WRITE test-file-record 27 ...
where:
Lines 1 - 2: |
SELECT test-file ASSIGN TO "test.dat" LOCK MODE MANUAL WITH ROLLBACK Specifies transaction processing for this data file. |
Line 7: |
WRITE test-file-record Starts a new transaction. |
Line 9: |
COMMIT Makes the updates to test-file permanent and terminates the transaction. |
Lines 10 - 15: |
call "fs_status" returning t-status end-call if t-status < > 0 display "Warning - Commit operation failed" end-if Checks the status of the COMMIT operation. |
Line 17: |
WRITE test-file-record Starts a new transaction. |
Line 19: |
ROLLBACK Removes the updates made to test-file and terminates the transaction. |
Lines 20 - 25: |
call "fs_status" returning t-status end-call if t-status < > 0 display "Warning - Rollback operation failed" end-if Checks the status of the ROLLBACK operation. |
Line 26: |
WRITE test-file-record Starts a new transaction. |
You do not need to change the configuration of the Fileshare Client to enable transaction processing.