Skip to content

Read an EDI interchange file

EdiManager.File().Path(p).Read() is the sanctioned entry point for reading an ASC X12 interchange file. It loads the physical file, delegates lexical parsing to EdiSegmentParser (Parse EDI text into segments and elements), and triggers envelope grouping (Build the X12 envelope hierarchy).

Field Value
Operation ID OP-05
Trigger Caller request.
Inputs File path.
Outputs Populated EdiFile with segments and functional-group hierarchy.
Primary components EdiManager.File(), EdiFileBuilder.Path, EdiFileBuilder.Read(), EdiFileReader.Read()
Entry point Common\SAIF.Common.Files\Edi\EdiManager.cs, Common\SAIF.Common.Files\Edi\Core\Builders\EdiFileBuilder.cs, Common\SAIF.Common.Files\Edi\Core\Readers\EdiFileReader.cs

Steps

  1. EdiManager.File() returns a new EdiFileBuilder; Path(path) stores the path and returns this (fluent).
  2. Read() constructs EdiFileReader { Path = path } and calls Read().
  3. Create EdiFile, set FileName from new FileInfo(Path).Name.
  4. File.ReadAllLines(Path), then trim and concatenate every line into one continuous string — line breaks in the physical file are not significant (BR-017).
  5. new EdiSegmentParser().Parse(fileData) — see Parse EDI text into segments and elements.

    Origin: Step 5 delegates lexical parsing to EdiSegmentParser.Parse, documented fully in Parse EDI text into segments and elements.

  6. file.SetSegments(segments) stores the segments and calls RefreshGroupings() (BR-029, BR-030) — see Build the X12 envelope hierarchy.
  7. EdiGroupParser.CreateFunctionalGroups(file) is called again explicitly — redundant with step 6's conditional call.*

Process flow

flowchart TD
    Start(["Caller: EdiManager.File().Path(p).Read()"]) --> Read[EdiFileReader.Read]
    Read --> Concat["File.ReadAllLines +<br>trim/concatenate lines"]
    Concat --> Parse["EdiSegmentParser.Parse(fileData)"]
    Parse --> Set["EdiFile.SetSegments"]
    Set --> Refresh["EdiFile.RefreshGroupings"]
    Refresh --> Complete{"ISA, IEA, GS, GE all present?"}
    Complete -->|Yes| Groups["EdiGroupParser.CreateFunctionalGroups"]
    Complete -->|No| Skip[No functional-group tree built]
    Groups --> EndOk([Populated EdiFile returned])
    Skip --> EndOk

Failure and edge-case behavior

  • Physical line wrapping has no semantic effect — a file wrapped at 80 characters and the same file on one line parse identically (BR-017).
  • If any of ISA, IEA, GS, GE is missing, EdiFile.FunctionalGroups is left unbuilt rather than raising an error (BR-030).

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • Common\SAIF.Common.Files\Edi\EdiManager.cs
  • Common\SAIF.Common.Files\Edi\Core\Builders\EdiFileBuilder.cs
  • Common\SAIF.Common.Files\Edi\Core\Readers\EdiFileReader.cs
  • Common\SAIF.Common.Files\Edi\EdiFile.cs