Program documentation is the practice of describing what a COBOL program does, how it is structured, and how to maintain it. It includes comments and REMARKS in the source code, naming and layout conventions, and often external documents such as program specifications. This page focuses on documentation standards, what to document, and how to write documentation that stays useful as the program changes.
Imagine a box of toys with no labels. You have to open every box to see what is inside. Program documentation is like putting labels on the boxes: "This program updates customer balances," "This section opens the files," "This paragraph runs when the input is invalid." When someone else (or you later) needs to change the program, the labels help them find the right place and understand what to change without guessing.
COBOL applications often run for years or decades. Many people will change the code over time. Without documentation, it is hard to know why a program exists, what files and other programs it uses, or why a particular condition or formula was chosen. Good documentation:
Documentation does not change how the program runs; the compiler ignores comments and REMARKS. It only helps humans work with the code.
Focus documentation on information that is not obvious from the code itself.
| What | Where / How |
|---|---|
| Program purpose and role in the system | REMARKS or top comment block |
| Files read or written (names, keys, record types) | REMARKS or FILE SECTION comments |
| Programs called (CALL, LINK) and what is passed | REMARKS or comment near CALL |
| Complex business rules or formulas | Comment above or beside the logic |
| Assumptions (e.g. input is sorted, type A only) | REMARKS or section comment |
| Important changes (dates, reason) | REMARKS change log or standard change block |
The IDENTIFICATION DIVISION holds the program name (PROGRAM-ID) and optional paragraphs such as AUTHOR, DATE-WRITTEN, and REMARKS. REMARKS is free-form: you can describe purpose, files, called programs, and a short change history. Use it for high-level description that applies to the whole program.
Comments are for section-level or line-level explanation. In fixed-format COBOL, put an asterisk (*) in column 7 to make the entire line a comment. Use these for section headers (e.g. *--- OPEN FILES ---) and blocks of explanation. In COBOL 2002 and later, >* starts an inline comment from that point to the end of the line, useful for short notes next to a statement.
12345678910111213141516171819IDENTIFICATION DIVISION. PROGRAM-ID. BALUPDT. REMARKS. Updates customer balance from transaction file. Input: TRANSFILE (key: CUST-ID), sequential Output: MASTFILE (key: CUST-ID), indexed Called by: BATCH-BAL (passes control) Change: 2024-01-15 - add support for type B transactions *============================================================== * OPEN FILES AND READ FIRST RECORD *============================================================== OPEN INPUT TRANSFILE I-O MASTFILE. READ TRANSFILE AT END SET WS-TRANS-EOF TO TRUE END-READ. *> Use prior-day balance when posting runs after midnight IF WS-POST-TIME < WS-MIDNIGHT MOVE WS-PRIOR-BAL TO WS-WORK-BAL END-IF.
Many shops define documentation standards so that every program is documented in a consistent way. Standards may require:
If your team has a standard, follow it. If not, adopting a simple set of rules (e.g. always REMARKS + section comments + meaningful names) still improves maintainability.
Consistent naming makes the code self-explanatory and reduces the need for extra comments. Common conventions include:
| Prefix / pattern | Example | Use |
|---|---|---|
| WS- | WS-COUNTER, WS-TOTAL | Working storage variables |
| -FLAG / -SW | WS-EOF-FLAG, WS-ERROR-SW | Flags and switches |
| -COUNT / -TOTAL | WS-REC-COUNT, WS-GRAND-TOTAL | Counters and totals |
| INIT- | INIT-FILES, INIT-COUNTERS | Initialization paragraphs |
| EXIT- | EXIT-PROGRAM, EXIT-PARAGRAPH | Exit or cleanup paragraphs |
| Verb-noun | PROCESS-RECORD, VALIDATE-INPUT | Processing paragraphs |
Paragraph names that describe the action (e.g. VALIDATE-INPUT, WRITE-OUTPUT-RECORD) act as a form of documentation. Avoid vague names like PARA-1 or PROCESS.
A program specification (or "program spec") is a description of the program, often written before or alongside coding. It usually includes:
The spec can be a separate document (Word, Wiki) or a long REMARKS/comment block. When the program changes, update the spec so it does not go stale.
Avoid cluttering the code with comments that restate the obvious. For example, "Move A to B" next to MOVE A TO B adds no value. Do not comment every line. Prefer clear names and a few well-placed comments that explain why something is done or what a non-obvious value means.
Take a small program (or write a minimal one) and add a REMARKS block that states purpose, input file, output file, and one called program (or "none").
Add comment blocks (lines with * in column 7) before each logical section of a program: file open, main loop, file close. Use a consistent style.
Find one non-obvious condition or calculation and add a >* comment on the same line or the line above explaining why it is there.
1. What is the main benefit of keeping documentation with the code?
2. Where should you document the purpose of a COBOL program?
3. What should comments explain?