The following example shows the general format of input-output coding. Explanations of user-supplied information (lowercase text in the example) follow the code.
IDENTIFICATION DIVISION.
. . .
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT filename ASSIGN TO assignment-name (1) (2)
ORGANIZATION IS org ACCESS MODE IS access (3) (4)
FILE STATUS IS file-status (5)
. . .
DATA DIVISION.
FILE SECTION.
FD filename
01 recordname (6)
nn . . . fieldlength & type (7) (8)
nn . . . fieldlength & type
. . .
WORKING-STORAGE SECTION.
01 file-status PIC 99.
. . .
PROCEDURE DIVISION.
OPEN iomode filename (9)
. . .
READ filename
. . .
WRITE recordname
. . .
CLOSE filename
STOP RUN.
If you want to have the system file-name identified at OPEN time, specify ASSIGN USING data-name. The value of data-name at the time of the execution of the OPEN statement for that file is used. You can optionally precede the system file identification by the file-system type identification.
The following example illustrates how inventory-file is dynamically (by way of a MOVE statement) associated with the file d:\inventory\parts.
SELECT inventory-file ASSIGN USING a-file . . .
. . .
FD inventory-file . . .
. . .
77 a-file PIC X(20) VALUE SPACES.
. . .
MOVE “d:\inventory\parts” TO a-file
OPEN INPUT inventory-file
Restriction: I-O is not a valid parameter of OPEN for line-sequential files.