Creating EDI data with TypedDocuments and .Net

In this tutorial we’ll discuss how to create EDI data using  TypedDocuments and C#.Net.  TypedDocuments enable developers to use typed EDI objects to create data.  Instead of having to worry about arrays, indexes and strings we can create EDI data in a higher object oriented fashion.

The Code

Typed5010Document sampleEDIFile = new Typed5010Document(); //Or Typed4010Document
 
// Puts the correct number of segments/headers/transaction in X12 SE, GE, and IEA segments
sampleEDIFile.AutoPlaceCorrectNumOfSegments = true;
sampleEDIFile.AutoPlaceNumOfTransactions = true;
sampleEDIFile.AutoPlaceNumOfFunctionalGroups = true;
sampleEDIFile.PadISAElementValues = true;
 
// Create an interchance loop. This loop will contain all other loops in the EDI structure
DocumentLoop interchangeHeader = sampleEDIFile.MainSection.CreateLoop(“Interchange Header”);
 
// Create an ISA segment in the interchange loop
ISA isa = interchangeHeader.CreateSegment<ISA>();
isa.AuthorizationInformationQualifier = “00”;
isa.AuthorizationInformation = “”;
isa.SecurityInformationQualifier = “00”;
isa.SecurityInformation = “”;
isa.InterchangeIDQualifier1 = “ZZ”;
isa.InterchangeSenderID = “InterchangeSenderID”;
isa.InterchangeIDQualifier2 = “ZZ”;
isa.InterchangeReceiverID = “InterchangeReceiverID”;
isa.InterchangeDate = “150303”;
isa.InterchangeTime = “1804”;
isa.RepetitionSeparator = “^”;
isa.InterchangeControlVersionNumber = “00501”;
isa.InterchangeControlNumber = “1”;
isa.AcknowledgmentRequested = “1”;
isa.InterchangeUsageIndicator = “P”;
isa.ComponentElementSeparator = “:”;
 
// Now create the function header section
DocumentLoop functionalHeader = interchangeHeader.CreateLoop(“Functional Header”);
 
GS gs = functionalHeader.CreateSegment<GS>();
gs.FunctionalIdentifierCode = “HC”;
gs.ApplicationSenderCode = “ApplicationSenderCode”;
gs.ApplicationReceiverCode = “ApplicationReceiverCode”;
gs.Date = “20150303”;
gs.Time = “1424”;
gs.GroupControlNumber = “1234”;
gs.ResponsibleAgencyCode = “X”;
gs.VersionReleaseIndustryIdentifierCode = “005010X222”;
 
// Create a transaction header loop
DocumentLoop transactionHeader = functionalHeader.CreateLoop(“Transaction Header”);
ST st = transactionHeader.CreateSegment<ST>();
st.TransactionSetIdentifierCode = “837”;
st.TransactionSetControlNumber = “1”;
st.ImplementationConventionReference = “005010X222”;
 
// Add an BHT segment to the transaction header loop
BHT bht = transactionHeader.CreateSegment<BHT>();
bht.HierarchicalStructureCode = “0019”;
bht.TransactionSetPurposeCode = “00”;
bht.ReferenceIdentification = “44445”;
bht.Date = “20040213”;
bht.Time = “0345”;
 
// Create the end of the transaction (SE segment). This must be done in a loop.
DocumentLoop endOfTransactionLoop = transactionHeader.CreateLoop(“End Of Transaction”);
SE se = endOfTransactionLoop.CreateSegment<SE>();
se.TransactionSetControlNumber = “1”;
se.NumberOfIncludedSegments = “3”;
 
// Create the end of the functional group (GE segment). This must be done in a loop.
DocumentLoop endOfFunctionalGroupLoop = functionalHeader.CreateLoop(“End Functional Group”);
GE ge = endOfFunctionalGroupLoop.CreateSegment<GE>();
ge.GroupControlNumber = “11234”;
ge.NumberOfTransactionSetsIncluded = “1”;
 
// Finally create the end of the interchange loop (IEA segment). This must be done in a loop.
DocumentLoop endInterchangeSection = interchangeHeader.CreateLoop(“End Interchange”);
IEA iea = endInterchangeSection.CreateSegment<IEA>();
iea.InterchangeControlNumber = “123”;
iea.NumberOfIncludedFunctionalGroups = “1”;
 
// Generate the EDI file
string ediData = sampleEDIFile.ToEDIString(new Delimiters()); 
 

Output

ISA*00* *00* *ZZ*InterchangeSend*ZZ*InterchangeRece*150303*1804*^*00501*1 *1*P*:~GS*HC*ApplicationSenderCode*ApplicationReceiverCode*20150303*1424*1234*X*005010X222~
ST*837*1*005010X222~
BHT*0019*00*44445*20040213*0345~
SE*3*1~
GE*1*11234~
IEA*1*123~

TypedDocuments supports all X12 4010 transactions as well as all X12 5010 HIPAA transactions

Now that was easy!

 

Take Charge Of EDI

RDPCrystal EDI Library

trial2