Processing Files and Records
6.3 Creating and Processing Files
6.
If the file characteristics specified by the program attempting an OPEN
operation differ from the characteristics specified when the file was created,
the OPEN statement fails.
If the file is on magnetic tape, the I/O system rewinds the tape. (To close a file
on tape without rewinding the tape, use the NO REWIND phrase.) This speeds
processing when you want to write another file beyond the end of the first file, as
in the following example:
CLOSE MASTER-FILE NO REWIND.
You can also close a file and prevent your program from opening that file again in
the same run, as in the following example:
CLOSE MASTER-FILE WITH LOCK.
6.3.2 File Handling for Sequential and Line Sequential Files
Creating a sequential or line sequential file involves the following:
1.
Opening the file for OUTPUT or EXTEND
2.
Executing valid I/O statements
3.
Closing the file
By default, Compaq COBOL assumes sequential organization and sequential
access mode. (See Example 6–22.)
Example 6–22 Creating a Sequential File
IDENTIFICATION DIVISION.
PROGRAM-ID. SEQ01.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TRANS-FILE ASSIGN TO "TRANS.DAT".
DATA DIVISION.
FILE SECTION.
FD
TRANS-FILE.
01
TRANSACTION-RECORD
PIC X(25).
PROCEDURE DIVISION.
A000-BEGIN.
OPEN OUTPUT TRANS-FILE.
PERFORM A010-PROCESS-TRANS
UNTIL TRANSACTION-RECORD = "END".
CLOSE TRANS-FILE.
STOP RUN.
A010-PROCESS-TRANS.
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.
6–26 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: ......