Day 12: Understanding COBOL Conditional Statements for Logical Decision-Making Using IF and EVALUATE Clauses

 

1. Introduction: The Role of Decision-Making in COBOL Programs

Every real-world business process involves decision-making — from approving a loan based on income to checking a student’s grade or validating a transaction. In COBOL, such decisions are implemented using conditional statements, which help control the flow of a program based on certain conditions.

COBOL provides two primary mechanisms for conditional processing:

  • IF Statements — for simple, direct comparisons.

  • EVALUATE Statements — for handling multiple conditions or cases, similar to “switch-case” logic in other languages.

By using these constructs, COBOL allows your program to take actions based on data values dynamically — a crucial skill for any COBOL developer working in enterprise systems like payroll, inventory, and banking.


2. Using the IF Statement for Simple and Nested Conditions

The IF statement is the most common conditional structure in COBOL. It checks whether a condition is true or false and executes code accordingly.

Example of a simple IF:

IF EMP-SALARY > 50000 DISPLAY "HIGH SALARY EMPLOYEE" ELSE DISPLAY "NORMAL SALARY EMPLOYEE" END-IF.

You can also nest IF statements for complex logic:

IF EMP-SALARY > 50000 IF EMP-DEPT = "IT" DISPLAY "SENIOR IT EMPLOYEE" ELSE DISPLAY "SENIOR NON-IT EMPLOYEE" END-IF ELSE DISPLAY "JUNIOR EMPLOYEE" END-IF.

You can use relational operators like =, >, <, NOT, AND, and OR for multiple conditions.
The IF structure is perfect for small, clear logic blocks, but for broader multi-condition checks, COBOL offers a cleaner alternative — EVALUATE.


3. The EVALUATE Statement: COBOL’s Version of Switch-Case

The EVALUATE statement in COBOL is used when you need to test multiple values or conditions in a clean, readable format.

Example:

EVALUATE TRUE WHEN EMP-DEPT = "HR" DISPLAY "HUMAN RESOURCES DEPARTMENT" WHEN EMP-DEPT = "IT" DISPLAY "INFORMATION TECHNOLOGY DEPARTMENT" WHEN EMP-DEPT = "FINANCE" DISPLAY "FINANCE DEPARTMENT" WHEN OTHER DISPLAY "UNKNOWN DEPARTMENT" END-EVALUATE.

You can even evaluate multiple expressions:

EVALUATE EMP-DEPT ALSO EMP-SALARY WHEN "IT" ALSO > 60000 DISPLAY "SENIOR IT EMPLOYEE" WHEN "IT" ALSO <= 60000 DISPLAY "JUNIOR IT EMPLOYEE" WHEN OTHER DISPLAY "OTHER EMPLOYEE" END-EVALUATE.

The EVALUATE statement improves readability and structure, especially when you have to handle many business rules.


🧠 Key Takeaways

  • IF statements handle simple or nested conditional checks.

  • EVALUATE statements simplify multi-condition decision-making.

  • Use logical operators (AND, OR, NOT) for compound conditions.

  • Clear decision-making logic helps structure COBOL programs efficiently.

  • Conditional statements are the backbone of business rules and validations in COBOL systems.


💻 Practice Task

  1. Write a COBOL program named SalaryDecision.cbl.

  2. Accept Employee Department and Salary from the user.

  3. Use IF statements to:

    • Display “High Salary” if above ₹60,000.

    • Display “Medium Salary” if between ₹40,000–₹60,000.

    • Display “Low Salary” otherwise.

  4. Use EVALUATE to:

    • Display department-based messages (e.g., HR, IT, FINANCE).

  5. Combine both to create a decision-based message like:
    👉 “High Salary Employee from IT Department”.



  6. "This Content Sponsored by SBO Digital Marketing.

    Mobile-Based Part-Time Job Opportunity by SBO!

    Earn money online by doing simple content publishing and sharing tasks. Here's how:

    • Job Type: Mobile-based part-time work
    • Work Involves:
      • Content publishing
      • Content sharing on social media
    • Time Required: As little as 1 hour a day
    • Earnings: ₹300 or more daily
    • Requirements:
      • Active Facebook and Instagram account
      • Basic knowledge of using mobile and social media

    For more details:

    WhatsApp your Name and Qualification to 9994104160

    a.Online Part Time Jobs from Home

    b.Work from Home Jobs Without Investment

    c.Freelance Jobs Online for Students

    d.Mobile Based Online Jobs

    e.Daily Payment Online Jobs

    Keyword & Tag: #OnlinePartTimeJob #WorkFromHome #EarnMoneyOnline #PartTimeJob #jobs #jobalerts #withoutinvestmentjob"

Comments