Processing Files and Records
6.4 Reading Files
6.4 Reading Files
Reading sequential, line sequential, relative, and indexed files includes the
following tasks:
1.
Opening the file
2.
Executing a READ or START statement
Sections 6.4.1, 6.4.2, and 6.4.3 describe the specific tasks involved in reading
sequential, line sequential, relative, and indexed files.
6.4.1 Reading a Sequential or Line Sequential File
Reading a sequential or line sequential file involves the following:
1.
Opening the file for INPUT or I/O for sequential files, or INPUT for line
sequential files (I/O is not permitted for line sequential files)
2.
Executing a READ statement
Each READ statement reads a single logical record and makes its contents
available to the program in the record area. There are two ways of reading
records:
•
READ file-name INTO destination-area
•
READ file-name
Statements ( 1 ) and ( 2 ) in the following example are logically equivalent:
FILE SECTION.
FD
STOCK-FILE.
01
STOCK-RECORD
PIC X(80).
WORKING-STORAGE SECTION.
01
STOCK-WORK
PIC X(80).
-------------(1)---------------
-------------(2)---------------
READ STOCK-FILE INTO STOCK-WORK.
READ STOCK-FILE.
MOVE STOCK-RECORD TO STOCK-WORK.
When you omit the INTO phrase, you process the records directly in the record
area or buffer (for example, STOCK-RECORD). The record is also available in the
record area if you use the INTO phrase.
In a READ INTO clause, if the destination area is shorter than the length of
the record area being read, the record is truncated on the right and a warning is
issued; if longer, the destination area is filled on the right with blanks.
If the data in the record being read is shorter than the length of the record (for
example, a variable-length record), the contents of the record beyond that data
are undefined.
Generally speaking, if the recordtype is fixed, the prolog and epilog are zero. The
exceptions to this are: for relative files there is a 1 byte record status flag prolog;
for sequential files there is a 1 byte epilog if the record length is odd.
Example 6–28 reads a sequential file and displays its contents on the terminal.
Processing Files and Records 6–37
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......