ZEROS in COBOL is a figurative constant that represents the numeric value zero. It is used for initializing variables, performing comparisons, and representing zero in calculations. ZEROS is the plural form of the zero constant, with ZERO being the singular form and ZEROES being an alternative plural form, though all represent the same value.
ZEROS usage patterns for initialization, comparisons, and calculations.
123456789101112131415IDENTIFICATION DIVISION. PROGRAM-ID. ZEROS-INITIALIZATION. DATA DIVISION. WORKING-STORAGE SECTION. 01 COUNTER PIC 9(4) VALUE ZEROS. 01 ACCUMULATOR PIC 9(8) VALUE ZEROS. 01 TOTAL-AMOUNT PIC 9(10)V99 VALUE ZEROS. 01 ITEM-COUNT PIC 9(3) VALUE ZEROS. PROCEDURE DIVISION. DISPLAY "Counter: " COUNTER DISPLAY "Accumulator: " ACCUMULATOR DISPLAY "Total Amount: " TOTAL-AMOUNT DISPLAY "Item Count: " ITEM-COUNT STOP RUN.
Basic ZEROS initialization of numeric variables.
12345678910111213141516171819202122232425262728293031IDENTIFICATION DIVISION. PROGRAM-ID. ZEROS-COMPARISONS. DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC 9(6)V99 VALUE 150.75. 01 BALANCE PIC 9(8)V99 VALUE ZEROS. 01 TRANSACTION-COUNT PIC 9(4) VALUE 0. PROCEDURE DIVISION. * Check if amount is zero IF AMOUNT = ZEROS DISPLAY "Amount is zero" ELSE DISPLAY "Amount is not zero: " AMOUNT END-IF * Check if balance is zero IF BALANCE = ZEROS DISPLAY "Balance is zero" ELSE DISPLAY "Balance is not zero: " BALANCE END-IF * Check if transaction count is zero IF TRANSACTION-COUNT = ZEROS DISPLAY "No transactions processed" ELSE DISPLAY "Transactions processed: " TRANSACTION-COUNT END-IF STOP RUN.
ZEROS usage in conditional statements and comparisons.
1234567891011121314151617181920212223242526272829303132IDENTIFICATION DIVISION. PROGRAM-ID. ZEROS-ARITHMETIC. DATA DIVISION. WORKING-STORAGE SECTION. 01 VALUE-1 PIC 9(4) VALUE 100. 01 VALUE-2 PIC 9(4) VALUE ZEROS. 01 RESULT PIC 9(6). 01 QUOTIENT PIC 9(6). 01 REMAINDER PIC 9(4). PROCEDURE DIVISION. * Addition with ZEROS ADD ZEROS TO VALUE-1 GIVING RESULT DISPLAY "Value + ZEROS = " RESULT * Subtraction with ZEROS SUBTRACT ZEROS FROM VALUE-1 GIVING RESULT DISPLAY "Value - ZEROS = " RESULT * Multiplication with ZEROS MULTIPLY VALUE-1 BY ZEROS GIVING RESULT DISPLAY "Value * ZEROS = " RESULT * Division by ZEROS (error handling) IF VALUE-2 = ZEROS DISPLAY "Cannot divide by ZEROS" ELSE DIVIDE VALUE-1 BY VALUE-2 GIVING QUOTIENT REMAINDER REMAINDER DISPLAY "Division result: " QUOTIENT END-IF STOP RUN.
ZEROS usage in arithmetic operations with error handling.
Initialize numeric variables to zero.
12301 COUNTER PIC 9(4) VALUE ZEROS. 01 TOTAL PIC 9(8)V99 VALUE ZEROS. 01 BALANCE PIC S9(10)V99 VALUE ZEROS.
Check if values are zero.
1234567IF AMOUNT = ZEROS DISPLAY "Amount is zero" END-IF IF BALANCE NOT = ZEROS PERFORM PROCESS-BALANCE END-IF
Use ZEROS in calculations.
12345ADD ZEROS TO TOTAL MULTIPLY VALUE BY ZEROS GIVING RESULT IF DIVISOR = ZEROS DISPLAY "Division by zero error" END-IF
Use ZEROS for loop initialization.
12345MOVE ZEROS TO LOOP-COUNTER PERFORM UNTIL LOOP-COUNTER >= MAX-COUNT ADD 1 TO LOOP-COUNTER PERFORM PROCESS-ITEM END-PERFORM
Usage | Syntax | Purpose |
---|---|---|
Initialization | VALUE ZEROS | Initialize variables to zero |
Comparison | IF X = ZEROS | Check if value equals zero |
Arithmetic | ADD ZEROS TO X | Use in calculations |
Error Check | IF DIVISOR = ZEROS | Prevent division by zero |
1. What is the primary purpose of ZEROS in COBOL?
2. How does ZEROS compare to ZERO and ZEROES in COBOL?
3. What is the main use case for ZEROS in COBOL?
4. How does ZEROS behave in arithmetic operations?
5. What is a common use case for ZEROS in COBOL programs?