The FILE SECTION defines the structure of data files and used to declare file record layout that is required for file processing in the program. It should begin with the FILE SECTION header followed by a separator period.

Syntax -


DATA DIVISION, FILE SECTION, FD/SD entries coding should start in AREA-A, and remaining entries coding should start in AREA-B.

FD is a File Description level indicator that declares file characteristics. SD is the "Sort file Description level indicator" representing the file specified as a sort file.

file-description-entries -

file-description-entries provide information about the file's physical structure and identification and provide the file record-names.

The File Description (FD) Entry or Sort File Description (SD) Entry specifies the highest level of organization in the FILE SECTION. FD or SD entry should be defined as a first entry, and other entries can be in any order.

Syntax -

Sequential file description entries syntax -

FILE SECTION for Sequential files Syntax

Relative or Indexed file description entries syntax -

FILE SECTION for Relative and indexed files Syntax

Sort/Merge file description entries syntax -

FILE SECTION for Sort and Merge files syntax

The FILE SECTION should contain a level-indicator for each input and output file. In addition, the FILE SECTION should have an FD entry for all the files except sort or merge files.

For each sort or merge file, the FILE SECTION should contain an SD entry.

A record in the FD should be defined as an alphanumeric group-variable or an elementary variable of type alphabetic, alphanumeric, or numeric.

file-name -

  • file-name should follow the level indicator (FD or SD), and file-name should be the same as specified in the associated SELECT clause.
  • file-name should follow the rules of the user-defined word.
  • file-name should be unique within the program.
  • One or more record description entries should follow file-name.
  • All other entries that follow file-name are optional and can appear in any order.

FD -

  • FD should specify for all physical files, including sequential, indexed, or relative.
  • The last entry should immediately followed by a separator period.
  • All the clauses followed by FD entry are optional.

SD -

  • An SD entry should code for each sort or merge file in the program.
  • The last entry should immediately followed by a separator period.


  • The EXTERNAL clause specifies the external file connector and allows communication between two programs by the sharing of files. Any program can reference an external file.
  • In the FILE SECTION, the EXTERNAL clause can specify only in file description (FD) entries.
  • The records appearing in the FD entry should not have the same name in corresponding external FD entries.

GLOBAL Clause -

  • The GLOBAL clause specifies the file-name as a global file.
  • A global file-name is available to every program (including the program that declared it) that is directly or indirectly in that program.
  • A file-name is global if the GLOBAL clause is specified in the FD entry along with the file-name.

RECORD Clause -

  • RECORD clause used to specify the record layout, size in terms of bytes regardless of variables with USAGE clause.
  • The record size calculates according to the rules for group-variable size.
  • If the RECORD clause is ignored, the compiler calculates the record lengths from the record descriptions.
  • If a RECORD clause contains an OCCURS DEPENDING ON clause, the compiler uses the maximum value as a record length.
  • The RECORD CONTAINS clause specifies the record size in characters because each record is wholly defined in a record description(level-01) entry. Therefore, the RECORD CONTAINS clause is optional for any FD entry.
  • The below three different formats for different types of records -
    • Fixed length
    • Variable-length
    • Fixed or Variable length

Fixed length -

If the file has fixed-length records, the declaration for fixed-length records is like below -


integer-3 -

  • integer-3 specifies the number of bytes(characters) that each record has in the file.
  • It should be an unsigned integer.
  • The record size defines at run time by comparing the DD statement parameters or dataset label.
  • If the actual record length is larger than the level-01 record description, level-01 record length takes as a record length in the program. If the actual record length is shorter than the level-01 record description, the actual record length takes as the record length in the program.
  • The RECORD CONTAINS 0 CHARACTERS clause specifies only for input QSAM files.
Note! Do not specify the RECORD CONTAINS 0 clause for an SD entry.

Variable length -

If the file has variable-length records, the declaration for variable-length records is like below -

RECORD [CONTAINS] integer-4 TO integer-5 [CHARACTERS].

In this case, the minimum and maximum record lengths are calculates from the record description entries.

integer-4 -

  • integer-4 specifies the size of the smallest record in the file.
  • integer-4 should be an unsigned integer.

integer-5 -

  • integer-5 specifies the size of the largest data record.
  • integer-5 should be an unsigned integer.

