Easytrieve Numeric Data Type

Numeric data drives payroll totals, inventory counts, tax calculations, and every SUM line on a report. Easytrieve does not use one universal number type—it offers N, P, B, U, and I, each mirroring mainframe storage formats COBOL programmers already know. Pick wrong and amounts look like garbage in DISPLAY HEX, control breaks subtotal incorrectly, or ADD produces overflow truncation. This overview explains each numeric family, decimal positions, quantitative versus non-quantitative fields, arithmetic assignment options, and how numeric types convert between each other and into character fields for printing.

Progress0 of 0 lessons

Numeric Type Family

Easytrieve numeric types at a glance
CodeNameTypical max lengthDecimalsCOBOL parallel
NZoned decimal18 bytes0-18PIC 9 display
PPacked decimal10 bytes0-18COMP-3
BBinary4 bytes0-10 quantitativeCOMP/COMP-4
UUnsigned packed9 bytes0-18Packed unsigned
IInteger2, 4, 8 only0 onlyBinary int

Declaring Numeric Fields

Pattern: name, position or W, length, type letter, optional decimal positions. GROSS 27 5 P 2 is five-byte packed with two decimals at byte twenty-seven of the record. WS-TOTAL W 9 N 2 is nine-byte zoned working storage with two implied decimal places. Omitting decimals on B makes a non-quantitative binary field where high bit is data not sign.

text
1
2
3
4
5
6
7
FILE PAYROLL FB(200 2000) EMPNO 1 6 N 0 GROSS 10 5 P 2 HOURS 15 3 P 1 DEFINE WS-TAX W 5 P 2 DEFINE WS-COUNT W 4 B

Decimal Positions and Quantitative Fields

Coding decimal positions—even zero—marks a field quantitative. Quantitative fields auto-SUM on reports when referenced in SUM statements. P 5 2 holds values where two decimal places are implied: stored 12345 may represent 123.45 depending on editing. DECIMALS on DEFINE aligns with decimal-positions parameter terminology in manuals. Type A cannot have decimals.

Arithmetic and Assignment

Arithmetic expressions use plus, minus, asterisk, slash with spaces around operators. Receive field type influences conversion. ROUNDED rounds on assignment; TRUNCATED truncates; INTEGER truncates toward zero for integer receive. Logical bit assignments use AND OR XOR with hex masks on binary-friendly fields. All operands in pure arithmetic must be numeric.

text
1
2
3
WS-TAX = GROSS * 0.15 WS-NET = GROSS - WS-TAX ROUNDED WS-PCT = (PART / TOTAL) * 100 TRUNCATED

Numeric vs Character

Assigning N or P to A produces character edited digits in receive field per Broadcom assignment examples—useful for DISPLAY without separate masks. Assigning A to N requires numeric character content. IDs with leading zeros stay type A; amounts that SUM stay P or N. Never store social security as P if leading zeros matter in character form—use A or masked N with leading nine edit on report only.

Initialization

Numeric working storage initializes to zero without VALUE. VALUE 1234.5 on P field sets initial packed amount. FILE fields inherit file bytes on read—uninitialized file data is a data quality issue not compiler zero fill. LOW-VALUES in file numerics causes wrong arithmetic until validated with IF.

MASK and Display

Numeric fields receive default system masks by length and decimal count. Override with MASK on DEFINE: '$$,$$9.99', 'ZZZ,ZZ9.99-', BWZ to blank zero amounts. MASK affects DISPLAY, LINE, TITLE numeric fields—not stored value. Alphanumeric fields cannot use standard numeric MASK except MASK HEX.

Comparison and IF

IF GROSS GT 1000 compares numeric values with implied decimals applied. Compare like types when possible to avoid conversion surprises. EQ between P and N may convert internally per format rules. Testing boundary values—exactly equal threshold, negative amounts, zero— catches decimal alignment bugs before production cycle.

Overflow and Capacity

Each type has maximum digit capacity by length. Packed P length five with two decimals cannot hold arbitrarily large amounts. Assignment overflow may truncate or wrap depending on type—test extremes. I integers have explicit min/max by byte length in DEFINE documentation for signed and unsigned interpretations.

Choosing a Numeric Type

  1. Read copybook or DB2 DCLGEN—match exactly.
  2. Use P for COMP-3 financial extracts majority of mainframe shops.
  3. Use N when interfacing display numeric files or easy human DISPLAY debug.
  4. Use B or I for binary APIs, counters, bit flags—not currency.
  5. Use U when layout specifies unsigned packed without sign nybble.

Common Numeric Mistakes

  • Wrong P length shifting all following FILE fields.
  • Missing decimal positions on amount that should SUM.
  • Arithmetic on A fields with digit strings.
  • Expecting portable I hex across mainframe and x86.
  • MASK BWZ hiding zero that IF logic still treats as zero.

Explain It Like I'm Five

Numeric types are different piggy banks for numbers. N is coins lined up one per slot you can read easily. P squishes two digit coins into one slot to save space. B is a machine counter with on-off switches. Pick the bank shape that matches the file you are reading— if you squeeze coins wrong, the total count is wrong even if the label says dollars.

Exercises

  1. Define five-byte P 2 salary and three-byte P 1 hours fields.
  2. Write assignment computing tax at 15% with ROUNDED.
  3. Explain quantitative vs non-quantitative B field.
  4. Map COBOL PIC S9(5)V99 COMP-3 to Easytrieve.
  5. List valid I field byte lengths.

Quiz

Test Your Knowledge

1. Packed decimal amounts typically use type:

  • P
  • A
  • K
  • M

2. Quantitative fields with decimal positions:

  • Auto-SUM on reports
  • Never print
  • Must be type A
  • Cannot use IF

3. Integer type I valid lengths are:

  • 2, 4, or 8 bytes
  • 1 through 254
  • 10 only
  • Same as P

4. Zoned decimal display digit 0 in EBCDIC is:

  • X'F0'
  • X'40'
  • X'00'
  • X'30'

5. ROUNDED and TRUNCATED on assignment apply to:

  • Numeric receive fields
  • All A fields
  • JCL only
  • Comments
Published
Read time14 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 numeric type N P B U I rulesSources: Broadcom Easytrieve Report Generator 11.6 TechDocs, DEFINE Statement, Assignment StatementApplies to: Easytrieve numeric data types and arithmetic