The Data Division

The DATA DIVISION defines the names that the program will use to refer to the data that it manipulates. It must begin with the phrase

DATA DIVISION.

It can have the following sections, which, if present at all must appear in the given order.

FILE SECTION
This describes the fields within the records of each file the program uses.
WORKING-STORAGE SECTION
Defines the data names that the program needs for internal manipulations of data.
LINKAGE SECTION
Required when one cobol program calls another. We shall not cover this.
COMMUNICATION SECTION
Needed for programs that communicate with other programs through message passing. We shall not cover this.
SCREEN SECTION
Used when the program does inout through forms on a screen. We shall not cover this.

The FILE SECTION

Every file selected in the INPUT-OUTPUT SECTION of the ENVIRONMENT DIVISION must have at least one corresponding entry in the FILE SECTION. The format for an input or output file is as follows: Parts in [ ] are optional.

FD filename [RECORD CONTAINS integer CHARACTERS] [DATA RECORD IS recordname].

It is usual to follow this by the definition of the data record. For a sort file the label FD is replaced by SD.

The format for the data record is a follows. (More details on this are in the WORKING STORAGE SECTION material below.)

01 Recordname. 05 RN-Field1 PIC X(20). 05 RN-Field2 PIC X(40).

The actual names and numbers (other than 01) will vary.

The WORKING-STORAGE SECTION

You are remined that this is only a summary for complete details you should see your text book.

Single Field Data Items

A data item may be indivisible. In this case it has a level number and a picture clause.

01 FIRST-NAME PIC X(15). If the data item has subdivisions then it has a level number and the subdivisions are given immediately following. 01 ADDRESS. 05 ADDRESS-LINE-1 PIC X(40). 05 ADDRESS-LINE-2. 10 CITY PIC X(17). 10 STATE PIC XX. 10 FILLER PIC X. 10 ZIP1 PIC 9(5). 10 FILLER PIC X VALUE IS "-". 10 ZIP2 PIC 9(4).

Address thus has 70 characters. Note that any item that is refined at a higher level number does not have a picture clause. (But check in the book on the redefines clause.) FILLER is a generic name for area within a record that will not be referred to by the program.

Picture Clauses

Every pice of data must have a picture. This determines the type of data that it is. Except in the case of a redefinition the picture clause is associated to the highest level in the field. There is a distinction between the pictures that are used for input (or working storage) fields and those that are used for output fields. The ones used for output fields can be used to edit the output and do things like suppress leaning zeroes or replace them by asterisks (for checks).

Input or Working Storage Pictures

X
Alpanumeric. Any character.
A
Letter or Blank.
9
Digit
V
Assumed decimal point
S
Sign
Output Pictures

X, A, and 9 can be used plus:

B
Blank
Z
Zero suppression
0
Zero insertion
/
Slash insertion eg. for a date.
,
Comma insertion (big numbers)
.
decimal point
+
forces a sign to appear
-
sign if negative
CR
Credit symbol
DB
Debit symbol
*
Asterisk instead of leading zeroes.
$
Dollar sign

Return to the cobol home page
Jonathan Hodgson Last Change: 9 January 1998