Binary type B stores raw bytes—not zoned digits, not packed nybbles. Mainframe programs use binary for bit flags, binary counters from system APIs, and COBOL COMP/COMP-4 layouts. Easytrieve distinguishes quantitative B fields with decimal positions where the high-order bit is sign from non-quantitative B where every bit is data. Confuse the two and sign handling inverts. Bit manipulation with AND, OR, and XOR hex masks clears status bits and merges flag bytes. Currency belongs in P, not B—but B is essential for interface records and low-level control blocks. This page teaches declaration, sign rules, masks, and debugging.
Syntax: field-name, location, length, B, optional decimal positions. FLAGS 20 2 B defines two-byte non-quantitative binary—sixteen data bits. COUNTER 22 4 B 0 defines four-byte quantitative binary integer with zero decimals—sign bit applies. Length typically up to four bytes in standard tables; verify DEFINE documentation for your release capacity.
123456DEFINE F1P W 2 P MASK HEX DEFINE F2P W 2 P VALUE X'123D' F1P = F2P AND X'FFFE' F1P = F2P OR X'000F' F1P = F2P XOR X'FFFF'
| Mode | Decimal positions | High-order bit | Typical use |
|---|---|---|---|
| Non-quantitative | Omitted | Data bit | Flags, bit maps, raw bytes |
| Quantitative | 0-10 specified | Sign bit | Binary numeric values |
Specifying decimal positions—even 0—makes B quantitative. Omitting decimals entirely yields non-quantitative where all bits contribute to magnitude without signed interpretation. Choose mode before writing IF comparisons on high bit as flag versus sign.
Logical assignment format: receive = send AND mask, OR mask, XOR mask. Masks may be hex literals X'FFFE' or binary-friendly fields. AND clears bits where mask is zero. OR sets bits where mask is one. XOR toggles bits. Broadcom assignment examples use packed fields with MASK HEX for display—binary logic applies to underlying bytes. Test each operation with DISPLAY HEX before production flag updates.
Type I is native integer—must be 2, 4, or 8 bytes, decimals blank or zero, host endianness. Type B supports up to four bytes with optional decimal semantics as binary numeric. APIs documenting 32-bit int may map to I 4; bitfield structures from COBOL may map to B 2 non-quantitative. Do not interchange blindly—hex patterns differ.
COBOL COMP binary items align to B fields when length and decimal usage match. SYNC boundaries in copybooks affect starting position—Easytrieve FILE position must match physical layout. COMP-4 and COMP-5 variants may differ from older COMP—consult copybook for exact byte length.
Quantitative B fields participate in arithmetic expressions with conversion to internal forms. Adding two binary counters works when both quantitative with matching decimals. Non-quantitative B in arithmetic may misinterpret sign bit as data—keep flags separate from math fields. SUM on reports applies to quantitative B rarely in business reports— usually P and N dominate totals.
DISPLAY HEX reveals bit patterns invisible in character DISPLAY. Compare before and after AND OR XOR operations. Mask width must match field length—two-byte field uses four hex digits inside X'....'. Varying fields exclude standard HEX in some contexts per screen formatting docs—use fixed B for flag tutorials.
Binary fields are rows of light switches—on or off in each spot. Sometimes the first switch means plus or minus for a number; sometimes every switch is just a flag for something like is the door open. AND OR XOR are rules for flipping groups of switches using a stencil (the mask). You look at the switches in hex code because they are too small to read as letters.
1. Binary numeric fields use type letter:
2. Non-quantitative B field high-order bit is:
3. Quantitative B field high-order bit is:
4. Bit masks in assignment use operators:
5. Maximum binary field length documented is: