COBOL Data Division

COBOL Input Output Section COBOL File Section

Advertisements


DATA DIVISION describes and defines the data items referenced by the program, including their names, lengths, decimal point locations, and storage formats.

DATA DIVISION defines the names that are used in the program to refer the data for manipulations.

DATA DIVISION is the place where all memory allocations required by the program are taken care.

DATA DIVISION is optional.

The DATA DIVISION has three main sections


  1. FILE SECTION
  2. WORKING-STORAGE SECTION
  3. LINKAGE SECTION

Let’s discuss each section one by one in detail.


FILE SECTION:


FILE SECTION describes the data is sent to, or comes from computer peripherals specially files.

FILE SECTION describes the fields within the records of each file that was using by the program.

DATA DIVISION, FILE SECTION, FD/SD should start from AREA A and remaining clauses should start in AREA B.


Syntax:

DATA DIVISION.
FILE SECTION.
 FD/SD filename 
	[RECORD CONTAINS integer CHARACTERS] 
	[BLOCK CONTAINS integer RECORDS]
	[DATA RECORD IS record-name].
	[RECORDING MODE IS {F/V/U/S}]

FD is a File Description level indicator which will describes the layout of the file defined.

SD is a Sort File Description level indicator which will describes about the sort files.

The FILE SECTION topic explained in detail here


WORKING-STORAGE SECTION:


WORKING-STORAGE SECTION is used to define the general variables, the additional sections under it.

WORKING-STORAGE SECTION defines the data names that the program needs for internal manipulations of data.

WORKING-STORAGE SECTION fields used for internal usage in the program and will not be accessed outside of the program.

All the WORKING-STORAGE SECTION fields will be initialized when the program execution starts.

Memory will allocated to all WORKING-STORAGE SECTION fields when the execution starts and memory will be de-allocated when the execution ends.


Syntax:

DATA DIVISION.
	WORKING-STORAGE SECTION.
		[Working-storage fields declaration]

The WORKING-STORAGE SECTION topic explained in detail here


LINKAGE SECTION:


LINKAGE SECTION describes that the data available to another program by using CALL.

LINKAGE SECTION uses the data items declared to make available the data to another program.

LINKAGE SECTION mainly used in subprograms where to send/receive the data between the programs (from main program/calling program) by using the layouts.

The LINKAGE SECTION used to access the data external to the program.

The LINKAGE SECTION normally coded in the called/sub program which is used to access the working-storage data in the called program.

The LINKAGE SECTION fields needs to be coded when the data sending from JCL through PARM. In this case 2 bytes extra field(s9(4) COMP) needs to be declared to store the length of data in the linkage section additional to the data length passing from JCL.


Syntax:

DATA DIVISION.
LINKAGE SECTION
	[linkage section data item]

The LINKAGE SECTION topic explained in detail here


Practicle Example:


A simple program for data division with file section and working-storage section


Code:



Input:



Jcl:



Output:



COBOL Input Output Section COBOL File Section

Advertisements