Processing Files and Records
6.4 Reading Files
A100-GET-RECORDS.
READ IND-ALPHA NEXT RECORD AT END MOVE "Y" TO END-OF-FILE.
IF END-OF-FILE NOT = "Y" DISPLAY INPUT-RECORD.
A100-GET-RECORDS-EXIT.
EXIT.
READ PRIOR retrieves a record from an Indexed file which logically precedes
the one which was made current by the previous file access operation, if such a
logically previous record exists. READ PRIOR can only be used with a file whose
organization is INDEXED and whose access mode is DYNAMIC. The file must
be opened for INPUT or I-O. Example 6–35 is an example of READ PRIOR in a
program.
Example 6–35 Reading an Indexed File Dynamically, with READ PRIOR
IDENTIFICATION DIVISION.
PROGRAM-ID. READ_PRIOR.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT F
ASSIGN TO "READPR"
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY
IS K0
ALTERNATE RECORD IS K2 DUPLICATES.
DATA DIVISION.
FILE SECTION.
FD F.
01 R.
02
K0
PIC
X(3).
02
FILLER PIC
X(5).
02
K2
PIC
X(2).
PROCEDURE DIVISION.
P0. DISPLAY "***READ_PRIOR***".
*+
* Indexed file creation: After this load, the indexed file
* contains the following records : 0123456789, 1234567890,
* 2345678990, and 9876543291
*+
OPEN OUTPUT F.
MOVE "0123456789" TO R.
WRITE R INVALID KEY DISPLAY "?1".
MOVE "1234567890" TO R.
WRITE R INVALID KEY DISPLAY "?2".
MOVE "2345678990" TO R.
WRITE R INVALID KEY DISPLAY "?3".
MOVE "9876543291" TO R.
WRITE R INVALID KEY DISPLAY "?4".
CLOSE F.
*+
* READ PREVIOUS immediately after file open for IO
*+
OPEN I-O F.
MOVE "000" TO K0.
READ F PREVIOUS AT END GO TO P1 END-READ.
DISPLAY "?5 " R.
P1. CLOSE F.
(continued on next page)
6–46 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: ......