Every field in Easytrieve—whether read from a payroll file or declared in working storage—has a data type that tells the compiler how bytes are interpreted, how arithmetic proceeds, and how reports edit values on paper. Unlike languages with int and string keywords, Easytrieve uses single-letter codes on DEFINE and FILE lines: A for alphanumeric text, N for zoned decimal, P for packed decimal, and more. Choosing the wrong type corrupts comparisons, breaks SUM totals, and misaligns with COBOL copybooks. This overview introduces each type, when to use it, how decimal positions work, and how types interact in MOVE and IF statements.
FILE statements describe record layouts with field name, start position, length, and type. DEFINE adds fields in working storage or refines file overlays. Syntax pattern: field-name, location (position number or W for working storage), length in bytes, type letter, optional decimal positions, optional VALUE, MASK, HEADING. The type letter is mandatory—omitting it is a compile error. Field length and type must match physical data in the file or your intended storage size in working storage.
123456FILE PERSNL FB(80 800) EMPNO 1 6 N 0 EMPNAME 7 20 A GROSS 27 5 P 2 DEFINE WS-TOTAL W 7 P 2
| Code | Name | Use when | Decimal positions? |
|---|---|---|---|
| A | Alphanumeric | Names, codes, text, flags as characters | No |
| N | Zoned decimal | Display numeric, legacy file digits | Yes (0-18) |
| P | Packed decimal | COMP-3 amounts, tight numeric storage | Yes (0-18) |
| B | Binary | Binary integers, counters, bit data | Yes for quantitative |
| U | Unsigned packed | Packed without sign nybble | Yes |
| I | Integer | Native binary integers 2/4/8 bytes | 0 only |
| K | DBCS | Double-byte character text | No |
| M | Mixed | SBCS and DBCS in one field | No |
Type A holds characters—letters, digits, symbols—in EBCDIC on the mainframe unless the file or PARM declares ASCII. Maximum length 254 bytes. No decimal positions. File fields match COBOL PIC X layouts. Working storage A fields initialize to blanks. Use A when data is not purely numeric for arithmetic—names, addresses, status codes, keys with leading zeros preserved as text. VARYING on A creates SQL-style variable length with two-byte length prefix.
Type N stores digits in zoned decimal format—one digit per byte with zone bits. Digit 0 is X'F0' in EBCDIC. Use N when file layout matches COBOL PIC 9 display numeric or signed zoned fields. Supports decimal positions for dollars and rates. Arithmetic and SUM on reports treat quantitative N fields as numbers. Misdeclaring zoned data as A still compares as text—999 sorts differently than numeric 999 in some contexts.
Type P is IBM packed decimal (COMP-3). Two digits per byte plus sign nybble in the last byte. Value 123 in two bytes might be X'123F'; -123 might be X'123D'. Common for amounts in financial files. EVEN option forces even digit count in packed fields. Decimal positions specify implied decimal point for arithmetic and MASK editing. Wrong length on P fields shifts all following FILE positions—verify against copybook.
Type B holds pure binary data. Quantitative B fields with decimal positions use high-order bit as sign. Non-quantitative B uses all bits as magnitude without sign semantics. Use for binary counters, timestamps, or interfacing with system structures. Assignment between B and N or P triggers conversion per format rules. DISPLAY HEX helps debug unexpected bit patterns during migration.
Type U is packed decimal without sign—only non-negative values. Two-byte example 123 may appear as X'0123' per Broadcom documentation. Use when business rules guarantee no negative quantities and file layout matches unsigned packed definitions. Decimal positions apply like P fields.
Type I stores native binary integers in two, four, or eight bytes depending on length coded. Values follow host endianness—mainframe versus open systems differ. Decimal positions must be blank or zero. Not portable if you depend on specific hex patterns across platforms. Ideal for loop counters and API buffers when binary int layout is known.
Type K is DBCS alphanumeric for Kanji and other double-byte scripts. Type M mixes single-byte and double-byte in one field with shift codes. Multinational applications use these; ASCII-only beginners may defer until requirements appear. Literal and conversion rules in Literal and Data Formatting Rules govern MIXED and DBCS interactions—unsupported format pairs error at compile time.
Code an integer 0 through 18 after numeric type letters to mark implied decimal places. Specifying decimal positions—even 0—makes a field quantitative. Quantitative fields participate in automatic SUM on reports. A field defined P 5 2 holds values up to five bytes with two decimal places—interpretation affects whether 12345 displays as 123.45. Omitting decimals on a B field makes it non-quantitative with different sign bit meaning.
A-type file fields are EBCDIC unless FILE CODE ASCII or PARM CODE applies. Working storage A follows PARM CODE PROCESS value. N zone nybbles differ between EBCDIC and ASCII—migration projects revalidate all zoned fields. Numeric P and B types are not character-encoded but bit layouts still require endian awareness for I fields.
MOVE and assignment statements convert between compatible types. Assigning N to A may produce edited character digits in the receive field per Broadcom examples. Assigning A to N requires numeric content or conversion errors. INTEGER, ROUNDED, and TRUNCATED options apply only to numeric receives. Plan types so hot paths avoid repeated conversion overhead in tight loops on large files.
Data types are labels on boxes telling workers what is inside. A box marked A holds words and letters. N and P boxes hold money numbers but packed differently—like coins stacked two per slot versus one coin per slot. B boxes hold machine counting codes. Pick the wrong label and someone might treat letters as money or stack coins wrong—the contents look messy even if the box size is right.
1. Alphanumeric file fields use data type:
2. IBM internal decimal format in files typically uses:
3. Integer type I fields must be length:
4. Decimal positions on DEFINE apply to:
5. Working storage alphabetic fields initialize to: