Format for coding input and output
The following example shows the general format of input-output coding. Explanations of the user-supplied information 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 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 described below:
- (1) filename
- Any legal COBOL name. You must use the same file-name in the
SELECT
clause and in theFD
entry, and in theREAD
,OPEN
, andCLOSE
statements. In addition, the file-name is required if you use theSTART
orDELETE
statements. This name is not necessarily the actual name of the data set as known to the system. Each file requires its ownSELECT
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 in a
DD
statement, in anALLOCATE
command (TSO), or as an environment variable (for example, in anexport
command) (z/OS® UNIX). - (3) org
- The organization can be
SEQUENTIAL
,LINE SEQUENTIAL
,INDEXED
, orRELATIVE
. This clause is optional for QSAM files. - (4) access
- The access mode can be
SEQUENTIAL
,RANDOM
, orDYNAMIC
. 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
orREWRITE
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, map each element accurately against the fields in the record.
- (9) iomode
- The
INPUT
orOUTPUT
mode. If you are only reading from a file, codeINPUT
. If you are only writing to a file, codeOUTPUT
orEXTEND
. If you are both reading and writing, codeI-O
, except for organizationLINE SEQUENTIAL
.