UNA, UNB and UNH: The EDIFACT Envelope, Field by Field
Every EDIFACT parser reads the same three segments before it reads anything else: UNA tells it which characters separate the data, UNB tells it who is talking to whom, and UNH tells it what kind of message follows. Get those three right and the rest is bookkeeping. Get one wrong and no content validation will ever run, because the file is unreadable. Here is each field, in order, with the failure modes that actually appear in production traffic.
UNA: the six characters that define the alphabet
UNA is the service string advice, and it is exactly nine characters long: the letters UNA followed by six separator definitions. A classic one looks like this:
UNA:+.? '
The positions matter more than the characters, because this line is a lookup table the parser applies to every byte that follows:
| Position | Character | Meaning |
|---|---|---|
| 1 | : | Component data element separator (inside composites) |
| 2 | + | Data element separator (between elements in a segment) |
| 3 | . | Decimal notation |
| 4 | ? | Release character (escapes the separators inside data) |
| 5 | (space) | Reserved; from syntax version 4 onwards it is the repetition separator |
| 6 | ' | Segment terminator |
Two things trip people up here. First, UNA is optional. When it is missing, the defaults apply (+ for elements, : for components, ? for release, apostrophe to terminate), which is why files with no UNA line at all still parse fine. Second, once a UNA line exists, it wins. Files exported with a UNA that says : is the component separator but built elsewhere with + in that role split into garbage exactly halfway through the first segment. Our segment terminator article goes deeper on the byte level, including what carriage returns do to naive parsers.
UNB: who sent this, and under which rules
UNB is the interchange header. It carries the syntax version both sides agreed on, both parties' addresses, and the control reference everything else hangs off. A typical automotive interchange opens like this:
UNB+UNOB:4+SENDEROID::OD+RECEIVEROID::OD+20261116:0930+493800001++DESADV'
Field by field:
UNOB:4is composite S001, the syntax identifier.0001names the syntax (UNOBis the standard character-level A syntax;UNOCand friends exist for other code pages) and0002is the syntax version, here 4.SENDEROID::ODis S002, the sender identification (0004) with an optional address qualifier (0007). In German automotive traffic the ID is typically the OFTP2 Odette ID, andODmarks it as such.RECEIVEROID::ODis S003, the recipient, same structure.20261116:0930is S004: the preparation date (0017) and time (0019). Watch the date width: with syntax version 4 the date is CCYYMMDD; older syntax levels used YYMMDD. A two-digit year riding in a level-4 interchange is a classic migration leftover.493800001is element 0020, the interchange control reference. It must be unique from this sender for a meaningful period, because receivers use it for duplicate detection, and UNZ at the end of the file must echo it exactly.- The empty element after it is where S005 (recipient's reference, sometimes a password qualifier in older setups) would sit; in modern automotive traffic it is usually empty.
DESADVis 0026, the application reference. It hints which message family the interchange carries, so a routing engine can hand the file to the right mapping without opening UNH. It is a hint, not a contract.
One more element worth knowing: 0035, the test indicator. When it carries 1, the whole interchange is a test. Files that go live with 0035 set to 1 get accepted in test environments and rejected in production, and the error message rarely says why.
UNH: what message is this, exactly
UNH opens every individual message inside the interchange and answers the question the mapper actually cares about:
UNH+1+DESADV:D:96A:UN'
1is element 0062, the message reference number. It only has to be unique within this interchange, and UNT at the end of the message must repeat it.- The composite is S009, the message identifier.
DESADV(0065) is the message type,D(0052) the version,96A(0054) the release, andUN(0051) the controlling agency. - A fifth position exists: 0057, the association-assigned code. Industry profiles use it to name the sub-profile (an OEM guideline code, for example), so
DESADV:D:96A:UN:XYZcan mean "DESADV, but narrowed down by guideline XYZ". If your mapping ignores 0057 while your partner populates it, you will eventually process a message against the wrong rule set.
The version and release pair is the one that hurts when it is wrong. D:96A is the common baseline for the VDA 49xx automotive profiles; a file that announces D:01B tells the receiver to expect element definitions from a different directory, and field lengths or codes that were fine in 96A suddenly fail schema checks that have nothing to do with your data.
A complete miniature interchange
Put it together and a one-message interchange looks like this:
UNA:+.? '
UNB+UNOB:4+SENDEROID::OD+RECEIVEROID::OD+20261116:0930+493800001++DESADV'
UNH+1+DESADV:D:96A:UN'
BGM+351+12345'
DTM+137:20261116:102'
...
UNT+12+1'
UNZ+1+493800001'
Three numbers must agree or the file dies: UNT's segment count must equal the real number of segments in the message (counting UNH and UNT themselves), UNT's reference must equal UNH's 0062, and UNZ must carry the same interchange count as UNB expects plus the same control reference 0020. Our envelope error article walks through what each of those mismatches looks like when it arrives from a partner.
The three envelope bugs we see most
- UNA disagrees with the file. Exported twice, edited once, concatenated never. The UNA says one alphabet, the body uses another.
- Sender and receiver swapped. In a self-billing setup the OEM is the sender, so UNB's S002 and S003 feel backwards to teams used to outbound files. The message is still correct; the surprise is.
- Control references reused. A counter that resets daily or per file template produces duplicate 0020 values, and the receiver's duplicate filter silently drops real files. Give each interchange a reference that cannot collide.
The envelope rules above are the same ones our validators enforce on every paste. If a partner file fails before it even reaches the content checks, the VDA 4987 validator and the VDA 4984 validator will tell you exactly which of these fields is out of line, in your browser, before your customer's gateway does.
Related reading: EDIFACT basics in 10 minutes and UNB, UNH, UNT, UNZ errors that break the whole file.