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.
| Code | Name | Typical max length | Decimals | COBOL parallel |
|---|---|---|---|---|
| N | Zoned decimal | 18 bytes | 0-18 | PIC 9 display |
| P | Packed decimal | 10 bytes | 0-18 | COMP-3 |
| B | Binary | 4 bytes | 0-10 quantitative | COMP/COMP-4 |
| U | Unsigned packed | 9 bytes | 0-18 | Packed unsigned |
| I | Integer | 2, 4, 8 only | 0 only | Binary int |
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.
1234567FILE 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
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 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.
123WS-TAX = GROSS * 0.15 WS-NET = GROSS - WS-TAX ROUNDED WS-PCT = (PART / TOTAL) * 100 TRUNCATED
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.
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.
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.
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.
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.
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.
1. Packed decimal amounts typically use type:
2. Quantitative fields with decimal positions:
3. Integer type I valid lengths are:
4. Zoned decimal display digit 0 in EBCDIC is:
5. ROUNDED and TRUNCATED on assignment apply to: