§ — — Structured Programming (COBOL)
After studying this lesson, learners should be able to:
FILE-CONTROL and SELECT ... ASSIGN TO for file assignments.COBOL references often use special formatting conventions:
| Convention | Meaning |
|---|---|
| Uppercase words | COBOL reserved words. |
| Lowercase or placeholder words | Programmer-supplied values. |
Brackets [ ] | Optional part. |
Braces { } | Placeholder or required choice, depending on reference style. |
Ellipsis ... | More entries of the same kind may follow. |
| Punctuation | If shown in the syntax, it must be typed. |
Example:
PROGRAM-ID. program-name.
This means PROGRAM-ID. is typed as shown, while program-name is replaced by the chosen program name.
The Identification Division names and identifies the program. In many beginner programs, the only required paragraph is PROGRAM-ID.
Basic form:
IDENTIFICATION DIVISION.
PROGRAM-ID. program-name.
Older examples may include documentation paragraphs such as AUTHOR, DATE-WRITTEN, or SECURITY, but student-facing study material should avoid personal or institutional identifiers.
Generic example:
IDENTIFICATION DIVISION.
PROGRAM-ID. SALES-REPORT.
The Environment Division describes external resources used by the program, especially files and machine-related details.
Common parts:
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. computer-name.
OBJECT-COMPUTER. computer-name.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT file-name ASSIGN TO "external-file-name".
In many simple modern learning examples, the CONFIGURATION SECTION may be omitted unless the compiler requires it. The INPUT-OUTPUT SECTION is important when the program reads or writes files.
The Configuration Section may document the source and object computers:
SOURCE-COMPUTER - the machine used to compile the program.OBJECT-COMPUTER - the machine used to run the program.SPECIAL-NAMES - optional special device or symbolic-name definitions.Generic example:
CONFIGURATION SECTION.
SOURCE-COMPUTER. GENERIC-PC.
OBJECT-COMPUTER. GENERIC-PC.
The Input-Output Section connects COBOL file names to external files or devices.
The most common paragraph is FILE-CONTROL.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT STUDENT-FILE
ASSIGN TO "STUDENT.DAT".
SELECT REPORT-FILE
ASSIGN TO "REPORT.TXT".
A COBOL program often uses two names for a file:
| Name type | Example | Purpose |
|---|---|---|
| Internal file name | STUDENT-FILE | Name used inside the COBOL program. |
| External file name | "STUDENT.DAT" | Actual file or device known to the operating system. |
Use meaningful names that describe the file's role:
SALES-INPUTSALES-REPORTSTUDENT-FILEPAYROLL-OUTPUTAvoid names that are too vague, personal, or unrelated to the program.
ProReviewer — locked
Drills, code labs, and full solutions.
Done with this module? Track it — your progress shows on the subject list.
Up next
Data Division, Data Fields, and PICTURE Clauses→←Previous: COBOL Character Set and COBOL Words