Com 213 Oocobol
Com 213 Oocobol
IN AFFILIATION WITH
TEMPLE GATE POLYTECHNIC
ABA, ABIA STATE.
COURSE TITLE: COMMERCIAL PROGRAMMING USING OOCOBOL
COURSE CODE: COM 213 DEPARTMENTS: COMPUTER SCIENCE
TIME ALLOWED: 2 HOURS INSTRUCTIONS: ANSWER FIVE QUESTIONS
QUESTION 1
QUESTION 2
b. The COBOL programme structure consists of various divisions. Briefly state these
divisions (10
marks)
QUESTION 3
a. What are the five fields of character positions (5 marks)
b. What is a comment and describe the two types of comment (9 marks
QUESTION 4
a. What are figurative constants and description. List five of them (6 marks)
b. Define data name, level number, picture clause and value clause (8 marks)
QUESTION 5
d. What are conditional statements and state four different types of conditional
statements (6 marks)
QUESTION 7
a. State the loop statements used in COBOL (4 marks)
b. List and explain the three string handling statements (10 marks)
Marking Scheme
1a.
In 1999 they reported that over 50% of all new mission-critical applications were still
being done in COBOL and their recent estimates indicate that through 2004-2005 15% of all
new applications (5 billion lines) will be developed in COBOL while 80% of all deployed
applications will include extensions to existing legacy (usually COBOL) programs.
Gartner estimates for 2002 are that there are about two million COBOL programmers world-
wide compared to about one million Java programmers and one million C++ programmers.
COBOL is one of the oldest programming languages in use. As a result it has some
idiosyncrasies which programmers used to other languages may find irritating. When
COBOL was developed (around the end of the 1950's) one of the design goals was to make it
as English-like as possible. As a result, COBOL uses structural concepts normally associated
with English prose such as section, paragraph and sentence. It also has an extensive reserved
word list with over 300 entries and the reserved words themselves tend to be long. COBOL
programs tend to be verbose especially when compared to languages like C. When COBOL
was designed, programs were written on coding forms punched on to punch cards, and
loaded into the computer using a punch card reader. These media (coding forms and punch
cards) required adherence to a number formatting restrictions that some COBOL
implementations still enforce today, long after the need for them has gone. Although modern
COBOL (COBOL 85 and OO-COBOL) has introduced many of the constructs required to
write well structured programs it also still retains elements which, if used, make it difficult,
and in some cases impossible, to write good programs.
1b
IMPORTANCE OF COBOL
COBOL was the first widely used high-level programming language. It is an English-
like language which is user friendly. All the instructions can be coded in simple English
words.
COBOL is also used as a self-documenting language.
COBOL can handle huge data processing.
COBOL has effective error messages and so, resolution of bugs is easier.
2a
FEATURES OF COBOL
Standard Language: COBOL is a standard language that can be compiled and executed on
machines such as IBM AS/400, personal computers, etc.
Business Oriented: COBOL was designed for business-oriented applications related to
financial domain, defense domain, etc. It can handle huge volumes of data because of its
advanced file handling capabilities.
Robust Language: COBOL is a robust language as its numerous debugging and testing
tools are available for almost all computer platforms.
Structured Language: Logical control structures are available in COBOL which makes it
easier to read and modify. COBOL has different divisions, so it is easy to debug.
3a.
Character positions are grouped into the following five fields −
Position Field Description
s
Character Strings
Character strings are formed by combining individual characters. A character string can be a
Comment,
Literal, or
COBOL word.
All character strings must be ended with separators. A separator is used to separate
character strings.
4a.
Figurative constants are constant values like ZERO, SPACES, etc. All the constant values
of figurative constants are mentioned in the following table.
Figurative Constants
Sr.No. Figurative Constants & Description
1 HIGH-VALUES
One or more characters which will be at the highest position in
descending order.
2 LOW-VALUES
One or more characters have zeros in binary representation.
3 ZERO/ZEROES
One or more zero depending on the size of the variable.
4 SPACES
One or more spaces.
5 QUOTES
Single or double quotes.
6 ALL literal
Fills the data-item with Literal.
4b.
Data Name
Level Number
Picture Clause
Value Clause
5a.
COBOL verbs are used in the procedure division for data processing. A statement always
starts with a COBOL verb. There are several COBOL verbs with different types of actions.
5b.
The following two verbs are used for this process −
Accept Verb
Accept verb is used to get data such as date, time, and day from the operating system or
directly from the user. If a program is accepting data from the user, then it needs to be
passed through JCL.
Display Verb
Display verb is used to display the output of a COBOL program.
Initialize Verb
Initialize verb is used to initialize a group item or an elementary item. Data names with
RENAME clause cannot be initialized. Numeric data items are replaced by ZEROES.
Alphanumeric or alphabetic data items are replaced by SPACES.
Move Verb
Move verb is used to copy data from source data to destination data. It can be used on both
elementary and group data items. For group data items, MOVE CORRESPONDING/CORR
is used. In try it option, MOVE CORR is not working; but on a mainframe server, it will
work.
For moving data from a string, MOVE(x:l) is used where x is the starting position and l is
the length. Data will be truncated if the destination data item PIC clause is less than the
source data item PIC clause. If the destination data item PIC clause is more than the source
data item PIC clause, then ZEROS or SPACES will be added in the extra bytes. The
following example makes it clear.
5c.
Add Verb
Add verb is used to add two or more numbers and store the result in the destination operand.
In syntax-1, A, B, C are added and the result is stored in C (C=A+B+C). A, B, D are added
and the result is stored in D (D = A + B + D).
In syntax-2, A, B, C, D are added and the result is stored in E (E=A+B+C+D).
In syntax-3, sub-group items within WS-GROUP1 and WS-GROUP2 are added and
Subtract Verb
6a.
Multiply Verb
Multiply verb is used for multiplication operations.
In syntax-1, A and B are multiplied and the result is stored in B (B=A*B). A and C are
multiplied and the result is stored in C (C = A * C).
In syntax-2, A and B are multiplied and the result is stored in E (E=A*B).
When you compile and execute the above program, it produces the following result
Divide Verb
Divide verb is used for division operations.
Syntax
Given below is the syntax for division operations −
In syntax-1, B is divided by A and the result is stored in B (B=B/A).
In syntax-2, A is divided by B and the result is stored in C (C=A/B) and the remainder is
stored in R.
6b.
Redefines Clause
Redefines clause is used to define storage with different data description. If one or more
data items are not used simultaneously, then the same storage can be utilized for another
data item. So the same storage can be referred with different data items.
Level numbers of redefined item and redefining item must be the same and it cannot be 66
or 88 level number. Do not use VALUE clause with a redefining item. In File Section, do
not use a redefines clause with 01 level number. Redefines definition must be the next data
description you want to redefine. A redefining item will always have the same value as a
redefined item.
Renames Clause
Renames clause is used to give different names to existing data items. It is used to re-group
the data names and give a new name to them. The new data names can rename across
groups or elementary items. Level number 66 is reserved for renames.
6c.
A COBOL copybook is a selection of code that defines data structures. If a particular data
structure is used in many programs, then instead of writing the same data structure again,
we can use copybooks. We use the COPY statement to include a copybook in a program.
COPY statement is used in the Working Storage Section.
6d. Conditional statements are used to change the execution flow depending on certain
conditions specified by the programmer. Conditional statements will always evaluate to true
or false. Conditions are used in IF, Evaluate, and Perform statements. The different types of
conditions are as follows −
IF Condition Statement
Relation Condition
Sign Condition
Class Condition
Condition-Name Condition
Negated Condition
Combined Condition
7a.
The loop statements used in COBOL are −
Perform Thru
Perform Until
Perform Times
Perform Varying
7b.
String handling statements in COBOL are used to do multiple functional operations on
strings. Following are the string handling statements −
Inspect
String
Unstring
Inspect
Inspect verb is used to count or replace the characters in a string. String operations can be
performed on alphanumeric, numeric, or alphabetic values. Inspect operations are
performed from left to right. The options used for the string operations are as follows −
Tallying
Tallying option is used to count the string characters.
The parameters used are −