Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Procedure Division

created by OldCobbler

(place) by OldCobbler (3.6 y) (print)   ?   (I like it!) 1 C! Thu May 31 2001 at 17:20:35

The part of a Cobol program that actually does the things that go wrong. It is the fourth of the four divisions that, and contains all the procedures or statements; as opposed to the previous three divisions, which define files and variables.

The procedure division is divided into paragraphs, each with an alphanumeric name. Division, paragraph, and (see below) section names begin in Area A (columns 8-11) and end in a full stop. Here is the simplest possible correct Cobol program:

000100  IDENTIFICATION DIVISION.
000200  ENVIRONMENT DIVISION.
000300  DATA DIVISION.
000400  PROCEDURE DIVISION.
000500  A.
000600      STOP RUN.
It has only one paragraph (A) and only one command in it, the one that ends the program. (Falling off the edge of the program without hitting a STOP RUN crashes it, at least with the compiler I use.)

A more realistic example is this. I'll give it a name MYPROG, assign a file, and create two variables, a counter and an EOF flag. Cobol keywords are hardlinked.

000100  IDENTIFICATION DIVISION.
000110  PROGRAM-ID.  MYPROG.
000120
000200  ENVIRONMENT DIVISION.
000210  INPUT-OUTPUT SECTION.
000220  FILE-CONTROL.
000230      SELECT F   ASSIGN DISK.
000240
000300  DATA DIVISION.
000310  FILE SECTION.
000320  FD  F.
000330  01  F-RECORD  PIC X(80).
000340
000350  WORKING-STORAGE SECTION.
000360  01  REC-CT    PIC 9(6).
000370  01  AT-EOF    PIC 9.
000380
000400  PROCEDURE DIVISION.
000500  A.
000510      PERFORM INITIALIZE-IT.
000520      PERFORM MAIN-LOOP UNTIL AT-EOF = 1.
000530      PERFORM TERMINATE-IT.
000600      STOP RUN.
000610  INITIALIZE-IT.
000620      MOVE 0 TO AT-EOF.
000630      MOVE 0 TO REC-CT.
000640      OPEN INPUT F.
000650  MAIN-LOOP.
000660      READ F
000670          END MOVE 1 TO AT-EOF
000680          EXIT PERFORM.
000690      ADD 1 TO REC-CT.
000700  TERMINATE-IT.
000710      CLOSE F.
000720      DISPLAY "TOTAL RECORDS = " REC-CT.
Once you're inside the Procedure Division it's not really that different from a lot of other languages.

Paragraphs can be grouped into sections. If sections are used at all, they must be used throughout. You give them alphanumeric names just like paragraphs. A fragment of the above with sections is this:

000400  PROCEDURE DIVISION.
000500  CTRL SECTION.
000505  PARA-1.
000510      PERFORM INITIALIZE-IT.
000520      PERFORM MAIN-LOOP UNTIL AT-EOF = 1.
000530      PERFORM TERMINATE-IT.
000540  PARA-99.
000600      STOP RUN.
000605.
000610  INITIALIZE-IT SECTION.
000615  PARA-1.
000620      MOVE 0 TO AT-EOF.

printable version
chaos

perform stop run COBOL Procedure
section command Paragraph statement
division Do not write, stamp, or sign below this line
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Just another sprinkling of indeterminacy
King Arthur
Canal Street
chemotherapy
Ian Hunter
Nimrod
Septuagint
mere words
Soup first, or noodles first?
summer solstice
How I made the Year Nodes
Christmas card
Playing rough on the bed
Ruben Salazar
New Writeups
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
stainedglass
1(fiction)
kalen
Three "T"s(idea)
octillion369
Undead(idea)
archiewood
Ico(fiction)
Heisenberg
Why I love Everything2(log)
octillion369
Death Knight(person)
XWiz
Are you hoping for a miracle?(review)
santo
The Host(review)
This affordable entertainment brought to you by The Everything Development Company