How To Split EDI Files With .Net

But John, my EDI file is perfect!  It has the proper Interchange Header, Functional Group and Transaction Header.  My ISA segment length is exactly 106 characters!  You can’t touch it.  If you split it, it’s like splitting part of me!

X12 EDI files are split into smaller ones for many reasons.  For example,

  1. The EDI file is too large
  2. We want the same number of Interchanges, Functional Groups or Transaction Headers in each file
  3. Smaller files are more manageable and can be processed in parallel
  4. If we receive EDI files with multiple Interchanges and we want to place each Interchange in a different file

EDIFileSplitterFlow

We are going to take a simple EDI file with 4 Transaction Headers (ST segment) and convert it to 4 files with 1 Transaction Header each.  Our original file looks like this:

 

Original File

ISA*00*……….*01*SECRET….*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID…*030101*1253*^*00501*000000905*1*T*:~
GS*RA*SENDER CODE*RECEIVER CODE*19991231*0802*2*X*005010X218~
ST*820*0001*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0001~
ST*820*0002*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0002~
ST*820*0003*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0003~
ST*820*0004*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0004~
GE*2*2~
IEA*2*000000905~

Some segments are left out for brevity.  Using the EDIFileSplitter component from RDPCrystal EDI Library we will split the file using the following code

The code

EDIFileSplitter ediFileSplitter = new EDIFileSplitter();ediFileSplitter.EDIFileType = FileType.X12;
ediFileSplitter.FileSplitLevel = FileSplitLevel.HEADER;
ediFileSplitter.NumberOfItemsPerFile = 1;
ediFileSplitter.OutputFilename = “MySplitFile”;
ediFileSplitter.Split(“myFile.txt”, Directory.GetCurrentDirectory());

After running the code above we now have 4 EDI files.

MySplitFile1

ISA*00*..........*01*SECRET....*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID...*030101*1253*^*00501*000000905*1*T*:~
GS*RA*SENDER CODE*RECEIVER CODE*19991231*0802*2*X*005010X218~
ST*820*0001*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0001~
GE*1*2~
IEA*1*000000905~

MySplitFile2

ISA*00*..........*01*SECRET....*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID...*030101*1253*^*00501*000000905*1*T*:~
GS*RA*SENDER CODE*RECEIVER CODE*19991231*0802*2*X*005010X218~
ST*820*0002*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0002~
GE*1*2~
IEA*1*000000905~

MySplitFile3

ISA*00*..........*01*SECRET....*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID...*030101*1253*^*00501*000000905*1*T*:~
GS*RA*SENDER CODE*RECEIVER CODE*19991231*0802*2*X*005010X218~
ST*820*0003*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0003~
GE*1*2~
IEA*1*000000905~

MySplitFile4

ISA*00*..........*01*SECRET....*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID...*030101*1253*^*00501*000000905*1*T*:~
GS*RA*SENDER CODE*RECEIVER CODE*19991231*0802*2*X*005010X218~
ST*820*0004*005010X218~
BPR*C*255*C*ACH*CTX*01*999999992*DA*12345678*1345678901**01*199999999*DA*98765*20071103~
SE*21*0004~
GE*1*2~
IEA*1*000000905~

Notice that the Transaction Set Control Numbers (ST02, SE02) are preserved correctly.  Also notice the the Group Control Number (GS06, GE02) and GE transactions counts (GE01) are correct.

So there you have it folks.  A simple tutorial on how to split an EDI file by Transaction Header.  RDPCrystal EDI Library also allows you to split files by Functional Groups and Interchange Headers as well.  You can even format the output filenames.

 

Take Charge Of EDI

RDPCrystal EDI Library

trial2