Menu
CoddyTech

Paragraphs and PERFORM

Part of the Decisions and Loops section of Coddy's COBOL Programming journey. Lesson 11 of 20.

A paragraph is a named block of statements in the PROCEDURE DIVISION. Its name starts in Area A and ends with a period:

PRINT-LINE.
    DISPLAY "----------".

PERFORM runs a paragraph, then comes back to the statement after the PERFORM:

MAIN-PARA.
    DISPLAY "Order 42".
    PERFORM PRINT-LINE.
    STOP RUN.

Statements run from top to bottom and flow from one paragraph into the next. That is why the main paragraph ends with STOP RUN: without it, the program would run into PRINT-LINE and print the dashes a second time.

Name a paragraph for what it does, like CHECK-LIMIT or PRINT-TOTALS. A main paragraph made of PERFORMs reads as the outline of the program.

challenge icon

Challenge

Easy

PRINT-LINE prints a line of dashes. Write MAIN-PARA so the program prints a three-line report: Monthly Report between two lines of dashes.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. REPORTS.
       PROCEDURE DIVISION.
       MAIN-PARA.
           *> Perform PRINT-LINE around the title
       PRINT-LINE.
           DISPLAY "----------".

All lessons in Decisions and Loops

Practice on your own: Online COBOL compiler