If you work in corporate treasury, ERP integration (NetSuite, SAP, Oracle), or accounting automation, you will eventually receive a raw .bai or .bai2 file from Chase, Wells Fargo, Bank of America, or Citi—and be asked to turn it into a clean CSV or Excel spreadsheet.
At first glance, ANSI X9.43 BAI2 looks like a simple comma-delimited text file. In reality, naive line.split(",") scripts silently corrupt real-world corporate bank files in four classic ways.
Here is a practical breakdown of the BAI2 record hierarchy, the exact edge cases that break quick parsers, and how to validate control totals properly.
1. The BAI2 Record Hierarchy
Every valid BAI2 file is a strict tree of numeric record codes:
| Record Code | Name | Role |
|---|---|---|
01 | File Header | Sender/receiver IDs and file creation timestamp |
02 | Group Header | Originator, As-Of-Date, and default currency code |
03 | Account Identifier | Bank account number, currency, and summary balances (010 Opening, 015 Closing, 100 Total Credits, 400 Total Debits) |
16 | Transaction Detail | Individual cash movement (type code, amount, funds type, bank ref, customer ref, remittance text) |
88 | Continuation | Appends extra fields or multi-line wire remittance text to the preceding 03 or 16 record |
49 | Account Trailer | Control total sum and record count for the current account |
98 / 99 | Group / File Trailer | Roll-up control sums across the group and entire file |
2. The 4 Edge Cases That Break Naive Parsers
Edge Case A: Funds Type Variable Column Offsets (S, V, D)
In a 16 transaction detail record, field 4 is the Funds Type. Depending on that single letter, the number of columns before Bank Reference changes dynamically:
-
0,1,2,Z→ 0 extra fields after Funds Type. -
V(Value Dated) → 2 extra fields (date,time). -
S(Distributed Availability) → 3 extra fields (immediate,1-day,2+ dayamounts). -
D(Distributed Availability with countN) → 1 + 2N extra fields.
If your parser assumes Bank Reference is always at index 4, every wire with Funds Type S or V shifts the columns and corrupts the reference and description fields.
Edge Case B: 88 Continuation Lines Containing Slashes (/)
BAI2 uses / as a record terminator—except inside free-form 88 remittance descriptions, where wire memos routinely include dates like INV 10/24/2026 or REF 04/12. Splitting blindly on / truncates wire narratives mid-sentence.
Edge Case C: Implied Currency Decimals (USD vs. JPY vs. KWD)
BAI2 stores amounts as raw integers with no decimal point:
-
12500inUSD/EUR/GBP(2 decimals) =125.00 -
12500inJPY/KRW(0 decimals) =12500 -
12500inBHD/KWD(3 decimals) =12.500
Always scale using integer/string decimal shifting rather than floating-point division to avoid IEEE-754 rounding drift.
Edge Case D: Checking Both Record 49 and Balance Equations
A trustworthy converter should verify two independent math checks before you trust the CSV:
- Account Balance Formula:
Opening Ledger (010) + Total Credits (100) - Total Debits (400) == Closing Ledger (015). - Account Trailer (
49): Sum of all summary and16transaction amounts plus exact physical record count (including88lines).
3. Open Reference Guide & Local-Browser Converter
Because corporate bank cash files are highly sensitive, uploading .bai statements to unknown cloud servers is a non-starter for most finance teams.
I put together two free resources to make working with BAI2 faster and safer:
- GitHub Spec & Sample Repo: bai2-format-spec-guide — quick reference for record codes
01–99,Funds Typecolumn offsets, and edge-case test fixtures. - 100% Client-Side Browser Converter: BAI2CSV.com — parses
.bai/.bai2and European SWIFT MT940 files completely locally in JavaScript (zero file uploads, zero login), validates49control totals, includes a searchable 157-code BAI2 Type Code directory, and exports clean CSV/Excel/QBO tables.
If you ever need to handle both raw corporate .bai files and legacy PDF bank statements in the same close workflow, OFXReady covers the PDF-to-QBO side as well.
