The following code shows the general
format of input-output coding. Explanations of the user-supplied
information 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 PICTURE 99.
. . .
PROCEDURE DIVISION.
. . .
OPEN iomode filename (9)
. . .
READ filename
. . .
WRITE recordname
. . .
CLOSE filename
. . .
STOP RUN.
The user-supplied information in the code above is as
follows:
- (1) filename
- Any legal COBOL name. You must use the same file-name in the SELECT clause and in the FD entry, and on the READ, OPEN, and CLOSE statements. In addition, the file-name is required
if you use the START or DELETE statements. This name is not necessarily the actual
name of the data set as known to the system. Each file requires its
own SELECT clause, FD entry, and input-output statements.
- (2) assignment-name
- Any name you choose, provided that it follows COBOL and system
naming rules. The name can be 1-30 characters long if it is a
user-defined word, or 1-160 characters long if it is a literal. You
code the name part of the assignment-name on a DD statement, in an ALLOCATE command (TSO) or as an environment
variable (for example, in an export command) (UNIX).
- (3) org
- The organization can be SEQUENTIAL, LINE SEQUENTIAL, INDEXED, or RELATIVE. This clause is optional for QSAM files.
- (4) access
- The access mode can be SEQUENTIAL, RANDOM, or DYNAMIC. For sequential file processing, including
line-sequential, you can omit this clause.
- (5) file-status
- The COBOL file status key. You can specify the file
status key as a two-character category alphanumeric or category
national item, or as a two-digit zoned decimal (USAGE DISPLAY) or national decimal (USAGE NATIONAL) item.
- (6) recordname
- The name of the record used in the WRITE and REWRITE statements.
- (7) fieldlength
- The logical length of the field.
- (8) type
- The record format of the file. If you break the record entry
beyond the level-01 description, each element should map accurately
against the fields in the record.
- (9) iomode
- The INPUT or OUTPUT mode. If you are only reading from a file, code INPUT. If you are only writing to it, code OUTPUT or EXTEND. If you are both reading and writing, code I-O, except for organization LINE SEQUENTIAL.