The Data Monster Under my bed : Migrating Cobol to the cloud – Part 3: Program Structure

As in any language, a COBOL program contains hierarchically ordered syntactically correct set of statements.
The difference from many languages from second generation (as COBOL is third generation programming language) is that the hierarchy consists of Divisions, Sections, Paragraphs, Sentences and Statements as follows (many Business Analysts, writers and content creators will recognise the structure I think 🙂)

Where:

Division

Division is a modal block of code, defined in Area A beginning with its name and ending with the next division declaration or at the end of the program itself, and can contain:

  • Block of Statements
  • Set of Sentences
  • Set of Sections
  • One/Multiple section (s)

As language definition COBOL consists of 4 divisions:

  • IDENTIFICATION DIVISION – providing identifiers for the program itself
  • ENVIRONMENT DIVISION – optional division that can describe the the data files used in the program as well as all devices used to compile and execute the program program.
  • DATA DIVISION – description (s) and definition (s) of data items referenced by the program (names, lengths, decimal point location, formats, and other)
  • PROCEDURE DIVISION – holding the actual program logic

Example Syntax:

IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.

Section (s)

Section (s) is/are block (s) of code that contain

  • one/more Paragraph (s)
  • set of Sentence (s)
  • block of Statements

Section begins with name, followed by the keyword Section, coded in Area A.

Section is valid until next section is defined or until the end of the program.

Example Syntax:

{SECTION_NAME} SECTION.

Paragraph (s)

Paragraph is a modal code block that begins with paragraph name and ends with next paragraph definition, section definition or program end, and might contain:

  • One/more sentence (s)
  • Set of Statements

Example Syntax defining paragraph start:

{PARAGRAPH_NAME}.

Sentence (s)

Sentence is defined in Area B, ant contain one or more statements that are marked by a period at the last line in order to define the end of it.


If marked with period in the middle it will be treated as Statement and not sentence.

Example Syntax:

DISPLAY "VAR1-NAME:"VAR1-NAME
DISPLAY "VAR2-NAME:"VAR2-NAME
DISPLAY "VAR3-NAME:"VAR3-NAME.

Statement (s)

Statement (conditional and/or unconditional) is grouped in four categories in COBOL and defined in Area B and consists os a verb and an operand (s), defined with/without a period at the end.
The categories are as follows.

  • Delimited scope
  • Compiler directing
  • Conditional
  • Imperative

Example Syntax:

DISPLAY "VAR1-NAME:"VAR1-NAME.
MOVE A TO B.
INSPECT A REPLACING ALL 'X' BY 'Y'.

TO BE CONTINUED …