Skip to main content

COBOL Procedure Division: Logic, File Handling, and Data Manipulation

Explore the COBOL PROCEDURE DIVISION, focusing on executable instructions, program logic with paragraphs and PERFORM statements, sequential file handling (opening, reading, writing, AT END clause), and data manipulation using the MOVE statement and basic arithmetic.

Save this reading to your study set

Sign up free

In COBOL programming, the PROCEDURE DIVISION is where the "action" happens. While the DATA DIVISION defines what your data looks like, the PROCEDURE DIVISION contains the actual executable instructions that tell the computer what to do with that data. This includes performing arithmetic, moving information between fields, handling files, and controlling the flow of the program through logic and loops.

The Structure of Logic: Paragraphs and Control

The PROCEDURE DIVISION is organized into a hierarchy of modules known as paragraphs. A paragraph is a named block of code that performs a specific task. In a well-structured program, a "main" paragraph acts as a controller, using the PERFORM statement to call subordinate paragraphs to do the heavy lifting.

For example, a high-level paragraph named 200-COMPUTE-PAY might control three specific sub-tasks: 300-COMPUTE-GROSS-PAY, 301-COMPUTE-TAX-PAYABLE, and 302-COMPUTE-NET-PAY. This modular approach makes code easier to read, test, and maintain.

This diagram illustrates a hierarchical program structure where a main paragraph controls the flow and calls subordinate task paragraphs for input, processing, output, and cleanup.
This diagram illustrates a hierarchical program structure where a main paragraph controls the flow and calls subordinate task paragraphs for input, processing, output, and cleanup.

To end the execution of a program, the STOP RUN statement is used, which signals to the operating system that the program has finished its work.

File Handling: Opening, Reading, and Writing

File handling is one of the most critical aspects of COBOL, especially in business environments where processing large amounts of data is standard. Before any data can be accessed, files must be explicitly opened using the OPEN statement.

Opening and Closing Files

Sequential files can be opened for input (OPEN INPUT filename) or for output (OPEN OUTPUT filename), but generally not both simultaneously. Once you are finished processing, you must use the CLOSE statement to release the file.

Keep reading for free.

Create an account to finish this reading and make it part of your study routine.

Continue reading free

Already have an account? Log in

Updated

Study it your way.

Import this reading into your study set to get started with another study mode.

Make it your own.

Keep this reading in a new study set, or add it to one you already use.