Processing Files and Records
6.3 Creating and Processing Files
Creating a Relative File in Sequential Access Mode
When your program creates a relative file in sequential access mode, the I/O
system does not use the relative key. Instead, it writes the first record in the file
at relative record number 1, the second record at relative record number 2, and
so on, until the program closes the file. If you use the RELATIVE KEY IS clause,
the compiler moves the relative record number of the record being written to
the relative key data item. Example 6–24 writes 10 records with relative record
numbers 1 to 10.
Example 6–24 Creating a Relative File in Sequential Access Mode
IDENTIFICATION DIVISION.
PROGRAM-ID. REL02.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FLAVORS ASSIGN TO "BRAND"
ORGANIZATION IS RELATIVE
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD
FLAVORS.
01
KETCHUP-MASTER.
02
FILLER
PIC X(14).
02
REC-NUM
PIC 9(05).
02
FILLER
PIC X(31).
02
FILLER
PIC X(31).
WORKING-STORAGE SECTION.
01
REC-COUNT
PIC S9(5) VALUE 0.
PROCEDURE DIVISION.
A000-BEGIN.
OPEN OUTPUT FLAVORS.
PERFORM A010-WRITE 10 TIMES.
CLOSE FLAVORS.
STOP RUN.
A010-WRITE.
MOVE "Record number" TO KETCHUP-MASTER.
ADD 1 TO REC-COUNT.
MOVE REC-COUNT TO REC-NUM.
WRITE KETCHUP-MASTER
INVALID KEY DISPLAY "BAD WRITE"
STOP RUN.
Creating a Relative File in Random Access Mode
When a program creates a relative file using random access mode, the program
must place a value in the RELATIVE KEY data item before executing a WRITE
statement. Example 6–25 shows how to supply the relative key. It writes 10
records in the cells numbered: 2, 4, 6, 8, 10, 12, 14, 16, 18, and 20. Record cells
1, 3, 5, 7, 9, 11, 13, 15, 17, and 19 are also created, but contain no valid records.
Example 6–25 Creating a Relative File in Random Access Mode
(continued on next page)
6–30 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: ......