Data Division

D

DATA DIVISION.

Data division is used to define the variables used in the program including their names, lengths, storage formats. It consists of four sections −

  • File section is used to define the record structure of the file i.e. the data sent to and comes from computer peripherals .
  • Working-Storage section is used to declare temporary variables and file structures which are used in the program like for the purpose of calculation and internal manipulation of data. They are the variable name belongs to the structure of the file.
  • Linkage section is used to describe the data names that are received from an external program.
  • Report Section used in report writer based programs.

Example

DATA DIVISION.

FILE SECTION.

  FD/SD FILE1

01 CUST-NAME PIC A (25).

WORKING-STORAGE SECTION.

01 WS-CUSTOMER PIC A (30).

01 WS-CUST-ID PIC 9(5).

  LINKAGE SECTION.

01 LS-CUST-ID PIC 9(5).

PROCEDURE DIVISION.

DISPLAY “I am a Data Division”.

STOP RUN.

File Section:

FD is the file description level indicator which describe the file structure.

SD is the sort file description level indicator that describe about sort files.

Working storage section:

It defines the variables that are used for data manipulation inside the programs like for calculation purpose.

Linkage section:

It is used in subprograms where we need to send or receive the data between the main program (calling program) and subprogram (called program).subprogram uses the working storage section of the main program to access the data.

Main Prog:

IDENTIFICATION DIVISION.

PROGRAM-ID MAINPGM.

ENVIRONMENT DIVISION.

DATA DIVISION.

WORKING-STORAGE-SECTION

01 WS-A PIC 9(2).

01 WS-B PIC 9(2).

01 WS-C PIC 9(2).

01 CALLED-PGM PIC X(6) VALUE “SUBPGM”.

PROCEDURE DIVISION

ACCEPT WS-A.

ACCEPT WS-B.

CALL CALLED-PGM USING WS-A,WS-B,WS-C.

DISPLAY WS-C.

STOP-RUN.

Sub program:

IDENIFICATION DIVISION.

PROGRAM-ID SUBPGM.

ENVIRONMENT DIVISION.

DATA DIVISION.

LINKAGE-SECTION

01 WS-A1 PIC 9(2).

01 WS-B1 PIC 9(2).

01 WS-C1 PIC 9(2).

PROCEDURE DIVISION USING WS-A1, WS-B1, WS-C1.

COMPUTE WS-C1=WS-A1+WS-B1.

DISPLAY WS-C1.

EXIT.

 

About the author

Add comment

By neelam

Find us

Address
Chennai ,Tamil Nadu,603103

Hours
Monday—Friday: 9:00AM–5:00PM
Saturday & Sunday: 11:00AM–3:00PM

About This Site

This site is to help the beginners in COBOL.

Categories