§ — — Structured Programming (COBOL)
After studying this lesson, learners should be able to:
Traditional COBOL uses letters, digits, spaces, and selected special symbols.
| Character type | Examples |
|---|---|
| Digits | 0 1 2 3 4 5 6 7 8 9 |
| Letters | A B C ... Z |
| Space | blank space |
| Special symbols | ( ) " = $ , ; + - * / > < |
COBOL words can be grouped into two major categories:
A user-defined word is a name chosen by the programmer. It may name a file, record, field, paragraph, section, or program.
Rules for user-defined words:
Examples:
| Name | Valid? | Reason |
|---|---|---|
SALES-AMT | Yes | Uses letters and hyphen correctly. |
3STUD-NAME | Yes in many COBOL systems | Begins with a digit but includes letters; check compiler rules. |
143 | No | Contains no alphabetic character. |
STUDENT ID | No | Contains a space. |
SALES*REP | No | Contains *, which is not allowed in user-defined names. |
AMOUNT-DUE- | No | Ends with a hyphen. |
A reserved word has a built-in COBOL meaning. Programmers cannot freely reuse it as a data name or file name.
Reserved words include:
READ, AT END, STOP RUN, MOVE, and DISPLAY.ZERO, ZEROS, ZEROES, SPACE, SPACES, QUOTE, and QUOTES.Example:
READ MASTER-FILE AT END
MOVE 1 TO EOF-SW.
In this example, READ, AT END, and MOVE are COBOL words. MASTER-FILE and EOF-SW are user-defined names.
Figurative constants are readable substitutes for common values.
| Constant | Meaning |
|---|---|
ZERO, ZEROS, ZEROES | Numeric zero or repeated zeroes. |
SPACE, SPACES | One or more blank spaces. |
QUOTE, QUOTES | Quotation mark character. |
HIGH-VALUE, HIGH-VALUES | Highest value in the system's collating sequence. |
LOW-VALUE, LOW-VALUES | Lowest value in the system's collating sequence. |
Example:
MOVE ZEROS TO TOTAL-SALES.
MOVE SPACES TO CUSTOMER-NAME.
A simple COBOL exercise can ask the program to:
A generic screen layout might be:
ENTER NAME: __________
ENTER MIDTERM GRADE: __________
ENTER FINAL GRADE: __________
AVERAGE: __________
INPUT MORE? (Y/N): __________
ProReviewer — locked
Drills, code labs, and full solutions.
ProReviewer — locked
Drills, code labs, and full solutions.
Done with this module? Track it — your progress shows on the subject list.
Up next
Identification Division and Environment Division→←Previous: COBOL Overview, Program Structure, and Coding Form