How To Split EDI Files

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!

Introduction

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

How to split a file

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 sample file looks like this:

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

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

Results

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

MySplitFile1.txt

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.txt

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.txt

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.txt

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.

Conclusion

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.

[divider]

Take Charge Of EDI

RDPCrystal EDI Library

trial2