Chapter 7. COMPUTING IN COBOL: THE ARITHMETIC VERBS

CHAPTER OBJECTIVES

Upon completion of this chapter, you should be able to

  • Demonstrate the various formats of the ADD, SUBTRACT, MULTIPLY, and DIVIDE operations.

  • Demonstrate the various options that are available with the arithmetic operations.

  • Demonstrate the use of scope terminators.

  • Demonstrate the use of the COMPUTE statement.

  • Demonstrate the use of the INITIALIZE statement.

  • Demonstrate the use of the LIKE clause.

THE FOUR BASIC ARITHMETIC OPERATIONS

All the basic arithmetic operations, ADD, SUBTRACT, MULTIPLY, and DIVIDE, require that the fields operated on (1) have numeric PICTURE clauses and (2) actually have numeric data when the program is executed. Keep in mind that the data-fields specified in any arithmetic statement must be defined in the DATA DIVISION, either in an input or output area of the FILE SECTION, or in the WORKING-STORAGE SECTION. Let us consider each of these arithmetic operations.

ADD STATEMENT

A simple ADD statement has the following instruction formats.

Instruction Format 1 (ADD . . . TO)

Examples:

ADD STATEMENT

Instruction Format 2 (ADD . . . GIVING)

Examples:

ADD STATEMENT

Instruction Format 3 (ADD..TO..GIVING)

Examples:

ADD STATEMENT

Let us review some rules for ...

Get PROGRAMMING IN COBOL/400: 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.