{
  "slug": "se01-segment-count-mismatch",
  "title": "SE01 segment count does not match: what the receiver is counting",
  "description": "A rejection for SE01 almost always means the sender counted differently from the spec. The rule is narrower than it looks.",
  "keywords": [
    "se01",
    "segment count",
    "edi 997 ak5 4",
    "x12 se segment",
    "transaction set trailer"
  ],
  "cause": [
    "SE01 must count every segment from ST through SE inclusive — which includes both ST and SE themselves.",
    "The usual mistakes are counting only the segments between them, forgetting that SE counts itself, or counting the envelope segments (ISA, GS, GE, IEA) that belong to the interchange rather than the transaction set.",
    "A 997 reports this as AK5 error code 4. That code means nothing without a table, so the sender often re-sends the same file with the same count."
  ],
  "example": {
    "label": "A transaction set claiming 99 segments when it has 3",
    "curl": "curl -sX POST https://fluentedi.com/v1/edi/validate -H 'content-type: application/json' \\\n  -d '{\"input\":\"ST*850*0001~BEG*00*SA*1**20260824~SE*99*0001~\"}'",
    "output": "\"errors\": [\n  {\n    \"segment\": \"SE01\",\n    \"check\": \"count\",\n    \"message\": \"SE01 must count every segment from ST through SE inclusive.\",\n    \"expected\": 3,\n    \"actual\": 99\n  }\n]"
  },
  "fix": [
    "Count ST, every segment in between, and SE. Nothing outside that range.",
    "Do not maintain the count by hand. Anything that generates the document should compute SE01, CTT01, GE01 and IEA01 from the segments it actually emitted.",
    "If you received a 997 rather than a description, decode it — AK5 code 4 is this error, and the acknowledgment also says which control number it applies to."
  ],
  "tools": [
    "https://fluentedi.com/v1/edi/validate",
    "https://fluentedi.com/v1/edi/acknowledge",
    "https://fluentedi.com/v1/edi/build"
  ]
}