Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
← Back to Conditional Logic
Conditional Logic | Intermediate | COBOL

Complex Conditions

Problem Description

Combine conditions using AND, OR, NOT operators.

Expected Output

Multiple condition evaluation

Hints

Use parentheses to control evaluation order.

Solution

IDENTIFICATION DIVISION. PROGRAM-ID. COMPLEX. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-AGE PIC 9(3). 01 WS-INCOME PIC 9(7). 01 WS-CREDIT PIC 9(3). 01 WS-ELIGIBLE PIC X(3). PROCEDURE DIVISION. DISPLAY "ENTER AGE: ". ACCEPT WS-AGE. DISPLAY "ENTER ANNUAL INCOME: ". ACCEPT WS-INCOME. DISPLAY "ENTER CREDIT SCORE: ". ACCEPT WS-CREDIT. * Complex condition with AND, OR IF (WS-AGE >= 21 AND WS-AGE <= 65) AND (WS-INCOME >= 30000 OR WS-CREDIT >= 700) MOVE "YES" TO WS-ELIGIBLE DISPLAY "LOAN ELIGIBLE: YES" ELSE MOVE "NO" TO WS-ELIGIBLE DISPLAY "LOAN ELIGIBLE: NO" END-IF. * Using NOT IF NOT (WS-CREDIT < 600) DISPLAY "CREDIT SCORE OK" ELSE DISPLAY "POOR CREDIT SCORE" END-IF. * Checking multiple values IF WS-AGE = 18 OR 21 OR 25 OR 30 DISPLAY "MILESTONE AGE!" END-IF. * Range check IF WS-INCOME >= 50000 AND <= 100000 DISPLAY "MIDDLE INCOME BRACKET" END-IF. STOP RUN.

Explanation:

AND, OR, NOT combine conditions. Parentheses control order. THRU for ranges.