MainframeMaster

COBOL Tutorial

COBOL ZEROES - Quick Reference

Progress0 of 0 lessons

Overview

ZEROES 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. ZEROES is an alternative plural form of the zero constant, with ZERO being the singular form and ZEROS being the primary plural form, though all represent the same value.

Key Features

  • Numeric constant - Represents the numeric value zero
  • Initialization - Used to initialize numeric variables
  • Comparisons - Used in conditional statements and comparisons
  • Arithmetic operations - Can be used in mathematical calculations

Syntax and Usage

ZEROES usage patterns for initialization, comparisons, and calculations.

Basic ZEROES Initialization

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
IDENTIFICATION DIVISION. PROGRAM-ID. ZEROES-INITIALIZATION. DATA DIVISION. WORKING-STORAGE SECTION. 01 COUNTER PIC 9(4) VALUE ZEROES. 01 ACCUMULATOR PIC 9(8) VALUE ZEROES. 01 TOTAL-AMOUNT PIC 9(10)V99 VALUE ZEROES. 01 ITEM-COUNT PIC 9(3) VALUE ZEROES. PROCEDURE DIVISION. DISPLAY "Counter: " COUNTER DISPLAY "Accumulator: " ACCUMULATOR DISPLAY "Total Amount: " TOTAL-AMOUNT DISPLAY "Item Count: " ITEM-COUNT STOP RUN.

Basic ZEROES initialization of numeric variables.

ZEROES in Comparisons

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
IDENTIFICATION DIVISION. PROGRAM-ID. ZEROES-COMPARISONS. DATA DIVISION. WORKING-STORAGE SECTION. 01 AMOUNT PIC 9(6)V99 VALUE 150.75. 01 BALANCE PIC 9(8)V99 VALUE ZEROES. 01 TRANSACTION-COUNT PIC 9(4) VALUE 0. PROCEDURE DIVISION. * Check if amount is zero IF AMOUNT = ZEROES DISPLAY "Amount is zero" ELSE DISPLAY "Amount is not zero: " AMOUNT END-IF * Check if balance is zero IF BALANCE = ZEROES DISPLAY "Balance is zero" ELSE DISPLAY "Balance is not zero: " BALANCE END-IF * Check if transaction count is zero IF TRANSACTION-COUNT = ZEROES DISPLAY "No transactions processed" ELSE DISPLAY "Transactions processed: " TRANSACTION-COUNT END-IF STOP RUN.

ZEROES usage in conditional statements and comparisons.

ZEROES in Arithmetic Operations

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
IDENTIFICATION DIVISION. PROGRAM-ID. ZEROES-ARITHMETIC. DATA DIVISION. WORKING-STORAGE SECTION. 01 VALUE-1 PIC 9(4) VALUE 100. 01 VALUE-2 PIC 9(4) VALUE ZEROES. 01 RESULT PIC 9(6). 01 QUOTIENT PIC 9(6). 01 REMAINDER PIC 9(4). PROCEDURE DIVISION. * Addition with ZEROES ADD ZEROES TO VALUE-1 GIVING RESULT DISPLAY "Value + ZEROES = " RESULT * Subtraction with ZEROES SUBTRACT ZEROES FROM VALUE-1 GIVING RESULT DISPLAY "Value - ZEROES = " RESULT * Multiplication with ZEROES MULTIPLY VALUE-1 BY ZEROES GIVING RESULT DISPLAY "Value * ZEROES = " RESULT * Division by ZEROES (error handling) IF VALUE-2 = ZEROES DISPLAY "Cannot divide by ZEROES" ELSE DIVIDE VALUE-1 BY VALUE-2 GIVING QUOTIENT REMAINDER REMAINDER DISPLAY "Division result: " QUOTIENT END-IF STOP RUN.

ZEROES usage in arithmetic operations with error handling.

Usage Patterns

Variable Initialization

Initialize numeric variables to zero.

cobol
1
2
3
01 COUNTER PIC 9(4) VALUE ZEROES. 01 TOTAL PIC 9(8)V99 VALUE ZEROES. 01 BALANCE PIC S9(10)V99 VALUE ZEROES.

Conditional Checks

Check if values are zero.

cobol
1
2
3
4
5
6
7
IF AMOUNT = ZEROES DISPLAY "Amount is zero" END-IF IF BALANCE NOT = ZEROES PERFORM PROCESS-BALANCE END-IF

Arithmetic Operations

Use ZEROES in calculations.

cobol
1
2
3
4
5
ADD ZEROES TO TOTAL MULTIPLY VALUE BY ZEROES GIVING RESULT IF DIVISOR = ZEROES DISPLAY "Division by zero error" END-IF

Loop Control

Use ZEROES for loop initialization.

cobol
1
2
3
4
5
MOVE ZEROES TO LOOP-COUNTER PERFORM UNTIL LOOP-COUNTER >= MAX-COUNT ADD 1 TO LOOP-COUNTER PERFORM PROCESS-ITEM END-PERFORM

Best Practices

  • Initialization - Use ZEROES to initialize numeric variables
  • Readability - Use ZEROES instead of literal 0 for better code readability
  • Error handling - Check for division by ZEROES to prevent runtime errors
  • Consistency - Use ZEROES consistently throughout your program
  • Documentation - ZEROES makes code self-documenting

ZEROES Quick Reference

UsageSyntaxPurpose
InitializationVALUE ZEROESInitialize variables to zero
ComparisonIF X = ZEROESCheck if value equals zero
ArithmeticADD ZEROES TO XUse in calculations
Error CheckIF DIVISOR = ZEROESPrevent division by zero

Test Your Knowledge

1. What is the primary purpose of ZEROES in COBOL?

  • To represent the numeric value zero in calculations and comparisons
  • To generate random numbers
  • To format output
  • To handle text strings

2. How does ZEROES compare to ZERO and ZEROS in COBOL?

  • ZEROES is an alternative plural form, ZERO is singular, ZEROS is primary plural
  • They are all exactly the same
  • ZEROES is faster than ZERO and ZEROS
  • ZEROES only works with integers

3. What is the main use case for ZEROES in COBOL?

  • To generate random numbers
  • To initialize variables, perform comparisons, and represent zero in calculations
  • To format output strings
  • To handle text processing

4. How does ZEROES behave in arithmetic operations?

  • It causes errors in all operations
  • It behaves as the numeric value zero in all arithmetic operations
  • It only works in addition
  • It only works in subtraction

5. What is a common use case for ZEROES in COBOL programs?

  • To generate random numbers
  • To initialize counters, accumulators, and perform zero-based comparisons
  • To format output
  • To handle text strings

Frequently Asked Questions