Data division is used to define data needed to be accessed by the program. Ø a.Describes input and output format of data in files...
Data division is used to define data needed to be accessed by the
program.
a.Describes input and output format of data in files.
b.Defines any constants and work areas.
1.FILE SECTION
Ø Describes Record Structure of Files
2.WORKING-STORAGE SECTION
Ø Succeeds file section
Ø Used for intermediate storage
Ø Common practice to group related
items together.
3.LINKAGE SECTION
Ø Describes data made available from
another program.
1.FILE
SECTION
File Description Entries
Ø Each file described with an
FD (File Descriptor) sentence
Ø One FD for each SELECT
statement in ENVIRONMENT DIVISION
Syntax:
FD file-name
RECORD
IS OMITTED
LABEL
RECORDS
ARE STANDARD
RECORD
CONTAINS integer-1 CHARACTERS
BLOCK CONTAINS integer-2 RECORDS.
File
Description clauses
LABEL
RECORDS clause - Used if labels stored in file
BLOCKS
CONTAINS clause - Indicates blocking factor for disk files
Both
labels and blocking usually handled by operating systems so clauses will be
omitted
RECORD
CONTAINS clause
- Indicates size of each record (Optional but
recommended since it provides check on record size)
Defining
a Record
Ø
Each FD followed by record description entries for the file
Record-name defined at the 01 level -Considered highest
level of data
Fields within a record defined at subordinate level with
level numbers from 02 to 49
Example:
01 Employee-Rec-In.
05 Name-In …
05 Annual-Salary-In …
05 Job-Description-In …
05 Name-In …
05 Annual-Salary-In …
05 Job-Description-In …
WORKING-STORAGE
SECTION
Ø Follows FILE SECTION
Ø Starts in Area A, ends with
period
Ø All items must be defined
at 01 level or in entries subordinate to 01 level entry
Ø Rules for user-defined
data-names apply
Ø Elementary items:
·
Must include PICTURE clause
·
May be assigned initial value with VALUE clause
LITERALS AND FIGURATIVE CONSTANTS
Ø Literal is a constant
representing a number or Non number (Alpha numeric) like 45.3 / ‘MANAGER’.
Ø Literals are storable in a
memory Location having a user defined name called Data Name or Identifier or
Variable or Field
Ø Figurative Constant is a
COBOL RESERVED WORD representing frequently used constants like ZEROS / SPACES.
Ø Figurative constants are
used in the program as such for better readability as.
MOVE SPACES TO WS-REC.
Ø
Literals are classified in to NUMERIC and NON-NUMERIC literals.
NUMERIC LITERAL
Ø Must contain at least one
digit
Ø + or - Sign, if used must
be the left-most character
Ø Not more than one decimal
point
Ø
Decimal may not
be the right most character
Ø
Maximum of 18
digits.
05 TOTAL-MARK PIC
9(3) VALUE 100.
Here 100 is a numeric constant
assigned in identifier TOTAL-MARK.
NON-NUMERIC LITERAL
Ø May consist of any
character in the character set
Ø Must be enclosed in quotes
Ø A numeric literal in quotes
is non-numeric
Ø Maximum length of 120 chars
05 COMPANY-NAME PIC
X(3) VALUE ‘EDS’.
Here ‘EDS’ is an alphanumeric constant
assigned in identifier
COMPANY-NAME
LIST OF FIGURATIVE CONSTANTS
ZERO / ZEROES / ZEROS ONE
OR MORE ZEROS
QUOTE / QUOTES ONE
OR MORE “
SPACE / SPACES ONE
OR MORE SPACE
HIGH-VALUE / HIGH-VALUES HIGHEST VALUE IN COLLATING
SEQUENCE
X’FF’ FOR EBCDIC
LOW-VALUE / LOW-VALUES
LOWEST VALUE IN COLLATING SEQUENCE
ALL literal ONE
or MORE OCCURENCES OF litera
Data Description
The general format of the data description is
Ø
Level-number
data-name / FILLER clauses
LEVEL NUMBERS
Ø
A Record is a Collection of all the fields pertaining to an
Item/person/Transaction.
Ø
A record structure is a structure of all the fields of a
record. It may be available in the FILE SECTION/ WORKING-STORAGE SECTION/
LINKAGE SECTION.
Ø
The level-number specifies the hierarchy of data within a
record, and identifies special-purpose data entries. A level-number begins a
data description entry, a renamed or redefined item, or a condition-name entry.
Ø
A level-number has a value taken from the set of integers
between 1 and 49, or from one of the special level-numbers, 66, 77, or 88.
01 This level - number specifies the
record itself.
Ø
A level - 01 entry may be either a group item or an
elementary item.
Ø
It must begin in Area A.
02-49 These
level numbers specify group and elementary items within a record.
Ø
They may begin in Area A or B
Ø
Group Level Data Names Will not have Picture Clause.
01
EMPLOYEE-REC.
02 EMP-NO PIC XXXX.
02 EMP-NAME.
03 FIRST-NAME PIC
A(30).
03 INITIAL-1 PIC A.
03 INITIAL-2 PIC A.
03 INITIAL-3 PIC A.
SPECIAL LEVEL NUMBER
66 Identifies
items that contain the RENAMES clause.
77
Identifies independent elementar
88 condition nam
Level
Number 01 can appear as a Group Level Number as well as Elementary data item
level number.
It can
appear only as an elementary Data Item Level Number.
Example
01 TOTAL PIC
9(5).
77
WS-FLAG PIC XX.
01 RECORD─I.
05 DN─1... .
│<───────────────RECORD─I───────────────>│
05 DN─2... .
┌──────┬──────────┬───────────┬──────────┐
05 DN─3... . │ DN─1 │ DN─2
│ DN─3 │
DN─4 │
05
DN─4... .
└──────┴──────────┴───────────┴──────────┘
66 DN─6 RENAMES DN─1 THROUGH DN─3. │<───────────DN─6────────────>│
WORKING-STORAGE SECTION.
01
SWITCHES.
02 LOADDATA-EOF-SWITCH PIC X(1) VALUE "N".
88 LOADDATA-EOF VALUE "Y".
Data Names
Ø Identifier name/ Data name should
not exceed 30 Characters.
Ø There should be at least one
Alphabet anywhere in the name.
Ø Only special Character allowed is –
( Hyphen) but should not be at the Beginning or End
Ø Examples of data names
Ø EMPLOYEE-NAME , COMPANY, 0001AB,
999-EMPLOYEE-RECORD
Ø Data name must be unique within a
Record
Ø If ‘Name’ is duplicated across
Records, it has to be qualified as Identifier-name of Record Name.
· DISPLAY BALANCE OF STOCK-RECORD
Ø Here balance is an identifier
declared in Stock-record.
Identify
the valid data-names
2.
Amount$Out
3.
Section
4.
My-Section
5. -First-Name
6. Last--Name
7. 98-6
8. Time out
FILLER:
Whenever
there is no need for specific reference to fields in a record structure, we
name it as
FILLER or
F. This Data name is used wherever there is fixed information like SPACES Or
Headings
Are
stored.
Example
01 Detail-record.
05
FILLER PIC X(10)
VALUE SPACES.
05
NAME PIC X(30) .
05
FILLER PIC X(10)
VALUE SPACES.
05 BASIC PIC 9(05) .
05 BASIC PIC 9(05) .
05
FILLER PIC X(10)
VALUE SPACES.
05 DA PIC 9(04) .
05 DA PIC 9(04) .
05
FILLER PIC X(10)
VALUE SPACES.
05 GROSS PIC 9(6).
05 GROSS PIC 9(6).
No comments
Post a Comment