Thursday, September 7, 2017

Decoding bai file type

This post is all about decoding bai file type. so that any application can be developed convert bai file type to csv or any. csv file is nothing but comma separated values, a simple file format used to store tabular data like spreadsheets. Prior to that, what is bai file type? bai is a file type (.bai extension) used to balance report in banking industry. Technically .bai is just a text file with respective delimiters called codes. Though comma is the column separator, the .bai files are typically formatted in such a way to represent other information using the prefix numeric code with every newline.

The first two digits of each line is the standard code for each line type to tell the system what type of line it is.
------------------------------------------------
01,,,,,,,,
02,,,,1230530,,,
03,80457080,,,,,,
16,475,3000,,1230530,,,456,
88,,
16,475,30000,,1230530,,,789,
98,,,
99,20000,,2
------------------------------------------------
Interpretation
01 File Header Begins File
02 Group Header Begins Group
03 Account Identifier Begins Account
16 Transaction Detail (Optional) Within Account
88 continuation of details
49 Account Trailer Ends Account
98 Group Trailer Ends Group
99 File Trailer Ends File

01
File Header
The file header marks the beginning of a file. It identifies the sender and receiver of the transmission, and it describes the structure of the file.
02
Group Header
The group header identifies a group of accounts that are from the same originator and includes the same as-of-date and as-of-time.
03
Account Identifier and Summary/Status
This record identifies the account number and reports activity summary and account status information. Summary information may be accompanied by an item count and funds availability distribution.
16
Transaction Detail
This record is used for transmission of detail transaction information. Transaction detail may include two reference numbers and a free-form alphanumeric text.
88
Continuation
A Continuation record is used when data exceed the maximum physical record length, or whenever it is desirable to continue data into an additional record. It may follow any record type, including another “continuation” (88) record.
49
Account Trailer
The Account Trailer record provides account control
totals
98
Group Trailer
This record provides group control totals.
99
File Trailer
This record provides file control totals.


File Header
It contains sender, receiver alphanumeric identifiers, File created date in YYMMDD format, File created time, file identification id, number of characters, block size, version number.
Group Header
It contains receiver identifier, originator identifier, status, date, time, currency code.
Account Header
It contains customer account number, currency code, type code, amount, item count, fund type
Transaction Header
It contains Transaction type code, Amount, fund type, bank reference number, customer reference number, Text. Among transaction type code 010 to 099 are reporting purpose. 100 to 399 type codes indicate Credit transaction. 400 to 760 indicate debit transaction.

A bai file should starts with 01 & ends with 99 code. It can have multiple groups starts with 02 & ends with 98 codes. Account details should be inside the group header. 16 indicates all type of Transaction details when the information is large than the continuations will be present with 88 code in next line.