How to Read and Fix X12 and EDIFACT EDI Files
Understand X12 and EDIFACT segments, separators and envelopes, read a purchase order line by line and fix segment count and control number errors fast.

If you work with retailers, distributors, carriers or health insurers, you will meet EDI. Purchase orders, invoices, ship notices and acknowledgements travel as compact text files that look like noise at first sight. Once you know how they are built, they are quite readable. This guide explains the structure of X12 and EDIFACT and how to fix the errors partners report most often.
Segments, elements and separators
Both standards use the same idea. A file is a list of segments, each starting with a short id such as BEG or NAD. Segments contain elements, and elements can contain components.
In X12, a typical line is PO1124EA3.75**VP*TEA-250~. The asterisk separates elements, the tilde ends the segment, and an empty element between two asterisks means the value is absent. The separators are defined by the ISA segment itself: it is always 106 characters long, its fourth character is the element separator, and its last two positions hold the component separator and the segment terminator.
In EDIFACT, a line looks like QTY+21:24'. Plus separates elements, colon separates components and the apostrophe ends the segment. An optional UNA segment at the start can change these characters. EDIFACT also has a release character, normally ?, so PO?+1 means the text PO+1.
Envelopes
Messages are wrapped in envelopes with counts and control numbers:
- X12: ISA and IEA around the whole interchange, GS and GE around each functional group, ST and SE around each transaction set such as an 850 purchase order.
- EDIFACT: UNB and UNZ around the interchange, optional UNG and UNE around groups, UNH and UNT around each message such as ORDERS.
The trailers repeat information from the headers. SE01 counts the segments from ST to SE, SE02 repeats the control number in ST02, GE01 counts transaction sets, and IEA01 counts groups. UNT does the same job for EDIFACT messages. When someone edits a file by hand and forgets to update these, the partner's system rejects it.
Reading and fixing a file
The EDI X12 and EDIFACT Viewer and Editor works in the browser.
- Paste the file or open it. The standard and the separators are detected from the file.
- Read the messages list: each transaction set or message with its type, for example 850 Purchase Order or ORDERS, and its control number.
- Browse the segments, one per row, each with its name. Filter by id, such as PO1 or NAD, to jump to line items or parties.
- Tap a segment to edit its elements. Components are shown separately, so composite values are easy to check.
- Look at the checks. Every count and control reference is verified, and each failure has a Fix button. Fix all counts and references corrects them together.
- Export JSON with keys like
BEG03, a CSV of segments, or a clean EDI file with one segment per line.
A typical repair
A buyer asks a supplier to remove one line from purchase order PO-88213. Someone deletes the second PO1 segment and its PID description in a text editor. The file now fails: SE01 still says 13 segments, but ST to SE has 11. The fix button sets it to 11. One thing remains for a person to check: the CTT segment, which holds the number of line items, still says 2. That is business content rather than envelope structure, so the tool leaves it to you.
What a viewer cannot check
Each trading partner publishes an implementation guide that says which segments are mandatory, which codes are allowed and how long each element may be. A syntax viewer does not know those rules. After fixing structure, test the file in your partner's validation portal or translator before sending it to production.
Summary
EDI is segments, elements and components, wrapped in envelopes that count what they contain. Learn the separators, read files segment by segment, keep the counts in step after every edit, and leave business rules to the partner's guide.



