The DECIMALS topic in field definitions is the decimal-positions parameter—the optional integer you code after the type letter on DEFINE and FILE lines. It does not add bytes to the field. It tells Easytrieve how many digit positions lie to the right of an implied decimal point inside the storage already described by length and type. GROSS 94 4 P 2 is four packed bytes where the last two digit positions represent cents. SERVICE 15 2 N 0 is whole years without fractional part—but still quantitative because zero is explicitly coded. Omit decimals entirely and the same bytes may be treated as unsigned non-quantitative with different sign handling and no automatic SUM. This page is the field-definition focused companion to the data types decimal page: how to code decimals on DEFINE, valid ranges per type, interaction with MASK and assignment options, and mapping COBOL V clauses.
Pattern: field-name, location, length, type-letter, decimal-positions. The decimal count is not written with a period—it is a separate integer token. P 5 2 is valid. P 5.2 is wrong syntax. EVEN for packed may follow decimals on P fields only.
12345PAY-GROSS 94 4 P 2 TAX-RATE W 3 P 4 HOURS 18 3 P 1 SERVICE W 2 N 0 DEPT 98 3 N
PAY-GROSS uses two decimals for currency. TAX-RATE four decimals for fractional rate 0.0825. HOURS one decimal for half-hour units. SERVICE uses explicit zero decimals for whole years. DEPT omits decimals—non-quantitative zoned if used as unsigned counter.
| Type | Decimal range | Example |
|---|---|---|
| N | 0–18 | AMT 10 9 N 2 |
| P | 0–18 | GROSS 94 4 P 2 |
| B | 0–10 | RATE 40 4 B 4 |
| U | 0–18 | QTY 50 3 U 0 |
| I | 0 only | COUNT W 4 I |
| A | Not valid | — |
Broadcom application guide states specifying decimal positions designates the field as signed quantitative—required for signed arithmetic and automatic totaling on control reports. Fields without decimal positions on numeric types are non-quantitative unsigned—leading zeros on print, positive sign assumptions on assignment left side. Currency almost always needs explicit decimals. Counters and codes sometimes omit decimals intentionally.
PIC S9(5)V99 COMP-3: five digits plus two fractional digits in five packed bytes—P 5 2. PIC 9(7)V99 display: eleven digit positions if V included in digit count—often N 11 2 for zoned. PIC S9(4)V9 COMP binary: verify COMP size—may be B 2 4 for four decimal places in two-byte binary quantitative field. V in COBOL counts decimal places; map to decimal-positions integer, not to extra length bytes.
Receive field decimal count influences stored scale after assignment. ROUNDED adjusts to receive decimals. TRUNCATED drops excess fractional digits. INTEGER truncates toward zero. Dividing two P 2 fields and storing in P 2 without rounding may lose fractional cents—test with known amounts. Literal 1234.56 assigns into P 5 2 with conversion per assignment rules.
123WS-TAX = GROSS * 0.15 WS-NET = GROSS - WS-TAX ROUNDED WS-PCT = (PART / TOTAL) * 100 TRUNCATED
Quantitative fields receive system default edit masks accounting for decimal count—commas and decimal point on LINE output. Override with MASK on same DEFINE. MASK nine count must align with field digits including decimal places. BWZ blank-when-zero works on quantitative fields with all zero amount.
REPORT SUM statement accumulates quantitative numeric fields. Fields with decimal positions specified participate when named in SUM. SUM on wrong scale field—missing decimals on amount—totals look like dollars but are stored as cents magnitude or vice versa. Reconcile SUM output against manual spreadsheet before production promotion.
N 2 0 explicitly quantitative with zero fractional digits. N 2 without third numeric parameter is non-quantitative—different rules. When copybook says whole number signed, prefer explicit 0 decimals for clarity in maintenance reviews.
DECIMALS tells the program where the cents part starts without drawing a dot on the number. Two decimals mean the last two digits are pennies. Zero decimals mean whole numbers only. If you forget to say how many cents digits exist, the program treats the box differently— like a whole piggy bank instead of dollars and cents.
1. Decimal-positions on DEFINE must be:
2. Specifying decimal positions—even zero—makes a field:
3. Type A fields can have decimal positions:
4. P 5 2 means:
5. Omitting decimals on numeric FILE amount often causes: