../courses.php
COBOL
COBOL106
3
Decisions In COBOL
COBOL uses IF, ELSE, and END-IF to choose between business rules.
How does COBOL make decisions?
COBOL makes decisions by testing conditions with IF statements and running different instructions depending on whether the condition is true or false.
Business programs are full of decisions.
If a balance is positive, an account may be active.
If a payment is late, a notice may be printed.
If a record is invalid, a batch job may skip it.
COBOL decisions are meant to make business rules readable.
Using IF and ELSE
DATA DIVISION.
WORKING-STORAGE SECTION.
01 BALANCE PIC 9999 VALUE 1000.
PROCEDURE DIVISION.
IF BALANCE IS GREATER THAN 0
DISPLAY "ACCOUNT ACTIVE"
ELSE
DISPLAY "ACCOUNT CLOSED"
END-IF.
STOP RUN.
IF starts the decision.
BALANCE IS GREATER THAN 0 is the condition.
The first DISPLAY runs when the condition is true.
The ELSE path runs when the condition is false.
END-IF closes the decision.
Business rules
IF statements express business decisions.
Safety
Bad records can be handled separately.
Reports
Different output can be produced for different cases.
Maintenance
Clear decisions help future programmers protect the rule.
No clear end to the decision
IF BALANCE IS GREATER THAN 0
DISPLAY "ACCOUNT ACTIVE"
Closed decision
IF BALANCE IS GREATER THAN 0
DISPLAY "ACCOUNT ACTIVE"
ELSE
DISPLAY "ACCOUNT CLOSED"
END-IF.
Ask ChatGPT: "Trace this COBOL IF statement and explain which business rule runs."
Create a numeric balance field.
Write an IF condition.
Add an ELSE path.
Close it with END-IF.
Explain how this represents a business rule.
Forgetting END-IF.
Writing unclear conditions.
Ignoring the ELSE case.
Changing a business rule without understanding it.
Testing only the true branch.
Use IF, ELSE, and END-IF to express simple COBOL business decisions.
Login - Jit4All
Login
Welcome back to Jit4All