Files: SELECT and FD
| FILE-CONTROL | |
| The FD record | |
| Where the blocks go |
FILE-CONTROL
ENVIRONMENT DIVISION wires the file to a name. SELECT names the internal file, ASSIGN TO names the external one, and ORGANIZATION picks the layout:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPLOYEE-FILE ASSIGN TO "emp.dat"
ORGANIZATION IS SEQUENTIAL.
The FD record
DATA DIVISION describes the record layout with an FD paragraph. Each 01 under it is one record, and its fields describe one line of the file:
DATA DIVISION.
FILE SECTION.
FD EMPLOYEE-FILE.
01 EMP-RECORD.
05 EMP-NAME PIC X(30).
05 EMP-SALARY PIC 9(7)V99.
Where the blocks go
The three pieces live in their own divisions: SELECT in ENVIRONMENT, the FD in DATA, and the OPEN, READ, WRITE, CLOSE verbs in PROCEDURE. Keeping them apart is what makes COBOL programs readable at any size.
Next: Sequential files: READ and WRITE
Article author: Arthur Isaev