Skip to main content
Module 2 · Lesson 1 of 23/16 in the course~15 min
Module lessons (1/2)

Arithmetic COBOL and COMPUTE

Lesson preview5 hands-on exercises readyCourse COBOL · Module 2 — Arithmetic and Decisions

Perform calculations with ADD/SUBTRACT/MULTIPLY/DIVIDE GIVING REMAINDER, master COMPUTE and mandatory spaces around operators.

What you'll learn in this lesson

  • Perform elementary calculations with ADD, SUBTRACT, MULTIPLY, and DIVIDE understanding the protective role of the GIVING clause.
  • Write readable algebraic formulas with COMPUTE, respecting the strict rule of spaces around each operator (+, -, *, /, =).
  • Prevent silent decimal truncation or integer overflows via ROUNDED and ON SIZE ERROR.

Overview

In COBOL, mathematical operations can be written either with traditional conversational verbs meant to be read aloud by accountants, or with the algebraic statement COMPUTE.

Each arithmetic verb directly modifies the last operand if you don't specify GIVING. However, when you add GIVING, the source operands remain unchanged and the result goes into the destination field:

Sections covered in this lesson

  1. 11. Formal verbs (ADD, SUBTRACT, MULTIPLY, DIVIDE)
  2. 22. The algebraic instruction COMPUTE and the required spaces
  3. 33. Rounding (ROUNDED) and Overflow (ON SIZE ERROR)
  4. 4Try it yourself
Pro Lesson · Module 2 — Arithmetic and Decisions

Unlock "Arithmetic COBOL and COMPUTE" and the full Course COBOL curriculum

Perform calculations with ADD/SUBTRACT/MULTIPLY/DIVIDE GIVING REMAINDER, master COMPUTE and mandatory spaces around operators.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course COBOL plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.