[go: up one dir, main page]

0% found this document useful (0 votes)
51 views15 pages

Module 2

Uploaded by

totorouuu5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views15 pages

Module 2

Uploaded by

totorouuu5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Module 2

Overview:
This module is a gives the detailed introduction and description of the COBOL program.
COBOL, a business oriented programming language which is very old but proven very useful and
helpful because of its unique structures. This module explains the uniqueness of the one and
only business programming language, very long program but easy to understand.

Module Objectives:
After successful Completion of this module, you should be able to:

● Know the importance and history of the COBOL program

● Learn and understand the basic structures of the COBOL programming


Where, How and Why we use COBOL
● In Mainframe COBOL is one of the most important programming languages
● COBOL is a programming language and we use it in multiple industries like Retail, Healthcare,
Insurance, Banking, Share Market, Finance and much more.
● And it is like the English language so it is self-documenting
● We can use 30years older COBOL code till now and run without any changes in modern
Mainframe server.
● COBOL is a procedural language and works well in legacy applications.
● Lots of COBOL programmers are retired and this is a great opportunity for a fresher to learn
COBOL to land a dream job.
● Most of the fortune 500 companies use Mainframe and COBOL is the most preferred
programming language is always a ‘MUST TO HAVE’ skills for a Mainframe Developer.

Introduction of COBOL​
● COBOL stands for Common Business Oriented Language.
● It is started in 1959 by CODASYL committee (Conference on Data Systems Language).
● COBOL programs appear like an ENGLISH language.
● COBOL can handle a huge volume of data.
● ANSI (American National Standards Institute) worked further on improving this and major
development took place in improvement in the year 1965 and 1974.
● The improved version of COBOL was introduced in 1985, with new features.
● In Mainframe COBOL is one of the most important programming languages
● COBOL is a programming language and we use it in multiple industries like Retail, Healthcare,
Insurance, Banking, Share Market, Finance and much more.
● And it is like the English language so it is self-documenting
● We can use 30years older COBOL code till now and run without any changes in modern
Mainframe server.
● COBOL is a procedural language and works well in legacy applications.
● Lots of COBOL programmers are retired and this is a great opportunity for a fresher to learn
COBOL to land a dream job.
● Most of the fortune 500 companies use Mainframe and COBOL is the most preferred
programming language is always a ‘MUST TO HAVE’ skills for a Mainframe Developer.

COBOL history
COBOL arose in the late 1950s and early 1960s. The development of the language was a project
sponsored by the United States Department of Defense (DoD) that included a consortium of
computer companies including IBM, Honeywell, Sperry Rand, and Burroughs. The goal was to
create a programming language with the following attributes:

● Portability between computer systems, thus making it easier to migrate software both across
generations of hardware and between hardware makers.
● More English-like syntax than other languages of the time (e.g., FORTRAN) as a way to encourage
programming by a wider audience, even if at the expense of some operational speed.
● The ability to accommodate future changes to the language.

The first official COBOL specifications came out in 1960. Over the next decade, and to the
consternation of its critics, COBOL became the default choice for writing business applications.
One reason for its fast spread was network effects: IBM, one of the original collaborators on the
language, became an aggressive early adopter, and IBM’s dominating presence in the computing
world helped contribute to COBOL adoption.

History of COBOL standards

The specifications approved by the full Short Range Committee were approved by the Executive
Committee on January 3, 1960, and sent to the government printing office, which edited and
printed these specifications as COBOL 60.

The American National Standards Institute (ANSI) has since produced several revisions of the
COBOL standard, including:

● COBOL-68
● COBOL-74
● COBOL-85
● COBOL 2002

From 2002, the ISO standard is also available to the public coded as ISO/IEC 1989.
Legacy

COBOL programs are in use global in governmental and military agencies, in commercial
enterprises, and on operating systems such as IBM’s z/OS, Microsoft’s Windows, and the POSIX
families (Unix/Linux etc.). In 1997, the Gartner Group reported that 80% of the world’s business
ran on COBOL it over 200 billion lines of code in existence and with an estimated 5 billion lines of
new code annually.

