Chapter 1
Chapter 1
Chapter 1
PROGRAMMING
Chapter 1
A COBOL Program
000100
000200
000300
000400
000500
000600
000700
000800
000900
001000
001100
IDENTIFICATION DIVISION.
PROGRAM-ID. Hello.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
PROGRAM-BEGIN. Paragraph
DISPLAY "Hello world".
Statement
PROGRAM-DONE.
STOP RUN.
Divisions
Sentence
IDENTIFICATION DIVISION.
PROGRAM-ID. Sentences.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
PROGRAM-BEGIN.
DISPLAY "This program contains four DIVISIONS,".
DISPLAY "three PARAGRAPHS".
DISPLAY "and four SENTENCES".
PROGRAM-DONE.
STOP RUN.
000100
IDENTIFICATION DIVISION.
000200
PROGRAM-ID. Comment.
000300
ENVIRONMENT DIVISION.
000400
DATA DIVISION.
MB072197
000500
PROCEDURE DIVISION.
000600
000700 * This is a comment.
MB072197
000800 * This paragraph displays information about the program.
000900
PROGRAM-BEGIN.
003700
DISPLAY "This program contains four DIVISIONS,".
003800
DISPLAY "three PARAGRAPHS".
MB072197
001000
DISPLAY "and four SENTENCES".
001100
PROGRAM-DONE.
001200
STOP RUN.
MB072197
MB072197
GUESS
THE
OUTPUT!
Programming Style
All user-defined names must adhere to following
rules:
Must contain at least 1 character and not more than 30 characters
Must contain at least one alphabetic character and must not begin or
end with a hyphen
Must be constructed from the characters A to Z, numbers 0 to 9, and
hyphen
Names are not case-sensitive. But it is good a good programming
practice to use uppercase for reserved words and mixed case for userdefined names
COBOL reserved words cannot be used as user-defined name
Exercises
Answers the following questions based on codes below:
000100
000200
000300
000400
000500
000600
000700
000800
000900
001000
IDENTIFICATION DIVISION.
PROGRAM-ID. BYEBYE.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
PROGRAM-BEGIN.
DISPLAY "Bye bye birdie".
PROGRAM-DONE.
STOP RUN.
Exercises
6. What is wrong with the following, class02.cbl?
000100
000200
000300
000400
000500
000600
000700
000800
000900
001000
IDENTIFICATION DIVISION.
PROGRAM-ID. CLASS.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
PROGRAM-BEGIN.
DISPLAY First class".
PROGRAM-DONE.
STOP RUN.
Exercises
7. What is wrong with the following, class03.cbl?
000100
000200
000300
000400
000500
000600
000700
000800
000900
001000
IDENTIFICATION DIVISION.
PROGRAM-ID. CLASS.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
This program display a message.
PROGRAM-BEGIN.
DISPLAY First class".
PROGRAM-DONE.
STOP RUN.