Decision tables in COBOL are structured approaches to handling complex decision logic involving multiple conditions and multiple actions. While COBOL doesn't have built-in decision table syntax, decision tables are implemented using EVALUATE statements, nested IF structures, or table-driven logic. Decision tables organize complex business rules into a clear, tabular format that maps conditions to actions, making complex logic more maintainable, testable, and understandable.
This comprehensive guide will teach you how to implement decision tables using EVALUATE with multiple conditions, create table-driven decision logic, organize complex business rules, handle all condition combinations, and follow best practices for maintainable decision table implementations. Whether you're implementing pricing rules, approval workflows, or complex business logic, mastering decision tables is essential for managing complex conditional logic in COBOL programs.
Decision tables organize complex decision logic into a structured format:
Decision tables make complex logic:
EVALUATE with ALSO is ideal for implementing decision tables as it can evaluate multiple conditions simultaneously.
1234567891011121314151617181920212223242526272829WORKING-STORAGE SECTION. 01 CUSTOMER-TYPE PIC X(1). 88 REGULAR-CUSTOMER VALUE 'R'. 88 PREMIUM-CUSTOMER VALUE 'P'. 01 ORDER-AMOUNT PIC 9(6)V99. 01 DISCOUNT-RATE PIC 9(2)V99. PROCEDURE DIVISION. MAIN-LOGIC. *> Decision table: Customer type + Order amount -> Discount rate EVALUATE TRUE ALSO ORDER-AMOUNT WHEN REGULAR-CUSTOMER ALSO LESS THAN 100.00 MOVE 0.00 TO DISCOUNT-RATE DISPLAY "No discount for regular customer, small order" WHEN REGULAR-CUSTOMER ALSO GREATER THAN 1000.00 MOVE 5.00 TO DISCOUNT-RATE DISPLAY "5% discount for regular customer, large order" WHEN PREMIUM-CUSTOMER ALSO LESS THAN 100.00 MOVE 2.00 TO DISCOUNT-RATE DISPLAY "2% discount for premium customer, small order" WHEN PREMIUM-CUSTOMER ALSO GREATER THAN 1000.00 MOVE 10.00 TO DISCOUNT-RATE DISPLAY "10% discount for premium customer, large order" WHEN OTHER MOVE 0.00 TO DISCOUNT-RATE DISPLAY "Default: No discount" END-EVALUATE STOP RUN.
This example demonstrates a decision table mapping customer type and order amount combinations to discount rates.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657IDENTIFICATION DIVISION. PROGRAM-ID. DECISION-TABLE-EXAMPLE. AUTHOR. MainframeMaster Tutorial. DATA DIVISION. WORKING-STORAGE SECTION. 01 LOAN-APPLICATION. 05 CREDIT-SCORE PIC 9(3). 05 INCOME-LEVEL PIC X(1). 88 LOW-INCOME VALUE 'L'. 88 MEDIUM-INCOME VALUE 'M'. 88 HIGH-INCOME VALUE 'H'. 05 EMPLOYMENT-STATUS PIC X(1). 88 EMPLOYED VALUE 'E'. 88 SELF-EMPLOYED VALUE 'S'. 88 UNEMPLOYED VALUE 'U'. 05 LOAN-DECISION PIC X(10). 05 INTEREST-RATE PIC 9(2)V99. PROCEDURE DIVISION. MAIN-LOGIC. DISPLAY "=== Loan Approval Decision Table ===" *> Initialize test data MOVE 750 TO CREDIT-SCORE SET HIGH-INCOME TO TRUE SET EMPLOYED TO TRUE *> Decision table: Credit score + Income + Employment -> Decision + Rate EVALUATE CREDIT-SCORE ALSO TRUE ALSO TRUE WHEN GREATER THAN 700 ALSO HIGH-INCOME ALSO EMPLOYED MOVE "APPROVED" TO LOAN-DECISION MOVE 3.50 TO INTEREST-RATE DISPLAY "Decision: " LOAN-DECISION " Rate: " INTEREST-RATE "%" WHEN GREATER THAN 700 ALSO HIGH-INCOME ALSO SELF-EMPLOYED MOVE "APPROVED" TO LOAN-DECISION MOVE 4.00 TO INTEREST-RATE DISPLAY "Decision: " LOAN-DECISION " Rate: " INTEREST-RATE "%" WHEN GREATER THAN 700 ALSO MEDIUM-INCOME ALSO EMPLOYED MOVE "APPROVED" TO LOAN-DECISION MOVE 4.50 TO INTEREST-RATE DISPLAY "Decision: " LOAN-DECISION " Rate: " INTEREST-RATE "%" WHEN GREATER THAN 650 ALSO HIGH-INCOME ALSO EMPLOYED MOVE "APPROVED" TO LOAN-DECISION MOVE 5.00 TO INTEREST-RATE DISPLAY "Decision: " LOAN-DECISION " Rate: " INTEREST-RATE "%" WHEN GREATER THAN 600 ALSO MEDIUM-INCOME ALSO EMPLOYED MOVE "CONDITIONAL" TO LOAN-DECISION MOVE 6.00 TO INTEREST-RATE DISPLAY "Decision: " LOAN-DECISION " Rate: " INTEREST-RATE "%" WHEN OTHER MOVE "DENIED" TO LOAN-DECISION MOVE 0.00 TO INTEREST-RATE DISPLAY "Decision: " LOAN-DECISION END-EVALUATE STOP RUN.
This complex example demonstrates a decision table for loan approval with multiple conditions (credit score, income, employment) mapping to decisions and interest rates.
Table-driven approaches store decision rules in data structures, allowing rules to be modified without code changes.
123456789101112131415161718192021222324252627282930313233343536373839404142434445WORKING-STORAGE SECTION. 01 DECISION-RULES. 05 RULE-TABLE OCCURS 10 TIMES INDEXED BY RULE-INDEX. 10 RULE-CONDITION-1 PIC X(1). 10 RULE-CONDITION-2 PIC X(1). 10 RULE-ACTION PIC X(20). 01 CURRENT-CONDITION-1 PIC X(1). 01 CURRENT-CONDITION-2 PIC X(1). 01 SELECTED-ACTION PIC X(20). 01 RULE-FOUND-FLAG PIC X(1) VALUE 'N'. 88 RULE-FOUND VALUE 'Y'. PROCEDURE DIVISION. MAIN-LOGIC. *> Initialize decision rules table MOVE 'A' TO RULE-CONDITION-1(1) MOVE 'X' TO RULE-CONDITION-2(1) MOVE "Action for A+X" TO RULE-ACTION(1) MOVE 'B' TO RULE-CONDITION-1(2) MOVE 'Y' TO RULE-CONDITION-2(2) MOVE "Action for B+Y" TO RULE-ACTION(2) *> Look up rule MOVE 'A' TO CURRENT-CONDITION-1 MOVE 'X' TO CURRENT-CONDITION-2 PERFORM VARYING RULE-INDEX FROM 1 BY 1 UNTIL RULE-INDEX > 10 OR RULE-FOUND IF RULE-CONDITION-1(RULE-INDEX) = CURRENT-CONDITION-1 AND RULE-CONDITION-2(RULE-INDEX) = CURRENT-CONDITION-2 MOVE RULE-ACTION(RULE-INDEX) TO SELECTED-ACTION SET RULE-FOUND TO TRUE END-IF END-PERFORM IF RULE-FOUND DISPLAY "Selected action: " SELECTED-ACTION ELSE DISPLAY "No matching rule found" END-IF STOP RUN.
Table-driven approaches allow rules to be loaded from external sources or modified without recompiling code.
Think of decision tables like a menu at a restaurant:
So decision tables are like a smart menu that helps you decide what to order based on your preferences!
1. What are decision tables used for in COBOL?
2. What COBOL statement is best for implementing decision tables?
3. What should you always include in a decision table implementation?
4. What are the main components of a decision table?
5. What is a table-driven decision table approach?