DEPENDING ON Clause (Fixed or Variable-lengths) -

DEPENDING ON clause uses to specify the record length during the runtime. The syntax is -

		DEPENDING [ON] data-name-1.

integer-6 -

  • integer-6 specifies the minimum record length of the file.
  • If integer-6 is not specified, the minimum length of any record in the file equals to least number of bytes defined for a record in that file.

integer-7 -

  • integer-7 specifies the maximum length of the record of the file.
  • If integer-7 is not specified, the maximum length of any record equals the maximum number of bytes defined for a record in that file.
  • The number of bytes associated with a record description (FD) determines by summing all elementary data items lengths (excluding redefinitions and renaming) plus implicit FILLER.

data-name-1 -

  • data-name-1 specifies the run-time value used to set the length of the record in the file.
  • The data-name-1 value changes from statement to statement like DELETE, RELEASE, REWRITE, START, WRITE, READ etc.
  • data-name-1 should be an unsigned integer and declare it as an elementary variable.
  • The data-name-1 value should be any value in between integer-6 to integer-7.
  • data-name-1 value decides the actual length of the record that is going to be processed.
  • In this case, the minimum record length is integer-6, and the maximum length is integer-7.

BLOCK Clause -

The BLOCK CONTAINS clause is used to specify the blocking factor for the file. The blocking factor specifies the block size in terms of no of characters or records per block. The actual blocking factor should define by the developer and cannot determine by the operating system.

In the BLOCK CONTAINS clause, the CHARACTERS phrase has the integer value that reflects the blocking factor of the record.

BLOCK CONTAINS clause can be ignored when the records in the associated file are not blocked or the associated file is a VSAM file.

Syntax -


integer-1 -

  • integer-1 specifies the minimum blocking size.
  • integer-1 should be an unsigned integer.
  • It can only specify when the file is a variable-length file.

integer-2 -

  • integer-2 specifies the maximum blocking size.
  • integer-2 should be an unsigned integer.
  • It is a mandatory value with the BLOCK CONTAINS clause.
  • If the integer-1 is not specified, then the file is a fixed-length file with block size integer-2. Otherwise, the file is a variable-length file with a blocking size that varies from integer-1 to integer-2.
Note! BLOCK CONTAINS clause always depends on the RECORD CONTAINS clause.


CHARACTERS clause specifies the number of bytes required to store the physical record regardless of the USAGE clause used for data items. The CHARACTERS phrase is the default.

CHARACTERS should be defined when -

  • The physical record contains padding.
  • Logical records are grouped.


  • If the RECORDS option is used, it specifies the number of logical records contains in each physical record.
  • BLOCK CONTAINS 0 RECORDS can specify for QSAM files.
  • The BLOCK CONTAINS clause can ignore SYSIN and SYSOUT files, and the operating system can determine the blocking.
Note! The BLOCK CONTAINS clause is syntax checked but has no effect on the program's execution when specified under an SD.
The BLOCK CONTAINS clause cannot use with the RECORDING MODE U clause.


The LABEL RECORDS clause documents the presence or absence of labels. The LABEL RECORDS clause is the only syntax checked but has no effect on the program's execution.

Syntax -



  • If STANDARD coded, it specifies labels corresponding to system specifications that exist for this file.
  • STANDARD is allowed for mass storage devices and tape devices.


  • If OMITTED coded, it specifies no labels exist for this file.
  • OMITTED is allowed for tape devices.


  • data-name-2 specifies the name of a user label record.
  • data-name-2 should appear as the subject of a record description entry (FD) associated with the file.


DATA RECORD names the data records associated with the file used to manipulate the data using the fields in the layout. The DATA RECORDS clause is syntax checked. It will not impact file operation, but it just links the record layout to the file.

Syntax -

DATA RECORD[S] [IS/ARE] data-name-4.

data-name-4 -

  • data-name-4 is the record description entries (level-01) associated with the file.
Note! The data-name should not require to associate with level-01 record description with the same name.


The RECORDING MODE clause specifies how logical records contained in the file and how the logical record being read/written to the file.

The RECORDING MODE is an optional clause and is only required for QSAM files.

The RECORDING MODE can be ignored and not needed for VSAM files.

The RECORDING MODE clause does not apply to sort or merge files.

