Easytrieve Packed Decimal (Type P)

Packed decimal—type P in Easytrieve, COMP-3 in COBOL—is how mainframe financial systems store money efficiently. Two digits squeeze into each byte except the last nybble, which carries the sign. A five-byte packed field can hold up to nine digits plus sign, far denser than one digit per byte zoned format. Payroll files, general ledger extracts, and invoice amounts overwhelmingly use P. Declare wrong length or decimal count and every field after the mistake reads misaligned bytes. This page teaches packed nybble layout, sign codes, EVEN option, decimal positions, and debugging with hex display.

Progress0 of 0 lessons

How Packed Storage Works

Each byte holds two decimal digits in nybbles (four bits each). The rightmost nybble of the last byte is the sign: F or C often positive, D negative in IBM conventions. Example: +123 in two bytes encodes as X'123F'. -123 encodes as X'123D'. The implied decimal point is not stored—it comes from decimal positions on DEFINE. P 3 2 might store 12345 representing 123.45.

text
1
2
3
DEFINE AMOUNT W 5 P 2 VALUE 1234.56 * Five bytes packed, two decimal places DISPLAY HEX AMOUNT

Declaring Type P Fields

Syntax: field-name, location, length, P, decimal-positions. SALARY 40 5 P 2 at byte forty, five bytes, two decimals. Working storage: WS-TOTAL W 7 P 2. Decimal positions 0 through eighteen. Specifying decimals makes field quantitative for automatic SUM on reports.

Packed sign nybble examples (typical IBM)
Value2-byte packed hexNote
+123X'123F'Positive sign F
-123X'123D'Negative sign D
+0X'000C' or similarZero patterns vary by context
Digits onlyPairs per byteLast nybble is sign

Length and Digit Capacity

Maximum P length ten bytes supports up to eighteen decimal digits with sign in last nybble— reference tables tie length to digit capacity and max decimal positions. A three-byte packed field holds fewer digits than seven-byte. Planning salary fields: estimate maximum amount with decimals, choose length that fits, verify against copybook COMP-3 length formula (digits + 1) / 2 rounded up for byte count.

EVEN Option

EVEN on DEFINE for P fields forces even digit count with high-order zero digit. Two-byte even packed holds exactly two digits such as X'012F' for 12. Use when file layout or external system requires even digit packed fields—uncommon but documented. EVEN valid only on P—not on N or A.

P vs N — When to Use Which

P when file is COMP-3 from COBOL or DB2 decimal export to packed. N when file is character numeric PIC 9 or zoned USAGE DISPLAY. P saves space and matches financial batch pipelines. N easier for human-readable DISPLAY without hex. Converting between them in assignment works but costs CPU in tight loops—match source format first.

Arithmetic with Packed Fields

ADD, subtract, multiply, divide in expressions use packed internal math when operands are P. WS-TAX = GROSS * 0.15 ROUNDED respects decimal positions on receive field. SUM GROSS on REPORT accumulates quantitative P fields. Watch overflow when result exceeds field capacity— test maximum wage amounts and bonus caps.

MASK on Packed Output

Default masks exist by P length and decimals. Custom MASK '$$$,$$9.99-' on DEFINE formats report columns. BWZ suppresses line when amount zero—common on detail lines, not always on totals. MASK does not alter packed bytes in storage.

COBOL COMP-3 Mapping

COBOL PIC S9(7)V99 COMP-3 typically maps to P length 5 with 2 decimals—seven digits plus two decimal digits fit five packed bytes. Always verify with copybook byte offset. SYNC and REDEFINES in COBOL may alter alignment—Easytrieve FILE must match physical record not just logical group picture.

Debugging Packed Data

  1. DISPLAY HEX field alongside edited DISPLAY field.
  2. Compare hex to known good values from COBOL dump.
  3. Verify length—off-by-one shifts sign nybble to wrong digit pair.
  4. Check decimal positions—value looks 100x too big or small.
  5. Confirm negative amounts use D sign not zoned minus character.

Common Packed Mistakes

  • Declaring P 4 when copybook needs P 5—misaligns rest of record.
  • Treating packed as A in FILE—displays garbage characters.
  • Wrong decimal count—penny amounts accumulate error over millions of rows.
  • Using EVEN without understanding even digit requirement.
  • Assuming unsigned when sign nybble present—use U for unsigned packed.

Explain It Like I'm Five

Packed decimal is putting two digit stickers in each box slot except the last sticker spot which tells if the number is plus or minus. You save box space compared to one digit per box. The decimal point is agreed in the rule book (decimal positions) not drawn on the stickers. If you use the wrong size box, every sticker after that sits in the wrong slot.

Exercises

  1. Map COBOL PIC S9(5)V99 COMP-3 to Easytrieve P length and decimals.
  2. State hex for +123 and -123 in two-byte packed.
  3. Explain what EVEN does on a P field.
  4. Write DEFINE for 7-byte packed total with 2 decimals in WS.
  5. Describe three steps to debug wrong salary amount.

Quiz

Test Your Knowledge

1. Packed decimal in Easytrieve uses type letter:

  • P
  • N
  • C
  • D

2. Value 123 in two-byte packed often appears as hex:

  • X'123F'
  • X'F1F2F3'
  • X'0123'
  • X'404040'

3. EVEN on DEFINE applies to:

  • P fields only
  • A fields only
  • All types
  • JCL

4. Maximum packed field length documented is:

  • 10 bytes
  • 18 bytes
  • 254 bytes
  • 4 bytes

5. Negative 123 packed sign nybble is often:

  • D
  • F
  • C
  • A
Published
Read time13 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 type P packed decimal and EVEN optionSources: Broadcom Easytrieve Report Generator 11.6 TechDocs, DEFINE Statement, Describe Files and FieldsApplies to: Easytrieve packed decimal COMP-3 fields