If you think of COBOL as a script language rather than a real one its inadequacy is less painful. (My first node and I'm lying like Satan already.) It actually serves okay for its main purpose, mass processing of input and output files where the data is in fixed columns. Admittedly, it helps to see it this way if you've never used any other language.

The part I find most painful is that there are no local variables and no parameters to routines. Everything is global, and spaghetti code abounds.

That and the fact that most Cobol systems are legacy systems that began long before Edsger Dijkstra descended from Mt Sinai (sorry for all the religious imagery, by the way) and proclaimed GO TO an abomination. So Cobol programs use GO TO and when you start working on them they're so complicated by generations of fiddling and accretion that you couldn't take the GO TOs out even if you wanted to and were brave enough to try.

The text of a Cobol program is structured in columns, to some extent:

  • columns 1-6 is the line number (your choice of numbers, but conventionally in increments of 100 for ease of later insertion)
  • column 7 is a special marker:
  • columns 8-12 (Area A) are where major divisions of the code start, and ordinary program text isn't allowed here
  • columns 13-72 (Area B) is the main text area
  • columns 73-80 are ignored by the compiler, so you typically use them for version information.
A program consists of four divisions. All four of these must be in every program, in this order:
IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
The Identification Division contains the name and things that are effectively comments.

The Environment Division contains file declarations and a ragbag of minor stuff.

The Data Division contains all file formats and all variables. Internal variables, i.e. those not describing positions in a file, are called working storage and live in the subdivision called the Working-Storage Section.

The Procedure Division contains the procedures. It is divided into paragraphs. All statements must be in a paragraph. You can either GO TO or PERFORM (= call) a paragraph. Most programs do both freely, with the attendant hilarity of the next person who tries to work on it. Optionally a program can have its paragraphs grouped into sections: you can also GO TO and/or PERFORM sections, at the same time as weaving in and out of their component paragraphs. 90% of Cobol-related murders are of people who did all of these at the same time.

I intend to node this wonderful language in detail, but might be returning to expand this main node in future.