../courses.php
COBOL
COBOL107
3
Performing Repeated Work
COBOL uses PERFORM whenever the same work must happen more than once.
Why does COBOL use PERFORM?
PERFORM executes a paragraph or block of code so the same instructions can be reused instead of copied many times.
Business programs repeat many tasks.
Every customer record may need the same calculations.
Every invoice may need the same printing routine.
Rather than copying code, COBOL performs it.
This makes maintenance easier.
Using PERFORM
PROCEDURE DIVISION.
PERFORM SHOW-MESSAGE.
STOP RUN.
SHOW-MESSAGE.
DISPLAY "HELLO".
PERFORM calls another section of the program.
Execution jumps to SHOW-MESSAGE.
DISPLAY executes.
Control returns after the paragraph finishes.
The same paragraph can be performed many times.
Reuse
One routine can serve many parts of the program.
Maintenance
Fix the code once instead of many times.
Readability
Programs become easier to follow.
Business processing
Repeated record handling becomes simpler.
Copying the same code everywhere
DISPLAY "HELLO".
DISPLAY "HELLO".
DISPLAY "HELLO".
Reuse with PERFORM
Ask ChatGPT: "Trace this COBOL PERFORM statement and explain the execution flow."
Create one paragraph.
Display a message.
PERFORM the paragraph.
PERFORM it twice.
Explain why PERFORM is better than duplicated code.
Copying identical code repeatedly.
Jumping to the wrong paragraph.
Giving paragraphs poor names.
Making paragraphs too large.
Ignoring reusable code.
Use PERFORM to reuse COBOL code safely.
Login - Jit4All
Login
Welcome back to Jit4All