EBCDIC to ASCII: what converts, and what breaks
Converting EBCDIC text to ASCII is a byte-for-byte table lookup. Converting a mainframe data file is not, because most of its fields are not text. Here is the table, the code page traps, and the one rule that keeps packed and binary fields intact.
Have the file at hand? Open it in the free EBCDIC viewer online: hex and decoded text side by side, nothing uploaded
The byte table
EBCDIC and ASCII give different bytes to the same characters. The same words, HELLO WORLD, in both:
Text HELLO WORLD EBCDIC 037 C8 C5 D3 D3 D6 40 E6 D6 D9 D3 C4 ASCII 48 45 4C 4C 4F 20 57 4F 52 4C 44
- Digits 0 to 9 are F0 to F9 in EBCDIC, 30 to 39 in ASCII.
- Capital letters come in three runs: A to I are C1 to C9, J to R are D1 to D9, S to Z are E2 to E9.
- A space is 40 in EBCDIC, 20 in ASCII. A blank-padded PIC X(20) field is full of 40 bytes.
- Letters, digits and the space are the same in every EBCDIC code page; punctuation, accents and currency signs are not.
Code pages: 037 is not 1047
There is no single EBCDIC. Each code page maps some bytes to other characters. Reading a file with the wrong one raises no error: every byte is valid, it just shows another character. These bytes, decoded by the extension in four code pages:
Bytes 037 1047 273 297 BA BB [ ] Ý ¨ ¬ | ¬ | AD BD Ý ¨ [ ] Ý ¨ Ý ~ 4A 5A ¢ ! ¢ ! Ä Ü ° § E0 \ \ Ö ç 9F ¤ ¤ ¤ ¤ (1140: €)
- 037: US, Canada and many other English-language sites. 1047: the Latin-1 code page of z/OS UNIX and many C programs; it differs from 037 on a handful of characters, the square brackets among them.
- 273 (Germany, Austria) and 297 (France) put national letters where 037 has symbols such as ¢ and !.
- 1140 to 1149 are the euro versions: 1140 is 037 with € at byte 9F.
- 500 is the international code page: 4A 5A read [ ] there.
In Mainframe File Viewer, the code page is proposed on the first screen and can be changed at any time from the status bar; 15 EBCDIC code pages are available, plus ISO-8859-1 and Windows-1252.
Why a text conversion breaks packed and binary fields
A COBOL record mixes text with numbers stored as raw bytes. A COMP-3 field PIC S9(7)V99 holding -1234.56 is five bytes, 00 01 23 45 6D. A binary PIC S9(4) COMP holding -2 is FF FE. None of these bytes are characters.
A text converter maps every byte through the table anyway. 6D is the EBCDIC underscore, so it becomes 5F; FF and FE have their own mapping, too. The digits of the amount are rewritten and the sign is lost. No later step can undo it, because the converter does not know which bytes were numbers.
The only safe conversion is field by field, with the copybook: text fields through the code page, packed, zoned and binary fields decoded as numbers. That is what the extension does on screen, and what its Pro export writes to CSV or JSON.
FTP: text mode or binary mode
FTP and most transfer tools have two modes. In text (ASCII) mode, the mainframe converts every byte to ASCII and adds a line end after each record. In binary mode, the bytes arrive as they are. A data file with packed or binary fields must be transferred in binary mode.
Mainframe File Viewer checks for this when it opens a file. On a test file transferred in text mode it shows: “This file looks like a text-mode transfer: 4 line ends found and 82% of the bytes are ASCII. Text mode converts every byte and adds line ends, which destroys packed (COMP-3) and binary fields. Transfer the file again in binary mode (FTP: binary).” The file cannot be repaired: ask for it again.
Binary mode also keeps the record structure as it is: an FB file has no line ends at all, and a VB file keeps the 4-byte RDW at the start of each record, which the viewer uses to find the records.
Common mistakes
- Converting the whole file with a text tool: every COMP-3 and binary field is lost.
- Downloading in text mode: same result, plus line ends that shift every record after the first.
- Reading with the wrong code page: no error, but brackets, accents and currency signs are wrong.
- Expecting line ends: an FB file is a stream of records of the same length, cut by the record length, not by lines.
- Forgetting the RDW: in a VB file, the first 4 bytes of each record are its length, not data.
Frequently asked questions
Is EBCDIC to ASCII conversion lossless?
For text fields, yes, as long as the code page is right and every character exists in the target. For packed (COMP-3) and binary fields, no: they are numbers stored as bytes and must be decoded with the copybook, not converted through a table.
Which EBCDIC code page does my file use?
Ask the team that produced it; on z/OS the CCSID of the data set or of the application says it. Otherwise, look at a field that contains brackets, accents or a currency sign and try 037, 1047 and your national code page: the right one shows the expected characters. Digits and capital letters read the same in all of them.
Can I convert an EBCDIC file to CSV?
Yes, with its copybook: each field decoded according to its PIC and USAGE. Mainframe File Viewer Pro exports the whole file, a filter or a selection to CSV or JSON, with decimals and leading zeros kept.
Read your own files the same way
Mainframe File Viewer for VS Code reads your EBCDIC files with their copybook, on your machine, with the hex next to every value. Free, no account; Pro adds several layouts per file, VB and OCCURS DEPENDING ON cut into fields, comparison details and CSV and JSON export.
A format or an in-house rule of your own? We build it in five working days, at a fixed price: EUR 490 + VAT where applicable, per work package. See the work packages