Paragraphs and sections

Paragraphs

A paragraph is a named block of sentences ending with a period. PERFORM runs it like a function call, and it can take parameters through LINKAGE in called programs:

MAIN-PARA. PERFORM COMPUTE-TOTALS. STOP RUN. COMPUTE-TOTALS. ADD WS-HOURS TO WS-TOTAL-HOURS. ADD WS-PAY TO WS-TOTAL-PAY.

Sections

A section groups paragraphs. PERFORM INIT-SECTION runs every paragraph in it in order, which is handy for one-time initialization sequences:

INIT-SECTION SECTION. OPEN-INPUT. OPEN INPUT EMPLOYEE-FILE. READ-FIRST. READ EMPLOYEE-FILE AT END MOVE "Y" TO WS-EOF END-READ.

GO TO: use sparingly

GO TO jumps to a paragraph unconditionally. Modern COBOL code prefers PERFORM, EVALUATE, and inline scope terminators, keeping GO TO for error exits and legacy maintenance.

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev