Input-Output Section
The INPUT-OUTPUT Section describes the Input-Output environment of the program. When compiling with a relaxed syntax check, the header for this section is optional.
General Format:
[ [ INPUT-OUTPUT SECTION. ]
[ FILE-CONTROL. ] { file-control-entry } ...
[ I-O-CONTROL. [ i-o-control-entry ] ] ] ]
General Rules:
The General Rules for the Statements and Clauses of the Environment Division entries are described below.
File-Control Paragraph
The FILE-CONTROL paragraph contains information about the files in the program.
General Format:
[ FILE-CONTROL. ] { file-control-sequence } ...
SELECT [OPTIONAL} filename
select_clause_sequence '.'
Syntax:
- The
file-control-sequenceis a description of the attributes of an Indexed, Sequential, Relative, or Sort file. - The
select_clause_ sequenceis a sequence of clauses, as described below, which provide the information needed to create, and manage the named file. - Not all clauses are valid in all file formats. Below are the valid usages of clauses in Indexed, Sequential, Relative, and Sort files respectively:
General Rules:
The General Rules for each of the different file formats is described below.
Indexed File Format
General Format:
SELECT [OPTIONAL] file-name
ASSIGN TO [ DYNAMIC ] [ { DISK } ] [ assignment-name ]
[ EXTERNAL]
[ ORGANIZATION IS ] INDEXED
[ ACCESS MODE IS { SEQUENTIAL } ]
{ RANDOM }
{ DYNAMIC }
[ RECORD KEY IS record-key ]
[ ALTERNATE RECORD KEY IS alt-rec-key [WITH [NO] DUPLICATES] ]
[ LOCK MODE IS {MANUAL WITH LOCK ON [MULTIPLE] {RECORD }} ]
{RECORDS}
{AUTOMATIC WITH LOCK ON [MULTIPLE] {RECORD }}
{RECORDS}
{EXCLUSIVE }
[ WITH ROLLBACK ]
[ SHARING [WITH] { ALL OTHER } ].
{ NO OTHER }
{ READ ONLY }
[ RESERVE {number} [AREA ]]
{NO } [AREAS]
[ COLLATING SEQUENCE IS alphabet-name ]
[ FILE STATUS IS file-status-var1 ] .
Sequential file format
General Format:
SELECT [OPTIONAL} filename
ASSIGN TO [ DYNAMIC ] [ { DISK } ] [ assignment-name ]
[ EXTERNAL] { PRINTER }
[ [ ORGANIZATION IS ] {[BINARY] SEQUENTIAL} ]
[RECORD]
[LINE ]
[ ACCESS MODE IS SEQUENTIAL ]
[ LOCK MODE IS { MANUAL } ]
{ AUTOMATIC }
{ EXCLUSIVE }
[ SHARING [WITH] { ALL OTHER } ].
{ NO OTHER }
{ READ ONLY }
[ RESERVE {number} [AREA ]]
{NO } [AREAS]
[ RECORD DELIMITER IS STANDARD-1 ]
[ FILE STATUS IS file-status-var1 ]
[ PADDING CHARACTER IS padding-char ].
Relative file format
General Format:
SELECT [OPTIONAL} filename
ASSIGN TO [ DYNAMIC ] [ { DISK } ] [ assignment-name ]
[ EXTERNAL]
[ ORGANIZATION IS ] RELATIVE
[ ACCESS MODE IS { SEQUENTIAL } ]
{ RANDOM }
{ DYNAMIC }
[ RELATIVE KEY IS relative-key ]
[ LOCK MODE IS {MANUAL WITH LOCK ON [MULTIPLE] {RECORD }} ]
{RECORDS}
{AUTOMATIC WITH LOCK ON [MULTIPLE] {RECORD }}
{RECORDS}
{EXCLUSIVE }
[ SHARING [WITH] { ALL OTHER } ].
{ NO OTHER }
{ READ ONLY }
[ RESERVE {number} [AREA ]]
{NO } [AREAS]
[ FILE STATUS IS file-status-var1 ] .
Sort file format
General Format:
SELECT file-name
ASSIGN TO [ DYNAMIC ] [ { DISK } ] [ assignment-name ]
[ EXTERNAL]
[ FILE STATUS IS file-status-var1 ] .
File control clauses
Assign clause
The ASSIGN clause describes where the data will be stored.
General Format:
ASSIGN TO [ DYNAMIC ] [ { DISK } ] [ assignment-name ]
[ EXTERNAL] { PRINTER }
Syntax:
assignment-nameis either a non-numeric literal or an alphanumeric data item in theworking-storagesection.File-nameandassignment-namemay be the same name.
General Rules:
- The
DYNAMICphrase indicates that assignment name is a data item.assignment-namedoes not need to be initialized to a value when the run unit is initiated, but it must have a value when theOPENstatement is executed. - The
EXTERNALphrase indicates that assignment name is a COBOL word. COBOL-IT will look for a file of the exact name, or an environment variable that matches assignment name to resolve the filename. - The
DISKandPRINTERphrases can only be used with files described with sequential files, as determined by theORGANIZATIONclause. - The
PRINTERphrase causes the file to be considered a Print file. Print files can only beOPENedOUTPUT, andEXTEND. Records that written to a Print files strip trailing spaces. See Using Data Files in the Getting Started with COBOL-IT document for more information on how COBOL-IT resolves filenames included in theASSIGNclause. - Unix command pipes are not supported by COBOL-IT. Notations such as "
| cmd" or "< cmd" in a file name are not supported. If this functionality is required, you should use the useCALL "SYSTEM", write output to a temporary file, and then address the temporary file in yourASSIGNClause.
Lock mode clause
General Format:
[LOCK MODE IS {MANUAL WITH LOCK ON [MULTIPLE] {RECORD }} ]
{RECORDS}
{AUTOMATIC WITH LOCK ON [MULTIPLE] {RECORD }}
{RECORDS}
{EXCLUSIVE }
[ WITH ROLLBACK ]
General Rules:
- The file system must support
COMMITandROLLBACK, otherwise theWITH ROLLBACKclause,COMMITstatement andROLLBACKstatement have no effect. - When the
WITH ROLLBACKphrase is used in theLOCK MODEclause, a file may use theCOMMITandROLLBACKstatements. WITH ROLLBACKimpliesLOCK MODE IS AUTOMATIC, as any of theI-OstatementsWRITE,REWRITE,DELETEautomatically place a lock on the record that is the target of theI-Ostatement. These locks are released when either theCOMMITorROLLBACKstatement is executed.- The effect of the
ROLLBACKstatement is that all record updates, throughWRITE,REWRITE,DELETEstatements since the lastCOMMITorROLLBACKstatement are nullified, or “rolled back”. - The effect of the
COMMITstatement is that all record updates, throughWRITE,REWRITE,DELETEstatements are flushed to from buffers to the data source, and locks released.
Access Clause
The ACCESS clause describes whether the data will be accessible sequentially, or through keyed READs, or both.
General Format:
[ACCESS [MODE] IS { SEQUENTIAL } ]
{ RANDOM }
{ DYNAMIC }
General Rules:
ACCESS MODE IS SEQUENTIALindicates that records are only accessible sequentially, throughREAD NEXTstatements, which retrieve the next record, as defined by the organization of the file.ACCESS MODE IS SEQUENTIALcan be applied to files described withORGANIZATIONthat isSEQUENTIAL,RELATIVE, orINDEXED.ACCESS MODE IS RANDOMindicates that records are only accessible throughREADs on aKEY.ACCESS MODE IS RANDOMcan be applied to files described withORGANIZATIONthat isRELATIVEorINDEXED. For relative files, theRELATIVE KEYis the key of reference. For indexed files, theRECORD KEYis the key of reference.ACCESS MODE IS DYNAMICindicates that records are accessible either throughREAD NEXTstatements, orREADs on aKEY.ACCESS MODE IS DYNAMICcan be applied to files described withORGANIZATIONthat isRELATIVEorINDEXED.- If no
ACCESS MODEis described, thenACCESS MODE IS SEQUENTIALis assumed.
Alternate Record Key Clause
The ALTERNATE RECORD KEY clause describes a non-primary RECORD KEY which may or may not accept DUPLICATES.
General Format:
[ ALTERNATE RECORD KEY IS alt-rec-key [WITH [NO] DUPLICATES] ]
[ ALTERNATE RECORD KEY IS split-key-name = item1, item2 …
[WITH [NO] DUPLICATES] ]
Syntax:
alt-rec-keyis a data item in the file's FD record description.split-keyname must be unique in the module.
General Rules:
- The number of alternate record keys in a file is set when the file is created.
alt-rec-keynames a data element within the file description (FD) as an alternate key of reference for the file. split-key-nameis a user defined name that is associated with a series of non-contiguous data elements within the file description as a key of reference.Split-key-nameis needed when using split keys, and referencing the non-contiguous data elements in aREAD KEY IS [record-key]orSTART KEY IS [record-key]statement.- The
WITH DUPLICATESphrase indicates that the data file may contain more than one record matching the given alternate record key of reference. - The
WITH NO DUPLICATESphrase indicates that the alternate record key of reference is a unique identifier of a record within the file.
Collating Sequence Clause
The COLLATING SEQUENCE clause names the alphabet used for purposes of sorting a key in an indexed file. The alphabet must be declared in SPECIAL-NAMES.
General Format:
[ COLLATING SEQUENCE IS alphabet-name ]
General Rules:
The alphabet-name used in the COLLATING SEQUENCE clause must be either an alphabet name that is declared in SPECIAL-NAMES with an ALPHABET clause, or EBCDIC.
File status clause
The FILE STATUS clause returns the status of the most recent FILE I/O operation.
General Format:
[ FILE STATUS IS file-status-var ]
Syntax:
file-status-var may be declared as PIC 99 or PIC XX.
General Rules:
file-status-varis updated following everyI-Ooperation for the associated file.- A status of “
00” indicates a successfulI-Ooperation. - For information on how unsuccessful
I-Ooperations updatefile-status-var, see File Status Codes.
Lock Mode Clause
The LOCK MODE clause describes the means by which LOCKing of records will be applied within the File.
General Format:
[LOCK MODE IS {MANUAL WITH LOCK ON [MULTIPLE] {RECORD }} ]
{RECORDS}
{AUTOMATIC WITH LOCK ON [MULTIPLE] {RECORD }}
{RECORDS}
{EXCLUSIVE }
{WITH ROLLBACK }
General Rules:
- If there is no
LOCK MODEclause, thenLOCK MODEisAUTOMATICis assumed unless aSHARINGclause in theSELECTstatement or in theOPENstatement indicates otherwise. Note that some file systems and some operating systems do not support record locking. In these cases, all references toLOCK MODEare treated as commentary. - The
LOCK MODE IS MANUALphrase applies when there is aREADon a record in a file that isOPENed in theI-Omode. WhenLOCK MODE IS MANUAL, theREADstatement must include aWITH LOCKclause in order for a lock to be applied. - The
LOCK MODE IS AUTOMATICphrase applies when there is aREADon a record in a file that isOPENed in theI-Omode. WhenLOCK MODE IS AUTOMATIC, the record retrieved by theREADis locked automatically, unless theREADstatement includes aWITH NO LOCKclause. - The
LOCK MODE IS EXCLUSIVEphrase locks the entire file for exclusive use. - The
WITH LOCK ON MULTIPLERECORDS phrase allows the file to hold multiple record locks within the same file. - The
WITH ROLLBACKphrase is recognized, and syntax is validated. However, theWITH ROLLBACKclause is otherwise treated as commentary.
LINE ADVANCING Clause
The LINE ADVANCING clause is recognized, and syntax is validated. However, the LINE ADVANCING clause is otherwise treated as commentary.
General Rules:
There are no General Rules.
OPTIONAL Clause
The OPTIONAL clause affects the behaviour of the OPEN statement when the file being OPEN’ed is not present.
General Rules:
- When the
OPTIONALclause is included in theSELECTphrase, theOPENstatement does not require that the named file be available in order for theOPENto be successful. - The effect of the
OPTIONALclause varies depending on theOPENmode.OPEN INPUT: TheOPENsucceeds, but the file is not created. The first attempt toREADdata in the file fails.OPEN I-O: TheOPENsucceeds and the file is created.WRITEs to the file are successful.OPEN Extend: TheOPENsucceeds and the file is created.WRITEs to the file are successful.
ORGANIZATION Clause
The ORGANIZATION clause describes the logical structure of the file.
General Format:
[ [ ORGANIZATION IS ] {INDEXED } ]
{[BINARY] SEQUENTIAL}
[RECORD]
[LINE ]
{RELATIVE }
General Rules ;
ORGANIZATION IS INDEXEDphrase indicates that the file is an indexed file. Indexed files can be accessed sequentially, or through aRECORD KEY, which identifies a record, and which establishes the order in which the records are ordered in the file.- The
ORGANIZATION IS RELATIVEphrase indicates that the file is a relative file. Relative files can be accessed sequentially, or through aRELATIVE KEY, which represents a record’s ordinal position in the file. ORGANIZATION IS SEQUENTIALindicates that the file is a sequential file. Sequential files can only be accessed sequentially. Records are stored in a sequential file in the order in which they were added to the file.ORGANIZATION IS BINARY/RECORD SEQUENTIALindicates that the file is a sequential file, and does not contain record delimiters.BINARYandRECORDare synonyms.ORGANIZATION IS LINE SEQUENTIALindicates that the file is a sequential file, and contains record delimiters.
PADDING CHARACTER Clause
The PADDING CHARACTER designates a single character literal to pad the last block of the file.
General Format:
[ PADDING CHARACTER IS padding-char ]
Syntax:
padding-char is a single character literal or alphanumeric data item.
General Rules:
- If
padding-charis not specified, theSPACEis used aspadding-char. - When a
PADDING CHARACTERis defined, that character is used to pad the last block of the file.
RECORD DELIMITER Clause
The RECORD DELIMITER clause is recognized, and syntax is validated. However, the RECORD DELIMITER clause is otherwise treated as commentary.
General Format:
[ RECORD DELIMITER IS STANDARD-1 ]
General Rules:
There are no General Rules.
RECORD KEY Clause
The RECORD KEY clause names the field in the file definition of an indexed file that is to be considered the primary key, for purposes of RANDOMly accessing records.
General Format:
[ RECORD KEY IS record-key ]
[ RECORD KEY IS split-key-name = item1 item2 … ]
Syntax:
record-keyis a data item in the file's FD record description.split-key-namemust be unique in the module.
General Rules:
RECORD KEYis defined when the file is created.Record-keynames a data element within the file description (FD) as a primary key of reference for the file, determining the order in which records are retrieved whenREADusingRECORD KEY.RECORD KEYis a unique identifier of a record within the file.split-key-nameis a user defined name that is associated with a series of non-contiguous data elements within the file description as a key of reference.Split-key-nameis needed when using split keys, and referencing the non-contiguous data elements in aREAD KEY IS [record-key]orSTART KEY IS [record-key]statement.
RELATIVE KEY Clause
The RELATIVE KEY clause names the field in the working-storage section that is to be considered the relative key, for purposes of RANDOMly accessing records in a relative file.
General Format:
[ RELATIVE KEY IS rel-key ]
Syntax:
rel-key is an unsigned integer data item declared in the working-storage section.
General Rules:
- Relative files can be accessed through a
RELATIVE KEY, which is stored in an unsigned data item declared in theworking-storagesection, and which represents a record’s ordinal position in the file. rel-keymust be set to a positive integer value before performingI-Ooperations.
RESERVE Clause
The RESERVE clause is recognized, and syntax is validated. However, the RESERVE clause is otherwise treated as commentary.
General Format:
RESERVE {number} [AREA ]]
{NO } [AREAS]
General Rules:
There are no General Rules.
SHARING Clause
The SHARING clause describes the situations in which concurrent access to a file is allowed from multiple processes.
General Format:
[ SHARING [WITH] { ALL OTHER } ].
{ NO OTHER }
{ READ ONLY }
General Rules:
- The
SHARINGclause sets a level of restrictiveness on whether a file that has beenOPENed can beOPENed by another file connector. Conditions causing a failedOPENare marked with the word “Fails”, and conditions leading to a successfulOPENare marked with the word “Succeeds” in the table below:

