You are on page 1of 15

What is COBOL

Authors:
Deepali Kayande
Anuja Jadhav
Sample Cobol Program
IDENTIFICATION DIVISION.
PROGRAM-ID. Multiplier.
AUTHOR. Abc.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.

PROCEDURE DIVISION.
DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING.
ACCEPT Num1.
DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING.
ACCEPT Num2.
MULTIPLY Num1 BY Num2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.
Flow of Cobol Program
IDENTIFICATION DIVISION.

ENVIRONMENT DIVISION.

DATA DIVISION.

PROCEDURE DIVISION.
Comparison With C
main() IDENTIFICATION DIVISION.
PROGRAM-ID. Multiplier.
{ AUTHOR. Abc.
int i,j,k;
printf(“Enter a number”); ENVIRONMENT DIVISION.
scanf(“%d”, &i); INPUT-OUTPUT SECTION.

printf(“Enter a number”); DATA DIVISION.


scanf(“%d”, &j); WORKING-STORAGE SECTION.
k=i*j; 01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
printf(“%d” ,k); 01 Result PIC 99 VALUE ZEROS.
}
PROCEDURE DIVISION.

DISPLAY "Enter first number (1 digit) :" WITH NO ADVANCING.


ACCEPT Num1.
DISPLAY "Enter second number(1digit) :“ WITH NO
ADVANCING.
ACCEPT Num2.
MULTIPLY Num1 BY Num2 GIVING Result.
DISPLAY "Result is = ", Result.
STOP RUN.
Cobol Program

IDENTIFICATIO PROCEDURE
N DIVISION. DIVISION.

ENVIRONMENT
DATA DIVISION
DIVISION.

Para-1.

CONFIGURA
TION INPUT-
SECTION OUTPUT
SECTION
WORKING-
FILE STORAGE
SECTION SECTION
What is Cobol
FORMAT FOR COBOL PROGRAMS

Field
Column
1-3 Page Number

4-6 Line Number (1-6 Sequence Number)

7 Continuation / Comment

8-11
A – Margin / Area A
12-72 B- Margin /Area B

73-80 Identification
STRUCTURE OF A COBOL PROGRAM
Every COBOL program must have the following Four divisions
in the order in which they are specified below.
1. Identification division
2. Environment Division
3. Data Division
4. Procedure Division
Identification division In the Identification division the
details about the author, date of
writing the program etc
Will be specified.
Environment Division In the Environment division, the
details about the computer
environment under which
the program was written and compiled
etc will be notified.
Data Division In the Data division, the variables that
are used by the program will be
defined and it is
an important division for the program.
Procedure Division In the procedure division, all the
programming statements (Executable
Cobol statements) will be written and
it is the most important division.
CHARACTER SET
0-9 10 numerals
A-Z 26 English alphabets-only capital
letters
– minus sign or hyphen
+ Plus sign
* Asterisk
/ Slash
0= Equal sign
$ Currency sign
,,; Comma, Semi colon
<,> Greater than symbol, Less than
symbol
. Period or decimal point
“ Quotation mark
( ,) Left Parenthesis, Right Parenthesis
A COBOL word can be formed using the following characters:
0-9,A-Z (a-z), - (hyphen)
Rules for Creating Cobol words
a) A word cannot begin or end with a hyphen.
b) A word can have at the maximum 30 characters.
c) One of the characters must be a letter. Some compilers put the
additional restrictions that the first character must be a letter.
d) Except hyphen (-) no special character allowed.
 
 
LITERALS
literal is the specific value which remains
unchanged throughout the execution of the
program. There are 3 types of literals
a) numeric
b) nonnumeric
c) figurative constants
(a) Numeric

A numeric literal can be formed with the help of digits only

Examples
(i) Valid Numeric Literal (ii) Invalid Numeric
Literals
.123 ‘’123’’(valid as
nonnumeric literal but
invalid as numeric
literal)
12.5 - 23 (there is a blank
space between the
sign and the first digit 2)
(b) Nonnumeric

A nonnumeric literal is used in general to output messages or headings.


Characters that are enclosed between “ “ constitute nonnumeric literal.

Ex:- “BHARATHIAR”
“DATA DIVISION”
“100.50”
“HOUR/RATE”
c) Figurative Constants

value 0
ZERO ZEROS ZEROES
SPACE SPACES
One or more blanks

Highest value in the


HIGH-VALUE HIGH-VALUES
Collating sequence

Lowest value in the


LOW-VALUE LOW-VALUES
Collating sequence
QUOTE QUOTES
one or more of “
ALL literal
One or more of the string Characters
comprising the literal

You might also like