CONDITION in COBOL refers to logical conditions or condition names that are used to make code more readable and meaningful. Condition names are defined using 88-level entries and provide descriptive names for specific values or ranges of values, improving code readability and maintainability.
CONDITION names follow specific syntax patterns in COBOL:
123456789101112131415161718192021222324252627* Basic condition name syntax 01 status-code PIC X. 88 active-status VALUE "A". 88 inactive-status VALUE "I". 88 terminated-status VALUE "T". 01 customer-type PIC X. 88 individual-customer VALUE "I". 88 corporate-customer VALUE "C". 88 government-customer VALUE "G". 01 account-status PIC X. 88 open-account VALUE "O". 88 closed-account VALUE "C". 88 suspended-account VALUE "S". * Multiple values for a condition 01 priority-level PIC 9. 88 high-priority VALUE 1, 2. 88 medium-priority VALUE 3, 4, 5. 88 low-priority VALUE 6, 7, 8, 9. * Range conditions 01 age PIC 9(3). 88 minor VALUE 0 THRU 17. 88 adult VALUE 18 THRU 64. 88 senior VALUE 65 THRU 999.
Condition names are defined using 88-level entries with VALUE clauses.
1234567891011121314151617181920212223242526272829303132333435363738* Using condition names in conditional statements PROCEDURE DIVISION. PROCESS-CUSTOMER. * Set status MOVE "A" TO status-code. * Use condition names in IF statements IF active-status DISPLAY "Customer is active" PERFORM process-active-customer ELSE IF inactive-status DISPLAY "Customer is inactive" PERFORM process-inactive-customer ELSE IF terminated-status DISPLAY "Customer is terminated" PERFORM process-terminated-customer END-IF. * Check customer type IF individual-customer DISPLAY "Processing individual customer" PERFORM process-individual ELSE IF corporate-customer DISPLAY "Processing corporate customer" PERFORM process-corporate END-IF. * Check priority level IF high-priority DISPLAY "High priority processing" PERFORM urgent-processing ELSE IF medium-priority DISPLAY "Medium priority processing" PERFORM normal-processing ELSE IF low-priority DISPLAY "Low priority processing" PERFORM background-processing END-IF.
Here are some practical uses of CONDITION names in COBOL:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081* Employee status processing with condition names DATA DIVISION. WORKING-STORAGE SECTION. 01 employee-record. 05 employee-id PIC X(10). 05 employee-name PIC X(50). 05 employee-status PIC X. 88 full-time VALUE "F". 88 part-time VALUE "P". 88 temporary VALUE "T". 88 contractor VALUE "C". 05 department-code PIC X(3). 88 it-department VALUE "IT". 88 hr-department VALUE "HR". 88 finance-department VALUE "FIN". 88 sales-department VALUE "SAL". 05 salary-grade PIC 9(2). 88 entry-level VALUE 01 THRU 05. 88 mid-level VALUE 06 THRU 10. 88 senior-level VALUE 11 THRU 15. 88 executive-level VALUE 16 THRU 20. PROCEDURE DIVISION. PROCESS-EMPLOYEE. * Read employee record READ employee-file AT END MOVE "Y" TO end-of-file-flag NOT AT END PERFORM analyze-employee END-READ. STOP RUN. ANALYZE-EMPLOYEE. * Process based on employment status IF full-time DISPLAY "Processing full-time employee: " employee-name PERFORM full-time-processing ELSE IF part-time DISPLAY "Processing part-time employee: " employee-name PERFORM part-time-processing ELSE IF temporary DISPLAY "Processing temporary employee: " employee-name PERFORM temporary-processing ELSE IF contractor DISPLAY "Processing contractor: " employee-name PERFORM contractor-processing END-IF. * Process based on department IF it-department PERFORM it-department-processing ELSE IF hr-department PERFORM hr-department-processing ELSE IF finance-department PERFORM finance-department-processing ELSE IF sales-department PERFORM sales-department-processing END-IF. * Process based on salary grade IF entry-level PERFORM entry-level-processing ELSE IF mid-level PERFORM mid-level-processing ELSE IF senior-level PERFORM senior-level-processing ELSE IF executive-level PERFORM executive-level-processing END-IF. FULL-TIME-PROCESSING. * Process full-time employee benefits DISPLAY "Full-time benefits processing". * Additional processing logic here. IT-DEPARTMENT-PROCESSING. * Process IT department specific logic DISPLAY "IT department processing". * Additional processing logic here.
Employee status processing using condition names for better readability.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081* Order processing with condition names DATA DIVISION. WORKING-STORAGE SECTION. 01 order-record. 05 order-id PIC X(10). 05 order-status PIC X. 88 pending-order VALUE "P". 88 confirmed-order VALUE "C". 88 shipped-order VALUE "S". 88 delivered-order VALUE "D". 88 cancelled-order VALUE "X". 05 payment-status PIC X. 88 payment-pending VALUE "P". 88 payment-received VALUE "R". 88 payment-failed VALUE "F". 05 order-amount PIC 9(8)V99. 88 small-order VALUE 0.01 THRU 99.99. 88 medium-order VALUE 100.00 THRU 999.99. 88 large-order VALUE 1000.00 THRU 9999.99. 88 premium-order VALUE 10000.00 THRU 999999.99. PROCEDURE DIVISION. PROCESS-ORDER. * Read order record READ order-file AT END MOVE "Y" TO end-of-file-flag NOT AT END PERFORM analyze-order END-READ. STOP RUN. ANALYZE-ORDER. * Process based on order status IF pending-order DISPLAY "Processing pending order: " order-id PERFORM pending-order-processing ELSE IF confirmed-order DISPLAY "Processing confirmed order: " order-id PERFORM confirmed-order-processing ELSE IF shipped-order DISPLAY "Processing shipped order: " order-id PERFORM shipped-order-processing ELSE IF delivered-order DISPLAY "Processing delivered order: " order-id PERFORM delivered-order-processing ELSE IF cancelled-order DISPLAY "Processing cancelled order: " order-id PERFORM cancelled-order-processing END-IF. * Process based on payment status IF payment-pending PERFORM payment-pending-processing ELSE IF payment-received PERFORM payment-received-processing ELSE IF payment-failed PERFORM payment-failed-processing END-IF. * Process based on order amount IF small-order PERFORM small-order-processing ELSE IF medium-order PERFORM medium-order-processing ELSE IF large-order PERFORM large-order-processing ELSE IF premium-order PERFORM premium-order-processing END-IF. PENDING-ORDER-PROCESSING. * Process pending order DISPLAY "Pending order processing". * Additional processing logic here. PAYMENT-RECEIVED-PROCESSING. * Process payment received DISPLAY "Payment received processing". * Additional processing logic here.
Order processing system using condition names for status and amount categories.
1. What is CONDITION in COBOL?
2. What are condition names used for?
3. Where are condition names typically defined?
4. What is the primary benefit of using condition names?
5. How are condition names used in conditional statements?