VDA EDI Tools

EDI Segment Terminator: The Apostrophe That Ends Everything

VDA EDI Tools Blog · 2026-11-16

One byte ends every EDIFACT segment, and it is not a newline. It is a single apostrophe. Most of the time nobody thinks about it, which is exactly why it causes so much damage when a file goes weird: the failure mode is silent, the error message points at the wrong segment, and the fix is almost never where the error says it is.

What the terminator actually is

In a default EDIFACT setup the segment terminator is the apostrophe character, hex 27. You will see it at the end of every line in a raw interchange:

UNH+1+DESADV:D:96A:UN'
BGM+351+12345'
DTM+137:20261116:102'

Nothing about this is required. The terminator is configurable, and it is defined in two places: position 6 of the UNA service string advice if one is present, and the syntax defaults otherwise. A UNA:+.? ' line says the apostrophe terminates segments; a different sixth character says something else. If you have not read the UNA line in a while, our UNA/UNB/UNH field guide walks through all six positions.

The terminator is also a real character, which means it can appear inside your data. More on that below, because it is the second most common cause of mystery failures we see.

Checking the bytes

When a file misbehaves, look at it in a hex viewer before trusting any editor display. Editors lie about line endings and invisible characters; hex does not. On Linux or in git-bash, xxd shows you exactly what is between segments:

$ xxd -l 96 sample.edi
00000000: 554e 482b 312b 4445 5341 4456 3a44 3a39  UNH+1+DESADV:D:9
00000010: 3641 3a55 4e27 0d0a 4247 4d2b 3335 312b  6A:UN'..BGM+351+
00000020: 3132 3334 3527 0d0a 4454 4d2b 3133 373a  12345'..DTM+137:

See the 27 0d 0a after UNH? That is terminator, carriage return, line feed. The apostrophe ends the segment, and the CR/LF pair is decorative whitespace that a conforming parser ignores. This pattern, segment data followed by 27 followed by optional CR/LF, is what healthy files look like at the byte level.

Quick counts from a shell tell you a lot too:

$ tr -cd "'" < sample.edi | wc -c     # how many terminators exist
$ xxd sample.edi | grep -c "0d0a"       # how many CRLF pairs exist

If the terminator count is wildly different from the segment count your message claims in UNT, the file is broken somewhere in the middle, not at the segment the parser complained about.

The CRLF problem

CR/LF after a terminator is legal and common, especially in Windows-generated files. Two ways it still bites you:

The rarer and meaner variant: a CR or LF before the terminator, as in QTY+12:100:PCE\r'. Now the carriage return is inside the data element, and a strict partner parser rejects a perfectly reasonable quantity. This typically appears when a mapping tool pads values to a fixed width with trailing spaces that got mangled upstream. The byte-level view shows it immediately; no editor will.

When the terminator lives inside your data

Apostrophes show up in real master data: names like O'BRIEN, addresses, free-text remarks, even article descriptions from a PDM system. If one rides into a field unescaped, the parser sees a segment boundary mid-value:

NAD+SE+12345++O'BRIEN LOGISTICS GmbH'
      segment 1 ^^^^^^^^^^^^^
                          segment 2 starts here: BRIEN LOGISTICS GmbH'

From the parser's view the segment ended at O', and everything after it is garbage that happens to look like segments. Typical downstream errors: "unknown segment BRI", "NAD too short", "UNT segment count mismatch". The error always lands after the real problem.

EDIFACT solves this with the release character, a question mark by default: a terminator preceded by ? is data, not a boundary. So O?'BRIEN LOGISTICS GmbH survives intact. The catch is that both sides must agree on the release character too (that is position 4 of UNA), and the tool that produced the file has to actually do the escaping. Many do not, which is why unescaped apostrophes are a classic reason a file passes your ERP export and fails at the OEM gateway. If you cannot fix the data at the source, and apostrophes genuinely belong in that field, the harder option is renegotiating a separator set where the terminator never appears in your data at all.

How this shows up as a validation error

Segment-count checks catch terminator trouble reliably, just late. UNT declares how many segments the message contains; a parser that split one NAD into three counts differently and the check fails. That is your signal to stop debugging the segment the message named and count the apostrophes instead:

  1. Count 27 bytes in the file. Compare against the claimed segment count.
  2. Walk the file in a hex view around the first place the counts diverge.
  3. Fix the data (escape it, or strip the apostrophe at the source system) rather than patching the file by hand. Hand patches break the UNT count in a new way.

Pre-flight check

None of this needs a gateway to reproduce. Paste the suspect file into the VDA 4987 validator or the VDA 4984 validator and the envelope and count checks run against your real bytes, locally, before anything leaves your machine. Files with genuine part numbers and volumes are exactly the ones you should never upload anywhere, which is why both tools do all their work in the browser.

Try it: Check terminator hygiene and segment counts on a real file without sending it anywhere. Open the tool →

Related reading: UNA, UNB and UNH field by field and envelope errors that break the whole file.

← All articles