The following example shows the general format of input/output coding. Explanations of user-supplied information (lowercase text in the example) are shown after 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-name by the file-system identifier, using a hyphen as the separator.
The following example shows how inventory-file is dynamically associated with the file /user/inventory/parts by means of a MOVE statement:
SELECT inventory-file ASSIGN USING a-file . . .
. . .
FD inventory-file . . .
. . .
77 a-file PIC X(25) VALUE SPACES.
. . .
MOVE "/user/inventory/parts" TO a-file
OPEN INPUT inventory-file
The following example shows how inventory-file is dynamically associated with the indexed Encina SFS file parts, and shows how the alternate index files altpart1 and altpart2 are associated with the fully qualified name (/.:/cics/sfs in this example) of the Encina server.
SELECT inventory-file ASSIGN USING a-file . . .
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS FILESYSFILE-KEY
ALTERNATE RECORD KEY IS ALTKEY1
ALTERNATE RECORD KEY IS ALTKEY2. . . .
. . .
FILE SECTION.
FD inventory-file . . .
. . .
WORKING-STORAGE SECTION.
01 a-file PIC X(80). . .
. . .
MOVE "/.:/cics/sfs/parts(/.:/cics/sfs/parts;altpart1,/.:/
cics/sfs/parts;altpart2)" TO a-file
OPEN INPUT inventory-file