2. Contents
Divisions—General Formats.
Level structure.
Data Description Entries.—PITURE and
VALUE Clause.
Editing Characters.
Special–names Paragraph, Classes and
categories of Data.
3. IDENTIFICATION DIVISION
Provides identifying information about program.
Divided into paragraphs.
PROGRAM-ID is only required paragraph . The entry in
the PROGRAM-ID paragraph contains the program name
to be used to identify the object program.
Other paragraphs are optional.
Used mainly for documentation purpose.
The division heading and paragraph names should be
coded as area A entries.
5. IDENTIFICATION DIVISION.
PROGRAM-ID. PROG1.
AUTHOR. R.R. BHATT.
INSTALLATION. ABC CORP.
DATE-WRITTEN. 01-JAN-2005.
DATE-COMPILED. 01-JAN-2005.
SECURITY. HIGH.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG1.
AUTHOR. R.R. BHATT.
INSTALLATION. ABC CORP.
DATE-WRITTEN. 01-JAN-2005.
DATE-COMPILED. 01-JAN-2005.
SECURITY. HIGH.
OPTIONAL
Compiler takes this as
Program Identifier.
PROGRAM-ID comes
immediately after ID
Division.
IDENTIFICATION DIVISION …
6. ENVIRONMENT DIVISION
The computer and all peripheral devices required by the
program are described in this division.
This division is machine-dependent since devices differ from
computer to computer.
It consists of 2 sections.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. entry.
OBJECT-COMPUTER. entry.
[SPECIAL NAMES. Entry].
[INPUT-OUTPUT SECTION.
FILE-CONTROL. {entry}.
[I-O-CONTROL. entry].]
7. ENVIRONMENT DIVISION
CONFIGURATION SECTION INPUT-OUTPUT SECTION
Identifies the
computer used for
compiling of programs
Identifies the
resources used for
executing the program
ENVIRONMENT DIVISION
8. 1.CONFIGURATION SECTION
This section contains an overall specification of the computer used
for the purpose of compilation and execution of the program.
The SOURCE-COMPUTER paragraph specifies the name of the
computer used to compile the COBOL program.
The OBJECT-COMPUTER paragraph describes the computer
on which the program is to be executed. It consist of MEMORY
SIZE, SEGMENT LIMIT etc.
The SPECIAL_NAMES is used to relate some hardware names
to user-specified mnemonic names. This is optional in all
computers.
SOURCE-COMPUTER. ICL-1901.
OBJECT-COMPUTER. ICL-1900.
9. 2.INPUT-OUTPUT SECTION
INPUT-OUTPUT SECTION
This section contains information regarding files to be used
in the program.
The INPUT-OUTPUT SECTION consists of two paragraphs
namely FILE CONTROL paragraph and I-O CONTROL
paragraph.
In the FILE CONTROL paragraph a file name is selected
for each file to be used in the program and assigned to a
device. The simplified format of a file control entry is given
below:
SELECT file-name ASSIGN TO hardware-name.
This section as a whole is optional in many computers.
10. The DATA DIVISION is used to describe the data structures
used in the program.
There are sections in the DATA DIVISION
1. FILE SECTION
2. WORKING-STORAGE SECTION
3. LOCAL STORAGE SECTION
4. LINKAGE SECTION
5. COMMUNICATION SECTION
6. REPORT SECTION
7. SCREEN SECTION
DATA DIVISION
11. The two most commonly used components (sections) are
a) WORKING-STORAGE SECTION
Internal data structures are defined here.
b) FILE SECTION
File I/O buffer areas are defined here.
General Format
DATA DIVISION.
[ FILE SECTION.
file section entries. ………….. ]
[ WORKING-STORAGE SECTION.
working-storage entries. ……….. ]
12. DATA DIVISION
The DATA DIVISION is used to declare the data items
that will be processed in the PROCEDURE DIVISION
of the source program. Though there are seven
different SECTIONs in DATA DIVISION, which appear
in the order :
1) FILE SECTION
The FILE SECTION is used to declare the FD (File
descriptor) and SD (Sort descriptor) entries for files and
sort files used in the program.
1) WORKING-STORAGE SECTION
The WORKING-STORAGE SECTION is used to declare
all the temporary variables and record structures used in
the program.
13. 3) LOCAL STORAGE SECTION
1) The LOCAL-STORAGE SECTION defines storage that
is allocated and freed on a per requirement basis.
2) On each requirement, data items defined in the Local-
Storage Section are reallocated and initialized to the
value assigned in their VALUE clauses.
4) LINKAGE SECTION
1) The LINKAGE SECTION is used to describe data
items made available from another program.
2) Storage is not allocated to the data structures
defined in the LINKAGE SECTION as the data exists
elsewhere.
14. 5) COMMUNICATION SECTION
1) The COMMUNICATION SECTION is used to create
a control block required for communication, which is
release dependent.
6) REPORT SECTION
1) The REPORT SECTION is used to describe RD
(Report Descriptor) entries, which will be required for
Report Writer Module.
15. 7) SCREEN SECTION
1) The SCREEN SECTION is used to describe labels
and data items, which will be required for formatted
input/output in case of application programs developed
for Personal computers.
Of these the sections which are most commonly used are –
a) WORKING-STORAGE SECTION
b) FILE SECTION
16. The PROCEDURE DIVISION consists of the following
1. Sections
2. Paragraphs
3. Sentences
4. Statements
General Format
PROCEDURE DIVISION.
[ section-name SECTION.
[paragraph-name. [sentence] …. ] …. ]
PROCEDURE DIVISION
17. PROCEDURE DIVISION
PROCEDURE DIVISION.
0001-ACCOUNT SECTION.
001-ACCOUNT-READ-PARA.
READ ACC-FILE AT END
MOVE ‘Y’ TO EOF.
MOVE TAX-REDUCT TO TAX-AMOUNT
001-ACCOUNT-VALIDATE-PARA.
ADD AMOUNT TO TOT-AMOUNT.
IF AMOUNT IS GREATER THAN 1000
GO-TO ACCOUNT-READ-PARA.
ACCEPT EMPLOYEE-SALARY.
DISPLAY “Current Employee Salary “
EMPLOYEE-SALARY.
001-EXIT-PARA.
STOP RUN.
Section
Paragraph
Sentences
statement
Section contain one or
more Paragraphs.
A PARAGRAPH
comprises of one or
more sentences
A SENTENCE is a
combination of one or
more statements and is
terminated by a full stop.
A STATEMENT is a
combination of a
COBOL verb and one or
more operands.
18. IDENTIFICATION DIVISION.
PROGRAM-ID. FIRSTPG.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY ‘-------------------------------’.
DISPLAY ‘ WELCOME TO COBOL’.
DISPLAY ‘--------------------------------’.
STOP RUN.
IDENTIFICATION DIVISION.
PROGRAM-ID. FIRSTPG.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY ‘-------------------------------’.
DISPLAY ‘ WELCOME TO COBOL’.
DISPLAY ‘--------------------------------’.
STOP RUN.
First COBOL program
19. DATA Description Entries
A data description entry describes a data item.
A component in this context is a level number, a data
name or a clause.
Except for the level number, no other component can
appear in area A.
There must be at least one space between any two
consecutive components of an entry.
20. All the data names used in the PROCEDURE DIVISION must
be described in the DATA DIVISION.
The description of a data name is done with the aid of the
following –
(1) Level number
(2) PICTURE clause
(3) VALUE clause
Description of data names
DATA DIVISION.
01 EMP-NO PIC X(10) VALUE 1001.
LEVEL NO Data Name Picture Clause VALUE Clause
21. It is a two-digit number starting from 01. Is used to
specify the data hierarchy.
Level number
Level Number Purpose
01 Record description and independent items
02 to 49 Fields within records and sub items
66 RENAMES clause
77 Independent items
88 Condition names
DATA NAME LEVEL NO
22. Picture Clause
The PICTURE Clause describes the general characteristics of
an elementary data item. The characteristics are
1. CLASS—A data item may be one of the 3 classes.
NUMERIC---Digits 0 to 9.
ALPHABETIC---A to Z & Space (Blank) Character.
ALPHANUMERIC---Digits, Letters, Special Characters.
2. SIGN---A numeric data item can be signed or unsigned.
Implicitly, unsigned, ie Positive.
Sign can be specified in the PICTURE clause to describe a
signed data item.
23. Picture Clause
3.POINT LOCATION---The position of the decimal point is
another characteristic that can be specified in the case of
numeric data items.
4.SIZE---Which specify the number of characters or digits
required to store the data item in the memory.
General format for PICTURE clause
PICTURE [PIC] IS character-string.
The PICTURE clause is only to be specified for elementary
items. It can’t be used for a group item.
The size of a group item is equal to the total of the sizes of all
subordinate elementary items.
The class of a group item is alphanumeric.
24. Code Characters Meaning
9 Numeric
A Alphabetic
X Alphanumeric
S (Signed) Sign bit
V position of Assumed Decimal point
P position of Assumed Decimal point
when the point lies outside the data item
Picture Clause
25. Rules
1. In Alphabetic item the picture may contain only A.
2. In Numeric item the picture may contain only
9,V,P,S.These are called operational characters. It
must contain at least one 9 and V & S can appear only
once.
S, if it is included, must be the leftmost character of
the picture string.
The Symbol P can be repeated as many times as
is required to indicate the position of the assumed
decimal point.
3. In Alphanumeric item, the picture may contain all Xs or
a combination of 9, A and X (except all 9 or all A).
26. Example
1.PIC IS S999V99
Means data is signed numeric with size 5 characters. The position
of decimal point is before 2 places from the rightmost end.
2. PIC IS PPP999
Means data is of 3 characters in size & 6 positions after the
assumed decimal point.
Data is 234, the value will be taken as .000234.
3. PIC IS 999PP
Data is 234, the value will be taken as 23400.
27. COBOL ‘PICTURE’ Clauses
Some examples
PICTURE 999 a three digit (+ive only) integer
PICTURE S999 a three digit (+ive/-ive) integer
PICTURE XXXX a four character text item or string
PICTURE 99V99 a +ive ‘real’ in the range 0 to 99.99
PICTURE S9V9 a +ive/-ive ‘real’ in the range ?
If you wish you can use the abbreviation PIC.
Numeric values can have a maximum of 18 (eighteen) digits
(i.e. 9’s).
The limit on string values is usually system-dependent.
28. Abbreviating recurring symbols
Instead of repeating 9, X, A or P in the picture string, it is
possible to write the number of occurrences of a character
enclosed within parentheses immediately after the said
character.
Recurring symbols can be specified using a ‘repeat’ factor
inside round brackets
PIC A(6) is equivalent to PICTURE AAAAAA.
PIC 9(6)V99 is equivalent to PIC 999999V99
PICTURE X(10) is equivalent to PIC XXXXXXXXXX
PIC S9(4)V9(4) is equivalent to PIC S9999V9999
PIC 9(18) is equivalent to PIC 999999999999999999
29. Declaring DATA in COBOL
In COBOL a variable declaration consists of a line containing the
following items;
ŒA level number.
A data-name or identifier.
ŽA PICTURE clause.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 999 VALUE ZEROS.
01 VatRate PIC V99 VALUE .18.
01 StudentName PIC X(10) VALUE SPACES.
Num1 VatRate StudentName
Num1 VatRate StudentName
000
000
.18
.18
DDATAATA
30. VALUE clause
Is used to assign an initial value to a elementary data item.
Syntax: VALUE IS literal.
The initial value can be numeric literal, non- numeric literal
or figurative constant.
We can give a starting value to variables by means of an
extension to the picture clause called the value clause.
It is an optional clause.
Examples: 1)VALUE IS 23.5.
2)VALUE IS “ Apples”. Or VALUE IS “My Data”.
3) VALUE ZERO.
31. VALUE clause
If a VALUE clause is used at a group level , it should not be
used for any item within the group. Only nonnumeric literals
and figurative constants can be used to specify the value of a
group item.
Example—1) 03 num1 PIC S9(3)V99 VALUE -2.34.
Here data item is level 3 elementary item belonging to a group.
2) 01 num2 VALUE IS “234567”.
02 data-1 PIC 9(2). ----- 23
02 data-2 PIC 9(3). ----- 456 Values Stored
02 data-3 PIC 9(1). ----- 7
32. In COBOL the term “group item” is
used to describe a data item which has
been further subdivided.
A Group item is declared using a
level number and a data name.
It cannot have a picture clause.
Where a group item is the
highest item in a data hierarchy it
is referred to as a record and
uses the level number 01.
Picture clauses are NOT
specified for ‘group’ data items
because the size of a group item
is the sum of the sizes of its
subordinate, elementary items
and its type is always assumed
to be PIC X.
Group and elementary items
WORKING-STORAGE SECTION.
01 EMPLOYEE-DETAILS PIC X(30).
01 EMPLOYEE-DETAILS.
05 EMP-NUM PIC 9(4).
05 EMP-NAME PIC X(10).
05 EMP-DEPT PIC X(4).
05 EMP-LOC PIC X(12).
WORKING-STORAGE SECTION.
01 EMPLOYEE-DETAILS PIC X(30).
01 EMPLOYEE-DETAILS.
05 EMP-NUM PIC 9(4).
05 EMP-NAME PIC X(10).
05 EMP-DEPT PIC X(4).
05 EMP-LOC PIC X(12).
36. In COBOL, Level numbers
are used to express data
hierarchy. The higher the
level number, the lower
the item is in the
hierarchy.
So Group items contain
sets of elementary items
with lower level numbers.
At the lowest level the
data is completely atomic.
LEVEL Numbers & DATA hierarchy
WORKING-STORAGE SECTION.
01 POLICY-DETAILS.
05 POLICY-NO.
10 POLICY-TYP PIC X(4).
10 POLICY-LOC PIC X(2).
10 POLICY-ID PIC X(5).
05 POLICY-TYPE PIC X(10).
05 POLICY-EXPDT PIC X(10).
WORKING-STORAGE SECTION.
01 POLICY-DETAILS.
05 POLICY-NO.
10 POLICY-TYP PIC X(4).
10 POLICY-LOC PIC X(2).
10 POLICY-ID PIC X(5).
05 POLICY-TYPE PIC X(10).
05 POLICY-EXPDT PIC X(10).
37. DATA DIVISION.
WORKING-STORAGE SECTION.
01 REGNO PIC X(5).
01 NAME.
05 FIRST-NAME PIC A(15).
05 MID-NAME PIC A(15).
05 LAST-NAME PIC A(10).
01 AGE PIC 99V99.
01 SCHOLARSHIP PIC 9(4) VALUE 1000.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 REGNO PIC X(5).
01 NAME.
05 FIRST-NAME PIC A(15).
05 MID-NAME PIC A(15).
05 LAST-NAME PIC A(10).
01 AGE PIC 99V99.
01 SCHOLARSHIP PIC 9(4) VALUE 1000.
Description of data names
38. H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
Group
Items/Records
StudentDetails
WORKING-STORAGE SECTION.
01 StudentDetails PIC X(26).
WORKING-STORAGE SECTION.
01 StudentDetails PIC X(26).
39. H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
StudentDetails
StudentName StudentId CourseCode Grant Gender
Group
Items/Records
WORKING-STORAGE SECTION.
01 StudentDetails.
0202 StudentNameStudentName PIC X(10).PIC X(10).
0202 StudentIdStudentId PIC 9(7).PIC 9(7).
0202 CourseCodeCourseCode PIC X(4).PIC X(4).
0202 GrantGrant PIC 9(4).PIC 9(4).
0202 GenderGender PIC X.PIC X.
WORKING-STORAGE SECTION.
01 StudentDetails.
0202 StudentNameStudentName PIC X(10).PIC X(10).
0202 StudentIdStudentId PIC 9(7).PIC 9(7).
0202 CourseCodeCourseCode PIC X(4).PIC X(4).
0202 GrantGrant PIC 9(4).PIC 9(4).
0202 GenderGender PIC X.PIC X.
40. H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
StudentDetails
Surname Initials
WORKING-STORAGE SECTION.
01 StudentDetails.
0202 StudentName.StudentName.
03 Surname03 Surname PIC X(8).PIC X(8).
03 Initials03 Initials PIC XX.PIC XX.
0202 StudentIdStudentId PIC 9(7).PIC 9(7).
0202 CourseCodeCourseCode PIC X(4).PIC X(4).
0202 GrantGrant PIC 9(4).PIC 9(4).
0202 GenderGender PIC X.PIC X.
WORKING-STORAGE SECTION.
01 StudentDetails.
0202 StudentName.StudentName.
03 Surname03 Surname PIC X(8).PIC X(8).
03 Initials03 Initials PIC XX.PIC XX.
0202 StudentIdStudentId PIC 9(7).PIC 9(7).
0202 CourseCodeCourseCode PIC X(4).PIC X(4).
0202 GrantGrant PIC 9(4).PIC 9(4).
0202 GenderGender PIC X.PIC X.
StudentName StudentId CourseCode Grant Gender
Group
Items/Records
41. FILE SECTION
This contain a file description entry followed by one or more
record description entries for each of the files used in a
program.
Format for file description entry is
FD file-name LABEL RECORDS ARE STANDARD
RECORD IS OMITTED
The label indicator FD must begin in Area A and rest of the file
description entry must appear only in Area B.
The file-name must be identical with the file name specified in
the select clause of the ENVIRONMENT section.
STANDARD option should be specified for disk files, OMITTED
option should be specified for card reader and printer files.
LABEL RECORD clause---it is mandatory in ANSI 74. Many
compilers treat it as optional.
42. FILE SECTION
The coding rule for an FD entry is similar to that of level 01
entry.
The description entries that follow the file description entry,
should describe the record types in the file. There should be one
record description entry for each type of record.
A record description entry is a 01 level group item along with all
its subdivisions.
Example
FD card-file.
01 card-records.
02 num pic 9(3).
02 price pic 9(2)v9(2)
02 amount pic 9(2)v9(2)
43. WORKING-STORAGE SECTION
The data in the working storage can be group item, containing
all its subdivisions same as record description.
There may also be elementary data item which do not belong to
a group. Such data items should be defined at a special level
number 77. Level number 77 must begin in Area A.
Elementary item in this section need not always be defined at
the level 77. It can as well be defined at the level 01.Example----
WORKING-STIRAGE SECTION.
77 num PIC X(7).
01 date.
05 day pic 99.
05 month pic 99.
05 year pic 9999.
01 address pic x(10).
45. EDITING
The data to be printed in a report requires some editing.
Example—To print a numeric data item ,by suppressing the
leading zeros.
Editing is normally performed by moving a numeric data item
to a field containing special editing characters in its picture
clause.
Following characters can be used in the PICTURE clause to
indicate editing
Z * $ - + CR DB . , B 0 /
46. Edit symbol Meaning
Z Zero suppression
* Check protection
, Comma insertion
- Minus sign insertion
+ Plus or minus sign insertion
Edited picture symbols
47. Edited picture symbols
Edit symbol Meaning
$ Dollar sign insertion
CR Credit symbol
DB Debit symbol
B Blank insertion
/ Slash insertion
. Decimal point insertion
BLANK WHEN
ZERO
Blank insertion when the value is
zero
48. Z-Zero suppression
The Z has the same meaning as that of 9 in the picture except
that the leading zeros in the source data.
If any, in the digit positions indicated by Z will be suppressed—
Replaced by space characters.
It is obvious that Z cannot appear to the right of any 9.
After the decimal point either the digit positions are indicated by
all Z or none at all.
In the below examples
The character b ---is used to indicate a space character.
The character ^ ---is used to indicate the position of the decimal
point.
49. ZZ999 01234 b1234
ZZ999 00034 bb034
ZZ999 1^23 bb001
ZZZV99 12^3 b1230
ZZZV99 0^12 bbb12
ZZZZVZZ 0^01 bbbb01
ZZZZVZZ 0 bbbbbb
Edit symbol Value Edited value
Z (Zero Suppression)---Example
50. *(Asterisk) Example
This is same as Z except that the leading zeros are replaced
by * instead of space.
Edit symbol Value Edited value
**999 01234 *1234
**999 00012 **012
**999 1^23 **001
51. $(Currency Sign) Example
A single currency sign can appear at the leftmost position of a
picture. In that case the $ character is inserted.
Edit symbol Value Edited value
$99999 123 $00123
$99999 12345 $12345
$ZZ999 123 $bb123
$ZZ999 12345 $12345
$**999 123 $**123
52. -(Minus Sign) Example
It can appear at leftmost or rightmost position of the picture. If the
value of an item is –ve, a - sign will be inserted, If value is +ve, a
space character will be inserted.
Edit symbol Value Edited value
-9999 -123 -0123
-9999 123 b0123
9999- -123 0123-
9999- 123 0123b
-ZZZV99 -12^34 -b1234
-ZZZV99 12^34 bb1234
53. +(Plus Sign) Example
It is same as minus sign except that when the item is +ve, + sign
will be inserted. If value is –ve, - sign will be inserted,.
Edit symbol Value Edited value
+9999 -123 -0123
+9999 123 +0123
9999+ -123 0123-
9999+ 123 0123+
+ZZZV99 -12^34 -b1234
+ZZZV99 12^34 +b1234
54. CR and DB (Credit and Debit Sign)
Example
CR or DB symbol appear only at the rightmost position of the
picture. These symbols appear in the rightmost position only if the
item is negative, otherwise they will be replaced by 2 spaces.
Edit symbol Value Edited value
9999CR -1234 1234CR
9999CR 1234 1234bb
ZZZCR -12 b12CR
ZZZ9V99DB -123^45 b12345DB
ZZZ9V99DB 123^45 b12345bb
55. Period or Decimal Point-
Example
It is used to insert a decimal point and may not appear more than
once.
Both period & V cannot appear in the same picture.
A period must not also appear as the rightmost character in the
picture.
If all the digits before and after the period happen to be zeros, the
period does not stop zero suppression and the entire field
including the period is space-filled (the period is not filled with
space when an asterisk(*) is used as a zero-suppression
character.
56. Period or Decimal Point-
Example
Edit symbol Value Edited value
9999.99 123^45 0123.45
ZZ99.99 12^34 bb12.34
ZZ99.99 123 b123.00
ZZZZ.ZZ 0^01 bbbb.01
ZZZZ.ZZ 0 bbbbbbb
****.** 0 ****.**
$ZZZ9.99 0123 $b123.00
57. , (Comma)-- Example
It is treated as an insertion character and inserted wherever it
appears.
If zero suppression takes place to the right of any comma, the
said comma will also be suppressed and a space character will
take its position .
It cannot appear either as the rightmost or leftmost character in a
picture.
There can be more than one comma in a picture.
58. , (Comma)-- Example
Edit symbol Value Edited value
99,999 1234 01,234
99,999 12 00,012
ZZ,Z99 1234 b1,234
**,*** 12 ****12
*,***,** 123 ****1,23
*,***,** 123456 1,234,56
ZZ,Z9.99 123^45 b1,23.45
59. B (Blank Insertion)-- Example
The appearance of a B anywhere in the picture will insert a space
character in the edited data. There can be more than one B in a
picture.
Edit symbol Value Edited value
99B99B99 123456 12b34b56
99B99B99 12 00b00b12
60. Z (Zero Insertion)-- Example
It is same as B except that 0 will be inserted instead of a space
character.
Edit symbol Value Edited value
9900 12 1200
09990 123 01230
61. / (Slash Insertion)-- Example
It may appear anywhere in the picture. If used, it will be inserted. It
is also called as stroke.
Edit symbol Value Edited value
99/99/99 123456 12/34/56
999/999/99 1234 000/012/34
62. BLANK WHEN ZERO-- Example
BLANK WHEN ZERO is an editing clause which may be used along
with a picture.
This will set the entire data item to blanks if its value is equal to 0.
Edit symbol Value Edited value
ZZZ.99 BLANK WHEN ZERO 1^2 bb1.20
ZZZ.99 BLANK WHEN ZERO 0 bbbbbb
999.99 BLANK WHEN ZERO 0 bbbbbb
63. SPECIAL-NAMES Paragraph
If a currency symbol other than $ is required for editing, a one
character symbol may be specified in the SPECIAL-NAMES
paragraph of the ENVIRONMENT DIVISION.
This character may not be a digit or letters A to D, L, P, R, S,
V, X, Z or special characters blank * - , . ; ( ) + ‘ ‘ / =.
Syntax
SPECIAL-NAMES.
CURRENCY SIGN IS “ character”.
Specifies a substitute character for the currency sign
DECIMAL-POINT IS COMMA.
64. CLASSES AND CATEGORIES OF
DATA
All elementary data items are classified into the following 5
categories.
1.Alphabetic ( A)
2.Numeric( 9)
3.Alphanumeric (X)
4.Edited numeric ( Z, $)
5.Edited alphanumeric(/,-)
The characters in the picture string determines the category
of an elementary data item.
65. Categories and the corresponding symbols
used in the PICTURE character string
1.Alphabetic A
2.Numeric 9 P S V
3.Edited Numeric 9 P V and at least one of the
editing symbols B / Z 0 + - * , . CR DB
4.Alphanumeric X 9 A (at least one X or a
combination of 9 and A)
5.Edited Alphanumeric X 9 A B 0 / ( must contain at least
one X with at least one of B 0 / or at least one A with at least one 0
or /)
66. CLASS & CATEGORY
These five categories of data are grouped into 3 classes. The
class of a data item indicates how the data is treated during
execution.
Level of Data Item Class category
Elementary Alphabetic Alphabetic
Numeric Numeric
Alphanumeric Numeric edited
Alphanumeric
Alphanumeric Edited
Group Alphanumeric Elementary data
within the group may
Brackets [ ] mean item is optional, braces { } mean one of enclosed items required Ellipses (. . .) mean entry may be repeated
The ENVIRONMENT DIVISION consists of two separate sections - CONFIGURATION SECTION The CONFIGURATION SECTION consists of two paragraphs namely SOURCE-COMPUTER paragraph and OBJECT-COMPUTER paragraph. The SOURCE-COMPUTER paragraph specifies the computer on which the source program is to be compiled and the OBJECT-COMPUTER paragraph specifies the computer for which the object program is designated. INPUT-OUTPUT SECTION The INPUT-OUTPUT SECTION consists of two paragraphs namely FILE CONTROL paragraph and I-O CONTROL paragraph. In the FILE CONTROL paragraph a file name is selected for each file to be used in the program and assigned to a device.
DATA DIVISION The DATA DIVISION is used to declare the data items that will be processed in the PROCEDURE DIVISION of the source program. Though there are seven different SECTIONs in DATA DIVISION, which appear in the order – FILE SECTION The FILE SECTION is used to declare the FD (File descriptor) and SD (Sort descriptor) entries for files and sort files used in the program. WORKING-STORAGE SECTION The WORKING-STORAGE SECTION is used to declare all the temporary variables and record structures used in the program. LOCAL STORAGE SECTION The LOCAL-STORAGE SECTION defines storage that is allocated and freed on a per-invocation basis. On each invocation, data items defined in the Local-Storage Section are reallocated and initialized to the value assigned in their VALUE clauses. LINKAGE SECTION The LINKAGE SECTION is used to describe data items made available from another program. It is important to note that storage is not allocated to the data structures defined in the LINKAGE SECTION as the data exists elsewhere. COMMUNICATION SECTION The COMMUNICATION SECTION is used to create a control block required for communication, which is release dependent. REPORT SECTION The REPORT SECTION is used to describe RD (Report Descriptor) entries, which will be required for Report Writer Module. SCREEN SECTION The SCREEN SECTION is used to describe labels and data items, which will be required for formatted input/output in case of application programs developed for Personal computers. Of these the sections which are most commonly used are – WORKING-STORAGE SECTION FILE SECTION
PROCEDURE DIVISION The PROCEDURE DIVISION consists of the following – a) Sections b) Paragraphs c) Sentences d) Statements
PROCEDURE DIVISION The PROCEDURE DIVISION is the most significant DIVISION of a COBOL program. It includes statements and sentences necessary for reading input, processing it and writing the output.
Description of DATA NAMES a) All the data names used in the PROCEDURE DIVISION must be described in the DATA DIVISION. b) The description of a data name is done with the aid of the following – (1) Level number (2) PICTURE clause (3) VALUE clause
LEVEL NUMBER Level numbers specify the hierarchy of data within a record and identify special-purpose data entries. A level number begins a data description entry and 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. The following are the significance of the various level numbers that can be used with data items. a) 01 - For record descriptions. b) 02 to 49 - For fields within records. c) 01 / 77 - For independent items (use 01, as 77 will be removed in future releases) d) 66 - For RENAMES clause. e) 88 - For condition names.
PICTURE clause The following are the general picture characters and their meaning. a) A for alphabetic b) X for alphanumeric c) 9 for numeric d) S for sign e) V for implied decimal point.
Group and Elementary items In COBOL the term “group item” is used to describe a data item which has been further subdivided. Some properties of a Group item are – a) A Group item is declared using a level number and a data name. b) It cannot have a picture clause. c) Where a group item is the highest item in a data hierarchy it is referred to as a record and uses the level number 01.
LEVEL Numbers & DATA hierarchy In COBOL, Level numbers are used to express data hierarchy. The higher the level number, the lower the item is in the hierarchy. So Group items contain sets of elementary items with lower level numbers. At the lowest level the data is completely atomic (i.e. at the lowest level we would always have an elementary item).
Edited picture symbols There are two general methods of editing in a PICTURE clause. Insertion - There are four types of Insertion editing namely 1) Simple insertion 2) Special insertion 3) Fixed insertion 4) Floating insertion Suppression and Replacement - This is of two kinds 1) Zero suppression and replacement with asterisk 2) Zero suppression and replacement with spaces
BASIC DATA TYPES There are five basic data types in COBOL. They are a) Alphabetic - (Made up of only upper and lower case letters) b) Numeric - (Made up of the digits 0, 1, 2, . . . ,9) c) Alphanumeric - (Made of both letters and digits), d) Edited Numeric - (Made up of digits and special characters) e) Edited Alphanumeric - (Made up of letters, digits and special characters)