COBOL Tutorial

Progress0 of 0 lessons

COBOL program design

Program design is how you organize a COBOL program so it is easy to understand, change, and test. Key ideas are top-down design (main steps first, then break each into smaller steps), modular structure (each paragraph or subprogram does one job), and clear flow (sequence, selection, iteration). This page introduces these ideas and how they look in COBOL. For the actual flow of control see Program flow and Program logic.

Design principles

Program design principles
PrincipleMeaning
Top-downStart with main steps; break each into smaller steps
ModularOne paragraph or program = one clear task
Single entry/exitParagraphs and subprograms have one way in and one way out
Readable namesParagraph and data names describe what they do or hold

Top-down design

Start with the big picture: what are the main steps? For example: open files, process records until end-of-file, then close and finish. Write a main paragraph that PERFORMs those steps. Then implement each step as its own paragraph; each of those can PERFORM lower-level paragraphs. You get a hierarchy: the main paragraph is the “boss”; the steps it PERFORMs are the next level; and so on.

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
PROCEDURE DIVISION. MAIN. PERFORM INIT-PROGRAM PERFORM PROCESS-ALL-RECORDS PERFORM TERMINATE-PROGRAM GOBACK. *> Top level: three main steps PROCESS-ALL-RECORDS. PERFORM READ-RECORD PERFORM PROCESS-LOOP UNTIL WS-EOF . *> Next level: read once, then loop until done PROCESS-LOOP. PERFORM VALIDATE-RECORD PERFORM UPDATE-AND-WRITE PERFORM READ-RECORD .

Modular paragraphs

Each paragraph should have a single responsibility: one clear task (e.g. validate input, compute total, write a line). Keep paragraphs short; if one grows too long, split it into smaller PERFORMed paragraphs. Use names that describe the task (VALIDATE-RECORD, CALCULATE-TOTAL, WRITE-OUTPUT-LINE). That way the PROCEDURE DIVISION reads like a table of contents and new developers can find where to change logic.

PERFORM vs CALL

PERFORM is for calling paragraphs or sections inside the same program. Use it for your main structure: init, process, terminate, and all the small steps in between. CALL is for a separately compiled subprogram. Use CALL when you need a reusable program (shared by many callers), need to link with another language, or want a clear program boundary. For most internal structure, PERFORM is the right choice; see Subprograms for CALL and parameter passing.

Step-by-step: design before coding

  • List the main steps the program must do (open, process, close, etc.).
  • Write the main paragraph as a sequence of PERFORM for those steps.
  • For each step, decide if it needs sub-steps; if so, create a paragraph that PERFORMs them.
  • Name paragraphs by task; keep each to one clear job.
  • Implement each paragraph with the right mix of logic (IF, EVALUATE, PERFORM UNTIL) and calls to lower-level paragraphs.

Test Your Knowledge

1. What does top-down design mean?

  • Writing the DATA DIVISION first
  • Defining high-level steps first, then breaking each into smaller steps
  • Writing the last paragraph first
  • Using only one paragraph

2. What is a good guideline for a paragraph or module?

  • Do as much as possible in one paragraph
  • Have a single, clear responsibility
  • Never use PERFORM
  • Avoid WORKING-STORAGE

Related concepts

Related Pages