Easytrieve Data Types Overview

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.

Progress0 of 0 lessons

Where Types Are Declared

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.

text
1
2
3
4
5
6
FILE 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

Type Code Reference

Easytrieve data type letters
CodeNameUse whenDecimal positions?
AAlphanumericNames, codes, text, flags as charactersNo
NZoned decimalDisplay numeric, legacy file digitsYes (0-18)
PPacked decimalCOMP-3 amounts, tight numeric storageYes (0-18)
BBinaryBinary integers, counters, bit dataYes for quantitative
UUnsigned packedPacked without sign nybbleYes
IIntegerNative binary integers 2/4/8 bytes0 only
KDBCSDouble-byte character textNo
MMixedSBCS and DBCS in one fieldNo

A — Alphanumeric

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.

N — Zoned Decimal

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.

P — Packed Decimal

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.

B — Binary

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.

U — Unsigned Packed

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.

I — Integer

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.

K and M — DBCS and Mixed

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.

Decimal Positions

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.

Encoding: EBCDIC vs ASCII

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.

Type Conversion in Assignments

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.

Choosing the Right Type

  1. Start from file copybook or data dictionary—match existing layout exactly.
  2. Use P or N for amounts that SUM on reports with decimal positions.
  3. Use A for keys with leading zeros you must preserve as text.
  4. Use B or I for binary interfaces—not display amounts.
  5. Use K or M only when DBCS data is present in requirements.

Common Data Type Mistakes

  • Declaring packed file data as A and wondering why arithmetic fails.
  • Wrong P length shifting all subsequent field positions.
  • Using I with wrong byte length (3 bytes—not allowed).
  • Decimal positions on A fields—compile error.
  • Ignoring ASCII CODE on files ported from open systems.

Explain It Like I'm Five

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.

Exercises

  1. Define FILE fields for a six-digit employee number (N) and twenty-character name (A).
  2. Explain when P is better than N for a five-byte salary field.
  3. List all types that accept decimal positions.
  4. State valid byte lengths for type I.
  5. Describe how quantitative fields differ on reports.

Quiz

Test Your Knowledge

1. Alphanumeric file fields use data type:

  • A
  • N
  • P
  • I

2. IBM internal decimal format in files typically uses:

  • P (packed decimal)
  • A (alphanumeric)
  • K (DBCS)
  • M (mixed)

3. Integer type I fields must be length:

  • 2, 4, or 8 bytes
  • 1 byte only
  • Any length 1-254
  • 10 bytes fixed

4. Decimal positions on DEFINE apply to:

  • N, P, B, U, and I quantitative fields—not A
  • All types including A
  • A only
  • JCL DD only

5. Working storage alphabetic fields initialize to:

  • Blanks
  • Zeros
  • LOW-VALUES only
  • Random
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 DEFINE statement data type codesSources: Broadcom Easytrieve Report Generator 11.6 TechDocs, DEFINE Statement, Describe Files and FieldsApplies to: Easytrieve A N P B U I K M data type selection