Easytrieve Bit Fields

A bit field packs many on-off switches into one binary storage unit. Instead of ten one-character Y/N flags consuming ten bytes, a two-byte binary halfword holds sixteen independent bits—each bit can mean record updated, tax exempt, or error pending. Easytrieve represents bit containers as type B fields without decimal positions—non-quantitative mode where every bit is data, not sign. You set and test bits with AND, OR, and XOR assignments using hex mask literals from the hex values page. Mis-declare the same bytes as quantitative B 2 0 and the high bit becomes sign, corrupting flag semantics. Interface programs reading COBOL COMP status words or CICS response codes depend on correct bit handling. This page teaches bit numbering, mask tables, set-clear-test patterns, and when character flags beat bit packing for maintainability.

Progress0 of 0 lessons

Declaring Bit Containers

Define STATUS 20 2 B without decimal positions for sixteen flag bits starting at byte twenty of the record. Length one gives eight bits; length four gives thirty-two. Do not add decimal positions unless the bytes represent signed binary numbers—not individual flags. VALUE X'0000' initializes all bits off at program start for working storage.

text
1
2
3
4
5
FILE CONTROL FB(80 800) STATUS-WORD 10 2 B COUNT 12 4 B 0 DEFINE WS-FLAGS W 2 B VALUE X'0000'

STATUS-WORD is non-quantitative flags from file. COUNT is quantitative binary integer with zero decimals—high bit is sign, not flag bit zero. Never mix both semantics on the same field definition.

Bit Numbering in a Two-Byte Field

Convention in many mainframe docs numbers bits 0 through 15 left to right within the hex display of the field—bit 0 is often least significant bit of the rightmost byte. Verify your shop diagram—some documentation reverses bit order in diagrams. Consistency matters more than universal standard when writing masks.

Example two-byte mask reference (low byte bits 0–7)
BitSet mask (OR)Clear mask (AND)
0X'0001'X'FFFE'
1X'0002'X'FFFD'
2X'0004'X'FFFB'
3X'0008'X'FFF7'
7X'0080'X'FF7F'

Set, Clear, and Toggle Operations

Set bit: field = field OR mask. Clear bit: field = field AND clear-mask where clear-mask has zero at target bit. Toggle: field = field XOR mask. Broadcom assignment examples demonstrate packed fields with MASK HEX; same operators apply to B containers. Always assign back to same field or another field of matching length.

text
1
2
3
4
5
6
7
8
* Set bit 0 on WS-FLAGS = WS-FLAGS OR X'0001' * Clear bit 0 WS-FLAGS = WS-FLAGS AND X'FFFE' * Toggle all bits in two-byte field WS-FLAGS = WS-FLAGS XOR X'FFFF'

Testing Bits in IF Logic

Copy field to work area, AND with test mask, compare result to zero or to mask. Some shops define bit-test PROCs. Simpler path for beginners: maintain parallel A 1 flags updated whenever bits change—trade storage for readable IF ACTIVE-FLAG EQ Y. High-volume interfaces keep bits only to match external layout.

text
1
2
3
4
5
DEFINE WS-TEST W 2 B WS-TEST = STATUS-WORD AND X'0001' IF WS-TEST NE 0 DISPLAY 'BIT 0 IS ON' END-IF

Bit Fields vs Character Flags

When to use bits vs character flags
ApproachAdvantagesDisadvantages
B bit fieldCompact; matches APIsHarder to read in dumps without hex
A 1 Y/NReadable IF and reportsOne byte per flag
N 1 0Numeric 0/1 testsNot standard for all interfaces

COBOL COMP and Status Words

COBOL copybooks document flag bytes as PIC S9(4) COMP or binary items with level-88 condition names per bit. Easytrieve maps the container as B 2 non-quantitative. Individual 88-level names become documentation for your mask constants—BIT-ACTIVE equals OR X'0004' when copybook says bit two means active. Transcribe mask values from copybook comments, not from guesswork.

Multiple Bits in One Operation

OR X'000F' sets low four bits at once. AND X'FFF0' clears low four bits. Design mask constants as named VALUE fields in working storage for maintainability—avoid magic hex scattered through fifty assignment lines without comments.

Bit Fields in FILE Records

FILE STATUS-WORD reads bits from input dataset. Do not assume zero on read—validate before testing bits on new file formats. FLDCHK debug helps catch length errors that misalign STATUS-WORD relative to COUNT quantitative field following it.

Common Bit Field Mistakes

  1. Quantitative B 2 0 for pure flags—sign bit conflicts with flag bit 15.
  2. Wrong mask width on four-byte status doubleword.
  3. Bit numbering off-by-one between documentation and code.
  4. Testing bits without AND isolation—comparing whole field to 1.
  5. DISPLAY decimal expecting readable flag names.

Explain It Like I'm Five

A bit field is a row of light switches in one small box. Each switch is on or off. Masks are instructions saying flip only the third switch or turn off the first switch. You cannot see switch labels in normal numbers—you need hex goggles (DISPLAY HEX) to see which lights are on.

Exercises

  1. Define two-byte non-quantitative B flags with VALUE X'0000'.
  2. Write OR to set bit 2 using mask from table.
  3. Write AND to clear bit 2.
  4. Explain why B 2 0 is wrong for sixteen independent flags.
  5. Describe when A 1 Y/N beats bit packing for a new in-house flag.

Quiz

Test Your Knowledge

1. Bit flags in Easytrieve typically use type B without:

  • Decimal positions (non-quantitative)
  • Any length limit
  • Field name
  • FILE statement

2. To clear bit 0 of a two-byte field you might AND with:

  • X'FFFE'
  • X'0001'
  • X'FFFF'
  • X'00'

3. Quantitative B with B 2 0 differs from non-quantitative B 2 because:

  • High-order bit is sign bit not a flag bit
  • Length changes
  • Type letter changes
  • Cannot assign

4. OR X'0001' on a flag halfword:

  • Sets bit 0 on
  • Clears all bits
  • Divides the field
  • Ends the job

5. Best debug view for bit fields is:

  • DISPLAY with MASK HEX
  • TITLE only
  • JCL SYSOUT class
  • Comments
Published
Read time13 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve 11.6 non-quantitative B AND OR XOR bit masksSources: Broadcom Easytrieve 11.6 DEFINE Statement, Assignments and Moves, Binary type pageApplies to: Easytrieve bit flags and binary status words