Introduction to Cobol Programming
COBOL is a third-generation programming language, and one of
the oldest programming languages still in active use.
Coding Areas, Syntax, The
Hello World Program.
The Four Cobol Divisions.
The Identification Division
The identification division tells the computer the name of the program and
supplies other documentation concerning the program's author.
The Environment Division
This division tells the computer what the program will be interacting with
(i.e. its environment) such as printers, disk drives, other files etc.
The data division is where memory space in
the computer is allocated to data and identifiers that are to be used by the
The procedure division is where the logic of
the program actually found.
Defining Data Part 1
A large portion of any COBOL program consists of the data division and how the
data is defined and manipulated.
There are three types of number formats.
Moving and Editing Data
Care must be taken when moving (using the MOVE verb) data to an item.
During a program run it is often necessary to reset an
item, or group of items, back to zero (or other value), or back to a certain literal.
Defining Data Part 2
How data is prepared for printing or for writing to a file is largely controlled
by how it is defined in the data division.
Printing and Writing Data
The specific commands used for printing or writing data
are given in the Commands and logic sections.
Also known as an array in other languages, a table is a
group of data associated with a single item name.
Boolean data is either TRUE or FALSE.
HIGH-VALUES and LOW-VALUES
There are occasions when you may wish to set a variable to
an infinitely high or infinitely low number.
Commands and Logics
Commands and Logics
Accept and Display
To enter data via the console during a program run, use
the ACCEPT verb.
The MOVE statement has already been extensively used in the examples in the Defining Data section.
The PERFORM verb is one of the most important in COBOL
Cobol IF... THEN...ELSE...
Another fundamental part of programming logic is the
ability to offer a choice of what to do that depends on the conditions asked of.
There are four types of conditions that could be tested
either in a PERFORM, IF..THEN, or EVALUATE.
If there are a large number of conditional alternatives,
then using a large number of nested IF statements can be messy.
STRING will move a series of strings into a destination
To output data to the printer or to a file, the verb WRITE
In the section
COBOL basics I mentioned the full stop (period).
This section outlines how data can read from and written to files.
Reading and Writing
In order to either read, alter or create a new file, we must first open it (even if it doesn't even exist yet).
REWRITE, DELETE, and EXTEND
In order to ammend a record in a file, such as to update
data (see League Table Program
in sample programs section)
SORT and MERGE
If you wished to take a file of unordered records and produce a new file of these records sorted into ascending or descending order of a field you would use SORT.
Input and Output Procedure
The SORT statement above sorted all the records in the
file into a new file.
FILE STATUS (error handling)
A number of errors can occur that result from file
input/output that programmer may wish to be able to deal with in order to avoid unexpected program termination.
Debugging COBOL Code
Debugging COBOL code