Near the end of the twentieth century the year 2000 problem was the focus of significant systems
decades before. The particular level of effort required for COBOL code has been attributed both
to the large amount of business-oriented COBOL, as COBOL is by of the COBOL language such as
the PICTURE clause, which can be used to define fixed-length numeric fields, including two-digit
fields for years.

COBOL 2002 and object-oriented COBOL

The COBOL2002 standard supports Unicode, XML generation and parsing, calling conventions to
and from non-COBOL languages such as C, and support for execution within framework
environments such as Microsoft’s .NET and Java (including COBOL instantiated as Enterprise
JavaBeans). Fujitsu and Micro Focus currently supports object- oriented COBOL compilers
targeting the .NET framework.

COBOL Advantages

● It is machine independent. A COBOL program can be executed in different types of


computer with slight or no modifications at all.
● It is easy to maintain. There are few modifications of the COBOL-74, it was revised only
in 1985 through COBOL-85, the latest began its modification only in late 1990s. Therefore,
a program that is easy to maintain can save a company considerable time and money.
● It is easy to understand. The programming language instructions or code contain
English-like words and phrases.
● COBOL programs are uniquely organized. Only four major parts are needed to
understand. These parts are called divisions.
● A COBOL program can handle voluminous commercial data processing using only a few
statements. COBOL is well suited for handling and processing large quantities of data by
writing several program statements using its input-output operations. This is unique in
comparison with other language.
● COBOL as defined in the original specification included a PICTURE clause for detailed
field specification. It did not support local variables recursion, dynamic memory
allocation, or structured programming constructs. Support for some or all of these
features have been added in later editions of the COBOL standard.
● COBOL has many reserved words (over 400), called keywords. The original COBOL
specification supported self-modifying code via the infamous “ALTER X TO PRECEED TO Y
“statement. This capability has since been removed.

Characteristics that contribute to COBOL’s success

● COBOL is self-documenting
One of the design goals for COBOL was to make it possible for non-programmers such
as supervisors, managers and users, to read and understand COBOL code. As a result,
COBOL contains such English-like structural elements as verbs, clauses, sentences,
sections and divisions. As it happens, this design goal was not realized. Managers and
users nowadays do not read COBOL programs. Computer programs are just too
complex for most laymen to understand them, however familiar the syntactic
elements. But the design goal and its effect on COBOL syntax has had one important
side-effect. It has made COBOL the most readable, understandable and
self-documenting programming language in use today. It has also made it the most
verbose.

It is easy for programmers unused to the business programming paradigm, where


programming with a view to ease of maintenance id very important, to dismiss the
advantage tat COBOL’s readability imparts. Not only does this readability generally
assist the maintenance process but the older a program gets the more valuable this
readability becomes.

When programmers are new, both the in-program comments and the external
documentation accurately reflect the program code. But over time as more and more
revisions are applied to the code, it gets out of step with the documentation until the
documentation is actually a hindrance to maintenance rather than a help. The
self-documenting nature of COBOL means that this problem is not as severe with
COBOL programs as it is with other languages.

● COBOL is simple
COBOL is a simple language (no pointers, no user defined functions, no user defined
types) with a limited scope of function. It encourages a simple straightforward
programming style. Curiously enough though, despite its limitations, COBOL has
proven itself to be well suited to its targeted problem domain (business computing).
Most COBOL programs operate in a domain where the program complexity lies in the
business rules that have to be encoded rather than in the sophistication of the data
structures or algorithms required. And in cases where sophisticated algorithms are
required COBOL usually meets the need with an appropriate verb such as the SORT and
the SEARCH.

We noted above that COBOL is a simple language with a limited scope of function. And
that is the way it used to be but the introduction of OO-COBOL has changed all that.
OO-COBOL retains all the advantages of previous versions but now includes-

User Defined Functions


