MainframeMaster

COBOL Tutorial

COBOL CONDITION - Quick Reference

Progress0 of 0 lessons

Overview

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.

Purpose and Usage

  • Code readability improvement
  • Self-documenting code
  • Status and flag representation
  • Business logic clarity
  • Maintenance enhancement

Syntax

CONDITION names follow specific syntax patterns in COBOL:

Basic Condition Name Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
* 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.

Using Condition Names

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
* 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.

Practical Examples

Here are some practical uses of CONDITION names in COBOL:

Employee Status Processing

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
* 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.

Order Processing System

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
* 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.

Best Practices

  • Use descriptive condition names that clearly indicate their purpose.
  • Group related condition names together under the same data item.
  • Use condition names instead of hardcoded values in conditional statements.
  • Document the meaning and usage of condition names.
  • Use consistent naming conventions for condition names.
  • Consider using condition names for all status codes and flags.

Common Pitfalls

  • Using unclear or ambiguous condition names.
  • Not using condition names consistently throughout the program.
  • Creating too many condition names that are rarely used.
  • Not documenting the business meaning of condition names.
  • Using hardcoded values instead of condition names.

Test Your Knowledge

1. What is CONDITION in COBOL?

  • A data type
  • A logical condition or condition name
  • A file operation
  • A program structure

2. What are condition names used for?

  • Data storage
  • Making code more readable and meaningful
  • File operations
  • Arithmetic calculations

3. Where are condition names typically defined?

  • In the PROCEDURE DIVISION
  • In the DATA DIVISION using 88-level entries
  • In the ENVIRONMENT DIVISION
  • In the WORKING-STORAGE SECTION

4. What is the primary benefit of using condition names?

  • Faster execution
  • Better code readability and maintenance
  • Reduced memory usage
  • Improved performance

5. How are condition names used in conditional statements?

  • As arithmetic operators
  • As logical conditions in IF statements
  • As file operations
  • As data declarations

Frequently Asked Questions