SORT TABLE
- A
SHARINGphrase on anOPENstatement takes precedence over aSHARINGphrase in aSELECTstatement.
I-O-CONTROL
The I-O-CONTROL paragraph describes input-output rules that are applicable for specified files.
General Format:
I-O-CONTROL.
[ APPLY WRITE-ONLY ON {file-name} ... ] ...
[ SAME [RECORD ] AREA FOR {file-name} ... ] ...
[SORT ]
[SORT-MERGE]
[ MULTIPLE FILE TAPE CONTAINS
{ file-name [ POSITION position-integer ] } ... ] ... .
Syntax:
file-nameis a file described by aSELECTclause in theFILE-CONTROLparagraph.position-integeris an integer literal.
General Rules:
- The
APPLYclause is recognized, and syntax is validated. However, theAPPLYclause is otherwise treated as commentary. - The
SAME RECORD AREAclause causes the listed files to share the same memory. Care should be taken to ensure that of the listed files, only one isOPENat a time. - The
SAME SORT AREAclause is recognized, and syntax is validated. However, theSAME SORT AREAclause is otherwise treated as commentary. - The
SAME SORT-MERGE AREAclause is recognized, and syntax is validated. However, theSAME SORT-MERGE AREAclause is otherwise treated as commentary. - The
MULTIPLE FILE TAPEclause is recognized, and syntax is validated. However, theMULTIPLE FILE TAPEclause is otherwise treated as commentary.