Module lessons (1/2)
Arithmetic COBOL and COMPUTE
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, andDIVIDEunderstanding the protective role of theGIVINGclause. - Write readable algebraic formulas with
COMPUTE, respecting the strict rule of spaces around each operator (+,-,*,/,=). - Prevent silent decimal truncation or integer overflows via
ROUNDEDandON 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
- 11. Formal verbs (
ADD,SUBTRACT,MULTIPLY,DIVIDE) - 22. The algebraic instruction
COMPUTEand the required spaces - 33. Rounding (
ROUNDED) and Overflow (ON SIZE ERROR) - 4Try it yourself
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.