Introduction to Cobol Programming
COBOL is a third-generation programming language, and one of
the oldest programming languages still in active use.
|
Cobol Basics
Coding Areas, Syntax, The
Hello World Program.
|
Cobol Divisions
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.
|
Data Division
The data division is where memory space in
the computer is allocated to data and identifiers that are to be used by the
program.
|
Procedure Division
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.
|
Number Formats
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.
|
Initializing Data
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.
|
Tables
Also known as an array in other languages, a table is a
group of data associated with a single item name.
|
Boolean Data
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.
|
Move
The MOVE statement has already been extensively used in the examples in the Defining Data section.
|
Perform
The PERFORM verb is one of the most important in COBOL
(alongside MOVE).
|
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.
|
Conditions
There are four types of conditions that could be tested
either in a PERFORM, IF..THEN, or EVALUATE.
|
Cobol Evaluate
If there are a large number of conditional alternatives,
then using a large number of nested IF statements can be messy.
|
Cobol Strings
STRING will move a series of strings into a destination
string.
|
Cobol Write
To output data to the printer or to a file, the verb WRITE
is used.
|
Scope Terminators
In the section
COBOL basics I mentioned the full stop (period).
|
File Handling
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
|