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

COMP-3 Packed Decimal, ROUNDED and ON SIZE ERROR

Lesson preview5 hands-on exercises readyCourse COBOL · Module 8 — COMP-3, Tax Accuracy & Legacy Ops

Calculate exact bytes of PIC S9(N)V99 COMP-3, avoid rounding errors IEEE-754 in accounting and trap overflow with ON SIZE ERROR.

What you'll learn in this lesson

  • Understand why fixed decimal point types (PIC S9(n)V99) avoid the binary rounding of float/double.
  • Calculate the byte footprint of COMP-3 (Packed Decimal) using the formula (cifre + 1) / 2 rounded to the next integer.
  • Protect monetary calculations from silent truncation using ROUNDED and ON SIZE ERROR.
  • Format numeric results for print reports using editing characters (ZZ,ZZ9.99-).

Overview

On z/OS mainframe processors have hardware instructions dedicated to decimal calculation (BCD / Packed Decimal). Here you will find out how to choose the right archiving format and avoid accounting pitfalls.

COBOL offers three large families of numeric storage via the USAGE clause:

Sections covered in this lesson

  1. 11. Comparison between DISPLAY, COMP-3 and COMP
  2. 22. Visual laboratory: PIC and size COMP-3
  3. 33. Rounding (ROUNDED) and overflow protection (ON SIZE ERROR)
  4. 44. Accounting formatting for reports
  5. 5Try it yourself
Pro Lesson · Module 8 — COMP-3, Tax Accuracy & Legacy Ops

Unlock "COMP-3 Packed Decimal, ROUNDED and ON SIZE ERROR" and the full Course COBOL curriculum

Calculate exact bytes of PIC S9(N)V99 COMP-3, avoid rounding errors IEEE-754 in accounting and trap overflow with ON SIZE ERROR.

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.