Processing Files and Records
6.5 Updating Files
Example 6–37 shows how to extend a sequential file.
Example 6–37 Extending a Sequential File
IDENTIFICATION DIVISION.
PROGRAM-ID. SEQ04.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TRANS-FILE ASSIGN TO "TRANS".
DATA DIVISION.
FILE SECTION.
FD
TRANS-FILE.
01
TRANSACTION-RECORD
PIC X(25).
PROCEDURE DIVISION.
A000-BEGIN.
OPEN EXTEND TRANS-FILE.
PERFORM A100-WRITE-RECORD
UNTIL TRANSACTION-RECORD = "END".
CLOSE TRANS-FILE.
STOP RUN.
A100-WRITE-RECORD.
DISPLAY "Enter next record
- X(25)".
DISPLAY "Enter END to terminate the session".
DISPLAY "-------------------------".
ACCEPT TRANSACTION-RECORD.
IF TRANSACTION-RECORD NOT = "END"
WRITE TRANSACTION-RECORD.
Without the EXTEND mode, a Compaq COBOL program would have to open the
input file, copy it to an output file, and add records to the output file.
6.5.2 Updating a Relative File
A program updates a relative file with the WRITE, REWRITE, and DELETE
statements. The WRITE statement adds a record to the file. Only the REWRITE
and DELETE statements change the contents of records already existing in the
file. In either case, adequate backup must be available in the event of error.
Sections 6.5.2.1 and 6.5.2.2 explain how to rewrite and delete relative records,
respectively.
6.5.2.1 Rewriting a Relative File
The REWRITE statement logically replaces a record in a relative file; the original
contents of the record are lost. Two options are available for rewriting relative
records:
•
Sequential access mode rewriting
•
Random access mode rewriting
Rewriting Relative Records in Sequential Access Mode
Rewriting relative records in sequential access mode involves the following:
1.
Specifying ORGANIZATION IS RELATIVE in the Environment Division
SELECT clause
2.
Specifying ACCESS MODE IS SEQUENTIAL in the Environment Division
SELECT clause
3.
Opening the file for I-O
6–50 Processing Files and Records
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......