Syntax -


mode -

Mode specifies the recording mode of the file. The valid recording modes are -

  • F(fixed)
  • V(variable)
  • U(fixed or variable)
  • S(spanned)

F (Fixed) -

  • F mode specifies the file only contains fixed-length records.
  • Blocks can contain more than one record, and each block has a fixed number of records.
  • No OCCURS DEPENDING on clause is allowed in record descriptions.
  • All records are fixed-length records, and no record length or block descriptor fields are required.
  • No additional memory is used to store the record apart from the actual record length.

V (Variable) -

  • V mode specifies that the file should contain either fixed length or variable length records.
  • Each record should contain within one block.
  • Blocks can contain more than one record. Each data record includes a record-length field, and each block includes a block-descriptor field.
  • For all the variable-length records, a record length field is required to store the actual length of the variable-length record.
  • The record length field exists at the first 4-bytes of each record and not available for use.

U (Fixed or Variable) -

  • U mode specifies the file contains either fixed-length or variable-length records.
  • One BLOCK has one record.
  • There are no record length and block descriptor fields required.
  • If the BLOCK CONTAINS clause is used, RECORDING MODE U can't be used.

S (spanned) -

  • S mode specifies the file contains either fixed-length or variable-length records that can be larger than a block.
  • If a record is larger than the remaining space in a block, a segment(part) of the record is written to fill the block. The remaining record is stored in the next block or blocks(if required).
  • Even if the segments(parts) of the records are distributed across blocks, only total records are available to us.
  • Each segment(part) of a record in a block includes a segment-descriptor field, and each block consists of a block-descriptor field.
  • The compiler determines the recording mode "S" if the maximum block size is smaller than the largest record size.

record-description-entry -

  • Record-description-entry specifies the record structure of a particular file. It defines a set of data description entries that describe the records contained in a specific file.
  • A record should define as an alphanumeric group variable or an elementary variable of type alphabetic, alphanumeric or numeric in FILE SECTION.
  • A single file can have more than one record description entry (level-01).

Practical Example -

Scenario - Below example describes about the usage of FILE SECTION and used ti display the file data in the spool.

Input -

File Section Input

Code -

File Section Example Code
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. FILESEC.                                             
       AUTHOR. MTH.                                                     
       ENVIRONMENT DIVISION.                                            
       INPUT-OUTPUT SECTION.                                            
           SELECT FILE1 ASSIGN TO DISK1                                 
           ORGANIZATION IS SEQUENTIAL                                   
           ACCESS MODE IS SEQUENTIAL                                    
           FILE STATUS IS WS-FS1.                                       
       DATA DIVISION.                                                   
       FILE SECTION.                                                    
       FD  FILE1                                                        
           RECORD CONTAINS 80 CHARACTERS                                
           BLOCK CONTAINS 800 CHARACTERS                                
           RECORDING MODE IS F                                          
           DATA RECORD IS STD-REC.                                      
       01 STD-REC             PIC X(80).                                
       WORKING-STORAGE SECTION.                                         
       01 WS-VAR.                                                       
           05 WS-FS1              PIC 9(02).                            
           05 WS-EOF-SW           PIC X(01) VALUE 'N'.                  
              88 EOF-SW           VALUE 'Y'.                            
              88 NOT-EOF-SW       VALUE 'N'.                            
       PROCEDURE DIVISION.                                              
           OPEN INPUT FILE1.                                            
           PERFORM UNTIL EOF-SW                                         
              READ FILE1                                                
              AT END MOVE 'Y' TO WS-EOF-SW                              
              NOT AT END DISPLAY STD-REC                                
           CLOSE FILE1.                                                 
           STOP RUN.                                                    
**************************** Bottom of Data ****************************


File Section JCL Code
***************************** Top of Data ******************************
//MATEGJF JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID                             
//*  RUN A COBOL FILE PROGRAM                                           
//STEP01  EXEC PGM=FILESEC                                              
//DISK1    DD  DSN=MATEGJ.INPUT.FILE01,DISP=SHR                         
//SYSOUT   DD  SYSOUT=*                                                 
**************************** Bottom of Data ****************************

Output -

File Section Output

Explaining Example -

Above example reads the input file and displays all the records to the spool.