TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - File Definition


The FILE SECTION must contain a level-indicator for each input and output file. For all files except sort or merge files, the FILE SECTION must contain an FD entry. For each sort or merge file, the FILE SECTION must contain an SD entry.

Syntax:

DATA DIVISION.
FILE SECTION.
FD FILENAME.
   RECORD CONTAINS N CHARACTERS.
   BLOCK CONTAINS N CHARACTERS/RECORDS.
   RECORDING MODE IS F/FB/V/VB/S/U.
   DATA RECORD IS FILE-REC.
01 FILE-REC PIC X(N).

Explanation:
  • RECORD Clause[optional] - This is to specify the record length of the files in bytes.

  • BLOCK CONTAINS Clause[Optional] - The BLOCK CONTAINS clause specifies the size of the physical records.

  • RECORDING MODE Clause[Optional] - The RECORDING MODE clause specifies the format of the physical records in a QSAM file. The clause is ignored for a VSAM file.

  • DATA RECORD Clause[Optional] - The DATA RECORDS clause is syntax checked but serves only as documentation for the names of data records associated with the file.

    The data-name need not have an associated 01 level number record description with the same name.

Example:

Let us take a employee file,

image missing

And, see how to code in COBOL,

DATA DIVISION.
FILE SECTION.
01 EMPLOYEE-DETAILS.
   05 EMPLOYEE-ID   PIC 9(05).
   05 EMPLOYEE-NAME PIC X(20).
   05 EMPLOYEE-GRADE PIC X(01).
   05 EMPLOYEE-SALARY PIC 9(10).


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal