Skip to content

ROLLBACK Statement

The ROLLBACK statement causes a FILE I-O operation to be cancelled. ROLLBACK is only available when underlying file system supports it.

General Format:

ROLLBACK.

General Rules:

  1. The ROLLBACK statement causes unwritten file buffers to not be written to the target file.
  2. After cancelling the unwritten FILE I-O operations, the ROLLBACK statement releases record and file locks held by the target file.

Code Sample:

       IDENTIFICATION DIVISION. 
       PROGRAM-ID. ROLLBACK-1. 
       ENVIRONMENT DIVISION. 
       INPUT-OUTPUT SECTION. 
       FILE-CONTROL. 
              SELECT RESWORDS ASSIGN TO "RESWORDS" 
              ORGANIZATION IS INDEXED 
              ACCESS IS DYNAMIC 
              RECORD KEY IS RESERVED-WORD 
              FILE STATUS IS RESWORDS-STAT. 

       DATA DIVISION. 
       FILE SECTION. 
       FD RESWORDS. 
       01 RESWORDS-RECORD. 
              03 RESERVED-WORD     PIC X(30). 

       WORKING-STORAGE SECTION. 
       77 RESWORDS-STATPIC XX. 
              88 END-OF-RESWORDS VALUE"10". 
       77 DUMMY                    PIC X. 

       PROCEDURE DIVISION. 
       MAIN. 
              OPEN OUTPUT RESWORDS. 
              MOVE "ACCEPT" TO RESERVED-WORD. 
              WRITE RESWORDS-RECORD. 
              ROLLBACK. 
              DISPLAY "ROLLBACK-1 FINISHED!" LINE 10 COL 10. 
              ACCEPT DUMMY LINE 10 COL 30. 

              CLOSE RESWORDS. 
              STOP RUN.
Back to top