Object Orientation
National Characters – Unicode
Multiple Currency Symbols
Cultural Adaptability (Locales)
Dynamic Memory Allocation (pointers)
Data Validation Using New VALIDATE Verb
Binary and Floating Point Data Types
User Defined Data Types

● COBOL is non-proprietary (portable)


The COBOL standard does not belong to any particular vendor. The vendor
independent ANSI COBOL committee legislates formal, non-vendor-specific syntax and
semantic language standards. COBOL has been ported to virtually every hardware
platform – from every favor of Windows, to every falser of UNIX, to AS/400, VSE, OS/2,
DOS, VMS, Unisys, DG, VM, and MVS.
● COBOL is Maintainable
COBOL has a 30 year proven track record for application maintenance, enhancement
and production support at the enterprise level. Early indications form the year 2000
problem are that COBOL applications were actually cheaper to fix than applications
written in more recent languages.[Capers Jones] [Kappleman] One reason for the
maintainability of COBOL programs has been given above – the readability of COBOL
code. Another reason is COBOL’s rigid hierarchical structure. In COBOL programs all
external references, such as to devices, files, command sequences, collating
sequences, the currency symbol and the decimal point symbol, are defined in the
Environment Division.

FEATURES OF A COBOL PROGRAM

A. English-like syntax
B. Unusual length compared with programs written in other languages.
C. Column-sensitive organization of the program.
D. Spacing between any two-program segments.
E. Use of indentations.

Structure of COBOL Program

You must write the COBOL programs in an organized way. It must follow a modular programming
approach which is a subset of procedural programming approach.
The COBOL program consists of a logical structure and this is called structure COBOL
programming.
Please follow these important points while designing your COBOL program –

● A COBOL Program is divided into DIVISION. Each DIVISION in COBOL Programs is further divides
into SECTION.
● A SECTION is further divided into PARAGRAPH.
● PARAGRAPH is divided into multiple SENTENCE.
● A SENTENCE contains STATEMENT.
● A STATEMENT is subdivided into CLAUSE or VERB.
● At the lowest Level, we have CHARACTER or WORD.

//realia -- compiler

COBOL Coding Rules

COBOL coding rules are very important and you should follow a particular COBOL format because
of COBOL of structured programming language.

This picture shows the major areas in a COBOL Program.


Areas in COBOL Program
Column 7

* comment

- continuation “COM

- PUTE”

/ - next page printing


There are 5 areas in COBOL Program –
1. Sequence Number Area
2. Indicator Area
3. Area A
4. And Area B
5. Program Identification Area

1. Sequence Number Area


● Column 1 to Column 6 is the Sequence Number area.
● The Sequence number area stores the Sequence numbers.
● And it’s number is for labeling a source statement line.
In the above picture of a COBOL program, the numbers in yellow area(column 1-6) are Sequence
numbers.

Question: Can you find the sequence numbers in the below?


