****************************************
* Program name: rewrite.cbl
* This program demonstrate the use
* of the REWRITE command.
*
* Copyright 2000 Deskware, Inc.
****************************************
* Syntax: REWRITE TO .
*
1 eof PIC 9 VALUE 0.
1 rec_found PIC 9 VALUE 0.
1 rec_position PIC 999999.
1 test-file PIC X(n) VALUE `TEST.DAT`.
FD test-file RECORD IS 9 BYTES.
1 record_var.
5 field_1 PIC X(4).
5 field_2 PIC X(5).
1 customer_of_interest PIC X(n) VALUE `Dave`.
1 new_field_2_val PIC X(n) VALUE `Davie`.
OPEN test_file FOR UPDATING.
PERFORM VARYING rec_position FROM 1 BY 1 UNTIL eof OR rec_found
READ test_file INTO record_var
AT END MOVE 1 to eof
IF field_1 = customer_of_interest
MOVE 1 TO rec_found
MOVE new_field_2_val TO field_2
REWRITE record_var TO test_file
END-IF
END-PERFORM.
CLOSE test_file.
IF eof
DISPLAY `Customer record of interest was not found.`
END-IF.