Skip to content
PERFORM and Paragraphs
step 1/4

Reading — step 1 of 4

Learn

~1 min readProcedures and Logic

COBOL paragraphs are named blocks of code. PERFORM invokes them.

       PROCEDURE DIVISION.
           PERFORM SAY-HELLO.
           PERFORM SAY-HELLO 3 TIMES.
           STOP RUN.

       SAY-HELLO.
           DISPLAY "hello".

A paragraph runs until the next paragraph or section starts. No explicit return — control flows back to the PERFORM call site.

PERFORM forms:

           PERFORM PARAGRAPH-NAME.                     *> just call
           PERFORM PARA 5 TIMES.                        *> repeat
           PERFORM PARA UNTIL DONE = "Y".              *> while-not
           PERFORM PARA WITH TEST AFTER UNTIL ... .     *> do-while-not
           PERFORM PARA THRU OTHER-PARA.                *> call paragraph range

Inline PERFORM — anonymous body with END-PERFORM:

           PERFORM 5 TIMES
               DISPLAY "hi"
           END-PERFORM.

PERFORM VARYING — counted iteration (you've used this for arrays):

           PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
               DISPLAY I
           END-PERFORM.

Sections group paragraphs:

       INITIALIZATION SECTION.
       OPEN-FILES.
           OPEN INPUT INPUT-FILE.
       READ-CONFIG.
           READ CONFIG-FILE.

       PROCESSING SECTION.
       MAIN-LOOP.
           ...

PERFORM SECTION-NAME runs all paragraphs in that section.

COBOL has no real functions or arguments — paragraphs work on shared WORKING-STORAGE. This is why old COBOL code reads as one big procedural script.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…