DATA DIVISION


  • DATA DIVISION is responsible for declaring the variables used to process the data in the application program.
  • It declares the variables with their type and size and initializes them with values if needed for processing.
  • DATA DIVISION is optional and required only when at least one variable is declared under any section. However, each section has specific functionality that can be performed within the program.
  • If sections are coded in the program, those should be coded in the same order as shown in the below syntax.

Syntax -

[DATA DIVISION.]
    [FILE SECTION.
         FD|SD file-description-entry...
         [data-description-entry...]]

    [WORKING-STORAGE SECTION.
         data-description-entry...]

    [LINKAGE SECTION.
         data-description-entry...]

The DATA DIVISION has mainly three sections -

  • FILE SECTION
  • WORKING-STORAGE SECTION
  • LINKAGE SECTION

FILE SECTION


FILE SECTION is used to declare all logical record structures of the files that are used in the program.

Syntax -

[DATA DIVISION.]
[FILE SECTION.]
[FD|SD logical-file-name]
    [RECORD CONTAINS ...]
    [BLOCK CONTAINS ...]
    [LABEL RECORD IS OMITTED|STANDARD|variable1]
	[DATA RECORD IS file-record]
	[RECORDING MODE IS F|V|U|S].

01 file-record    PIC X(max-rec-length).

Parameters -

  • FD - Specifies the file description entry for the physical file.
  • SD - specifies the sort description entry for work files.
  • logical-file-name - Specifies the logical file name used in the program to process the file. FD|SD and SELECT clauses should have the same logical-file-name.
  • RECORD CONTAINS - Specifies the size of the record.
  • BLOCK CONTAINS - Specify the block size in terms of characters or records per block.
  • LABEL RECORD IS - Specifies if label records exist in the file and their type. (e.g., STANDARD, OMITTED).
  • DATA RECORD IS - Assigns a local name to the file record. (e.g., EMPLOYEE-RECORD).
  • RECORDING MODE IS - Specifies how the records are stored in the file. (e.g., F(Fixed), V(Variable), U(Unformatted), S(Spanned)). It is only applicable for sequential files.
  • 01 file-record ..- Specifies the record structure declaration.

For example - Declaring a file with length 80.

----+----1----+----2----+----3----+----4----+
       DATA DIVISION.
       FILE SECTION.
       FD  file1
           RECORD CONTAINS 80 CHARACTERS
           BLOCK CONTAINS 800 CHARACTERS 
           RECORDING MODE IS F
           DATA RECORD IS emp-rec.
	   01 emp-rec         PIC X(80).

WORKING-STORAGE SECTION


WORKING-STORAGE SECTION is used to declare all the variables and record structures required for processing data in the program.

Syntax -

[DATA DIVISION.]
[WORKING-STORAGE SECTION.]
	[record-layout-definition.]
	[variables-declaration.]

Examples -

Scenario1 - Declaring a variable.

 WORKING-STORAGE SECTION.
 01 WS-VAR           PIC 9(03). 

LINKAGE SECTION


LINKAGE SECTION declares the variables used to pass data between COBOL programs or receive data from run JCL.

Syntax -

----+----1----+----2----+----3----+----4----+----5----+
	   DATA DIVISION.
	   LINKAGE SECTION.
	   variable-declaration-entries.

Examples -

Scenario1 - Receiving variables from MAINPROG.

       DATA DIVISION.                                                   
       LINKAGE SECTION.                                         
       01 LN-VAR.                                                       
          05 LN-IP1       PIC 9(02).  *> To receive input1 from MAINPROG
          05 LN-IP2       PIC 9(02).  *> To receive input2 from MAINPROG
          05 LN-RESULT    PIC 9(04).  *> To send result to MAINPROG