|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 01 SEQUENCE-NUMBER PIC 9(03.
000002 01 WS-TEMP-VAR PIX X(3).
Answer
000001
000002

2. Indicator Area
● Column 7 is the Indicator Area in COBOL.
● You can start Comments, Continuation or Debugging mode(D) in this Indicator Area.
CommentsTo give a comment a line in COBOL, you can give an 'asterisk' i.e. '*' symbol in Column 7

The Syntax of Comment:


|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 *THIS IS A COMMENT IN COBOL
Example of Comments in the COBOL program

Continuation

If you are writing a COBOL program and for some reason, you are not able to fit your current code
in a line, then you can continue it from the next line by providing a hyphen i.e. '-' symbol in the
7th column.
Note: We will discuss Continuation in detail as we will move further.
The Syntax of Continuation:
|----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
000001 -

3. Area A
● Area A Starts from Column 8 to Column 11.
● All Division, Section, Paragraph, Start Declarative, End Declarative, 01 Level number must start
in Area A.

Example of Area A

In this sample screenshot, you can see that DIVISION, SECTION and 01 LEVEL starts from Area A.

4. Area B
● Area B Starts from Column 12 to Column 72.
● All Statement, Sentence, Verbs, Clause, Characters, and Words must start in Area B.
The Sentence is divided into various types of Statements and there can be one or more statements
in a sentence.

Let us take all the lines one by one –


Line1 – DISPLAY “HELLO WORLD”.
This is a Sentence which is also a Statement.

Line2 – MOVE A TO B // equivalent to B = A


This is a Statement.

Line3 – MOVE C TO D // equivalent to D = C


This is also a Statement.

Line4 – COMPUTE E = C + D.
This is also a Statement.

If we combine Line 2, Line 3 and Line 4, then it becomes a Sentence so at the end of a Sentence,
we must have a dot(.).
In, MOVE A TO B, MOVE is a verb.
Similarly, COMPUTE E = C + D. -> Here COMPUTE is also a Verb.
Example of Area B

In this sample screenshot, you can see that statement, sentence etc are starting in Area B.

5.Program Identification Area


● Program Identification area in COBOL Program is the area between column 73 to column 80.
● They do not have much relevance in today’s world.
● The idea of using this area was to enter the program identification of each individual lines in
the code.
Example of Program Identification Area

Record Layouts

A record layout is a description of all the individual fields that comprise each record in the
data file. COBOL layouts follow specific rules. Since we are not teaching you how to program in
COBOL, we will only discuss the rules you need to know to read layouts.

The layout specifies at-least the name of each field, its type, size, and position in the record. A
layout may give a detailed description of the use of each field and the values found in it, but that
information is often contained in the data dictionary. A COBOL layout usually pertains to a single
disk or tape file, as opposed to a table within a database.

Fields and the PIC clause

The lowest level data item in a COBOL layout is a field, also called an elementary item. Several
fields can be associated to form a group. All the fields together form a record.

A COBOL layout is comprised of a line for each field or group. A COBOL field definition gives
the level (discussed later), field name, and a "picture", or PIC clause, which tells you the data
type or data category of the field, and its size. The three data types you are likely to see are:
1. "A" for alpha (A-Z, a-z, and space only).
2. "9" for a numeric field (numbers 0-9, but no letters).
3. "X" for any character, (including binary).

For example, the following field (elementary item) is called ZIP-CODE and is 5 digits wide, as
specified by the five 9s. i.e., the "picture" of the field is "99999".
05 ZIP-CODE PIC 99999.
This could also be written:
05 ZIP-CODE PIC 9(5).
Where the 9 means the field type is numeric, like the first example, and the (5) says there are
five digits. The 9(5) and the 99999 are identical field specifications. The parentheses are usually
used when it makes the definition shorter or clearer, as in 9(11) vs: 99999999999. The period at
the end separates this field definition from the next one.

A character field such as last name could be written:

05 LAST-NAME PIC A(15).


Meaning it's a 15 character alphabetic field. But it's actually more common to see character fields
specified as PIC X, like:
05 LAST-NAME PIC X(15).
PIC X allows any character, including numbers, punctuation, and binary codes.

Like the numeric example above, a PIC X field specification could be written as either multiple Xs
or a count in parentheses, like these two identical field specifications:

05 LAST-NAME PIC X(15).


05 LAST-NAME PIC XXXXXXXXXXXXXXX.

Although not commonly seen in COBOL files, you can mix types in a field. For example,

05 ZIP-PLUS-9 PIC 99999X9999.


permits a dash (or anything) between ZIP and ZIP+4, like 01886-2001.

A decimal point in a PIC, like "PIC 999.99" separates the integer portion from the decimal
portion. This is discussed in more detail later, along with implied decimal.

Let's practice one more, just to get the point across. The following are different ways of
specifying the same thing:

05 AMOUNT PIC 999.99.


05 AMOUNT PIC 9(3).9(2).
05 AMOUNT PIC 9(3).99.
05 AMOUNT PIC 999.9(2).

Filler

There is a special type of COBOL field called FILLER. This reserves space in a COBOL record,
commonly for future expansion or to fill a gap created by a redefined field. FILLER is a reserved
word, and you can have as many FILLER fields in a record as you want -- the name does not have
to be unique as field names generally must be.
Filler can also be used to create a field, or place holder, that you will never need to refer to by
name, so you might find it contains actual data, not just blank space.

It's also common for a vendor to use fields for some internal purpose, for example as a key field,
but to mark those fields as FILLER when the data is sent outside the company. So FILLER fields can
contain anything, including binary data. You should not expect them to be neatly filled with
spaces.

Special Formatting Characters

There are a number of special characters that cause specific actions on the data, such as leading
zeros or spaces, floating signs, leading or trailing signs, decimal points, etc. We will mention only
a few common ones:

1. A literal in a field causes that character to appear in that location. For example,

05 ZIP-PLUS-9 PIC 99999-9999.


specifies a field with five digits, a dash, and four more digits. The dash is not part of the variable
data -- it is a literal character.

2. A decimal point in a numeric field does two things: it places an actual decimal point into the
file, and determines the location of the decimal for calculations. The following field is six bytes
wide and has a "real decimal" in the file:

05 AMOUNT PIC 999.99.


If you view a record containing the value 123.45 in this field, you will see "123.45"

3. A "V" in the PIC clause specifies the location of an implied decimal. This is discussed later, in
the section on numeric fields. The following field is five bytes wide and has an "implied decimal"
at the location of the V:

05 AMOUNT PIC 999V99.


If you view a record containing the value 123.45 in this field, you will see "12345" .

4. A minus sign, "-", reserves a byte in the record for an actual sign, and puts a "-" in negative
values, and a space in positive values.

5. Similarly, a "+" in the PIC puts a "-" in negative values and a "+" in positive values. See the
section below on "signed fields" for the representation of PIC S9 fields.

6. A "P" in a PIC clause scales the value. This is seldom seen, so we will be brief, via two
examples:

The three 9s cause this field to be three bytes in size, and the three Ps scale it UP
PIC
by 1000. If the field contains the digits 123, the actual value represented is
999PPP.
123,000.

PIC This scales the value DOWN. If the field contains the digits 123 the actual value is
PPP999. 0.000123
Columns, Line Numbers, and Comments

Columns 1-6 in most COBOL layouts are ignored by the compiler, as is everything after column 72.
You will often find line numbers or other comments (such as when a field was added or changed,
or where it originated) in these columns. These may be useful to you in finding your way around a
large layout; just be aware they are ignored by the compiler.

COBOL layouts are divided into "areas", and there are many rules for what data may be found in
which area, but one you should remember is that an asterisk, *, in column 7, the "indicator area"
turns the entire line into a comment, which is ignored by the COBOL compiler. Even if that line
contains a field specification, it will be ignored if there is an * in column 7.

There are variations on COBOL layouts that discard columns 1-6, shifting the entire layout left.
And, some printed documentation may not show these columns. You can usually find your place in
the layout from the 01 level, which normally starts in column 8. All other levels should start in
column 12 or above.

A COBOL field definition does not need to be entirely on one line. A line-ending has no
significance to the compiler; it's the period at the end that's the COBOL separator, not the
carriage-return.

Levels and Groups

COBOL layouts have levels, from level 01 to level 49. These levels tell the COBOL compiler how
to associate, or group, fields in the record. Level 01 is a special case, and is reserved for the
record level; the 01 level is the name of the record. Levels from 02 to 49 are all "equal" (level 2 is
no more significant than level 3), but there is a hierarchy to the structure. Any field listed in a
lower level (higher number) is subordinate to a field or group in a higher level (lower number).
For example, LAST-NAME and FIRST-NAME in the example below are part of, or belong to, the
group CUSTOMER-NAME, as can be seen by the level numbers of 05 and 10.
05 CUSTOMER-NAME.
10 LAST-NAME PIC X(15).
10 FIRST-NAME PIC X(8).
Notice that CUSTOMER-NAME does not have a PIC, since it's a group, not a field. Also notice that
the two fields within the group are at a lower level, level 10, than the 05 group. Lower levels are
normally indented further for clarity, but this is not required, and in fact the compiler doesn't
care.

For the rest of this tutorial we will use levels 05, 10, and 15 to be consistent. Just remember
these choices are arbitrary; we could have used 02, 03, and 04, or any other numbers between 02
and 49.

There can be many levels. Here is a brief example of a record with three levels:

01 MAILING-RECORD.
05 COMPANY-NAME PIC X(30).
05 CONTACTS.
10 PRESIDENT.
15 LAST-NAME PIC X(15).
15 FIRST-NAME PIC X(8).
10 VP-MARKETING.
15 LAST-NAME PIC X(15).
15 FIRST-NAME PIC X(8).
10 ALTERNATE-CONTACT.
15 TITLE PIC X(10).
15 LAST-NAME PIC X(15).
15 FIRST-NAME PIC X(8).
05 ADDRESS PIC X(15).
05 CITY PIC X(15).
05 STATE PIC XX.
05 ZIP PIC 9(5).
Most of the fields in this record (company, address, city, state, zip) are simple fields that need no
comment. But there are some interesting things about the contact fields:

There is a group called CONTACTS at the 05 level. Within this group are three 10 level groups.
The first one is PRESIDENT, and within this group are the LAST-NAME and FIRST-NAME fields for the
president. So far this is similar to the previous example, with one more level. This group is 23
bytes (15 + 8).

Next we have a group to contain the name of the VP of Marketing. This group is also 23 bytes.
Notice it uses the same field names, LAST-NAME and FIRST-NAME, as used in the president's group.
Although this isn't commonly seen, it is permitted in COBOL. They are considered different fields
because they are within different groups. In COBOL you distinguish them by referring to
"LAST-NAME OF PRESIDENT" for the president's name, and "LAST-NAME OF VP-MARKETING" for the
name of the VP of Marketing.

The last group in the CONTACTS group is for "alternate contacts". This one contains a field called
TITLE which contains the title of the alternate contact (e.g., CEO). Like the others, it contains
LAST-NAME and FIRST-NAME fields. This group is 33 bytes.

COBOL's 66 and 88 Levels

These two levels have special meaning. The 66 level assigns an alternate name to a field or
group. It doesn't add a new field to the record, it just assigns an alternate name to an existing
field. You are not likely to see level 66.

You are likely to see the 88 level, though. The 88 level simply equates a value with a name.
Here's a simple example:

05 SEX PIC X.
88 MALE VALUE "M".
88 FEMALE VALUE "F".
This equates the value "M" with "MALE", and the value "F" with "FEMALE" for the field SEX. (This
allows your COBOL program to, for example, test IF MALE rather than having to say IF SEX IS
EQUAL TO "M"). Since we are not teaching COBOL programming, this is incidental to us, but here's
what is important to know about the 88 level:

1. The 88 level does not define a field, and does not take space in the record; it is merely a
value definition.
2. The 88 level does not limit the possible codes to only those listed. There could be other
values used in that field; M and F are not the only values you might find. (Although a
good layout will list them all.) In this case there might be a "U" (unknown), or a blank.
3. If the layout is complete, this is a handy list of the values you can expect to find in this
field. Sometimes it's all you have to go on.

88 levels may specify multiple values, or a range of values, such as:


88 ODD-NUMBERS VALUE 1, 3, 5, 7, 9.
88 PRE-SCHOOL VALUE 0 THROUGH 4.

Course Materials:

https://www.tutorialbrain.com/mainframe/cobol_divisions/

https://devops.com/the-beauty-of-the-cobol-programming-language-v

https://www.infoworld.com/article/3539057/what-is-cobol-cobol-programming-explained.html

http://www.3480-3590-data-conversion.com/article-reading-cobol-layouts-1.html

You might also like