MainframeMaster

COBOL Condition Names (88-levels)

Condition names (88-levels) create readable boolean conditions over data items, replacing magic values with meaningful names. They improve code clarity and make maintenance easier.

Basic Condition Name Declaration

cobol
1
2
3
4
5
6
WORKING-STORAGE SECTION. 01 CUSTOMER-STATUS PIC X VALUE 'A'. 88 ACTIVE-CUSTOMER VALUE 'A'. 88 INACTIVE-CUSTOMER VALUE 'I'. 88 SUSPENDED-CUSTOMER VALUE 'S'. 88 CLOSED-CUSTOMER VALUE 'C'.

Declare condition names using level 88 under a data item. Each condition name represents a specific value that the data item can have. Use meaningful names that describe the business condition.

Using Condition Names in Logic

cobol
1
2
3
4
5
6
7
8
9
10
IF ACTIVE-CUSTOMER DISPLAY 'Customer is active' PERFORM PROCESS-ACTIVE-CUSTOMER ELSE IF INACTIVE-CUSTOMER DISPLAY 'Customer is inactive' PERFORM PROCESS-INACTIVE-CUSTOMER ELSE IF SUSPENDED-CUSTOMER DISPLAY 'Customer is suspended' PERFORM PROCESS-SUSPENDED-CUSTOMER END-IF.

Use condition names directly in IF statements. This is much more readable than testing for 'A', 'I', or 'S' directly. The code becomes self-documenting and easier to understand.

Setting Values with Condition Names

cobol
1
2
3
4
5
6
7
8
9
*> Set values using condition names SET ACTIVE-CUSTOMER TO TRUE SET INACTIVE-CUSTOMER TO TRUE SET SUSPENDED-CUSTOMER TO TRUE *> Multiple values for same condition 01 PROCESSING-CODE PIC X. 88 VALID-CODES VALUE 'A' 'B' 'C' 'D'. 88 INVALID-CODES VALUE 'X' 'Y' 'Z'.

Use SET statement to assign values using condition names. You can define multiple values for the same condition name using a list. This centralizes all valid values in one place.

Complex Condition Names

cobol
1
2
3
4
5
6
01 TRANSACTION-AMOUNT PIC 9(9)V99. 88 SMALL-TRANSACTION VALUE 0 THRU 1000. 88 MEDIUM-TRANSACTION VALUE 1001 THRU 10000. 88 LARGE-TRANSACTION VALUE 10001 THRU 999999. 88 ZERO-AMOUNT VALUE 0. 88 POSITIVE-AMOUNT VALUE 1 THRU 999999.

Define ranges using THRU keyword for numeric conditions. You can create overlapping conditions and use them in complex logic. This makes business rules explicit and maintainable.

Nested Condition Names

cobol
1
2
3
4
5
6
7
8
9
10
11
12
01 CUSTOMER-RECORD. 05 CUSTOMER-TYPE PIC X. 88 INDIVIDUAL VALUE 'I'. 88 CORPORATE VALUE 'C'. 05 ACCOUNT-STATUS PIC X. 88 OPEN-ACCOUNT VALUE 'O'. 88 CLOSED-ACCOUNT VALUE 'C'. 05 CREDIT-RATING PIC 9. 88 EXCELLENT-CREDIT VALUE 9. 88 GOOD-CREDIT VALUE 7 THRU 8. 88 FAIR-CREDIT VALUE 5 THRU 6. 88 POOR-CREDIT VALUE 1 THRU 4.

Create condition names at different levels of a group item. This allows for complex business logic while keeping the code readable. Use meaningful prefixes to distinguish between different types of conditions.

Condition Names in EVALUATE

cobol
1
2
3
4
5
6
7
8
9
10
EVALUATE TRUE WHEN ACTIVE-CUSTOMER AND INDIVIDUAL PERFORM PROCESS-INDIVIDUAL-ACTIVE WHEN ACTIVE-CUSTOMER AND CORPORATE PERFORM PROCESS-CORPORATE-ACTIVE WHEN INACTIVE-CUSTOMER PERFORM PROCESS-INACTIVE WHEN OTHER PERFORM PROCESS-UNKNOWN-STATUS END-EVALUATE.

Use condition names in EVALUATE statements for complex decision logic. Combine multiple conditions using AND/OR operators. This makes complex business rules clear and maintainable.