Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
'This is just an example program to demonstrate how to generate an EDI X12 214 file using Framework EDI component in VB.NET
Dim oEdiDoc As ediDocument
Dim oSchema As ediSchema
Dim oSchemas As ediSchemas
Dim oInterchange As ediInterchange
Dim oGroup As ediGroup
Dim oTransactionset As ediTransactionSet
Dim oSegment As ediDataSegment
Dim sPath As String
Dim sEdiFile As String
Dim sSefFile As String
btnGenerate.Enabled = False
sPath = AppDomain.CurrentDomain.BaseDirectory
sEdiFile = "214Output.X12"
sSefFile = "214_004010.SEF"
'CREATES EDI DOCUMENT OBJECT
ediDocument.Set(oEdiDoc, New ediDocument)
'THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES
'NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO GENERATE THE EDI FILE.
ediSchemas.Set(oSchemas, oEdiDoc.GetSchemas)
oSchemas.EnableStandardReference = False
'ENABLES FORWARD WRITE, AND INCREASES BUFFER I/O TO IMPROVE PERFORMANCE
oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite
oEdiDoc.Property(DocumentPropertyIDConstants.Property_DocumentBufferIO) = 200
'SET TERMINATORS
oEdiDoc.SegmentTerminator = "~{13:10}"
oEdiDoc.ElementTerminator = "*"
oEdiDoc.CompositeTerminator = ">"
'LOADS THE SEF FILE
ediSchema.Set(oSchema, oEdiDoc.ImportSchema(sPath & sSefFile, 0))
'CREATES THE ISA SEGMENT
ediInterchange.Set(oInterchange, oEdiDoc.CreateInterchange("X", "004010"))
ediDataSegment.Set(oSegment, oInterchange.GetDataSegmentHeader)
oSegment.DataElementValue(1) = "00" 'Authorization Information Qualifier
oSegment.DataElementValue(2) = " " 'Authorization Information
oSegment.DataElementValue(3) = "00" 'Security Information Qualifier
oSegment.DataElementValue(4) = " " 'Security Information
oSegment.DataElementValue(5) = "01" 'Interchange ID Qualifier
oSegment.DataElementValue(6) = "001325851 " 'Interchange Sender ID
oSegment.DataElementValue(7) = "01" 'Interchange ID Qualifier
oSegment.DataElementValue(8) = "050357789M " 'Interchange Receiver ID
oSegment.DataElementValue(9) = "000110" 'Interchange Date
oSegment.DataElementValue(10) = "1425" 'Interchange Time
oSegment.DataElementValue(11) = "U" 'Interchange Control Standards Identifier
oSegment.DataElementValue(12) = "00401" 'Interchange Control Version Number
oSegment.DataElementValue(13) = "000000035" 'Interchange Control Number
oSegment.DataElementValue(14) = "0" 'Acknowledgment Requested
oSegment.DataElementValue(15) = "P" 'Usage Indicator
oSegment.DataElementValue(16) = ">" 'Component Element Separator
'CREATES THE GS SEGMENT
ediGroup.Set(oGroup, oInterchange.CreateGroup("004010"))
ediDataSegment.Set(oSegment, oGroup.GetDataSegmentHeader)
oSegment.DataElementValue(1) = "QM" 'Functional Identifier Code
oSegment.DataElementValue(2) = "001325851" 'Application Sender's Code
oSegment.DataElementValue(3) = "050357789M" 'Application Receiver's Code
oSegment.DataElementValue(4) = "20000110" 'Date
oSegment.DataElementValue(5) = "1425" 'Time
oSegment.DataElementValue(6) = "767" 'Group Control Number
oSegment.DataElementValue(7) = "X" 'Responsible Agency Code
oSegment.DataElementValue(8) = "004010" 'Version / Release / Industry Identifier Code
'CREATES THE ST SEGMENT
ediTransactionSet.Set(oTransactionset, oGroup.CreateTransactionSet("214"))
ediDataSegment.Set(oSegment, oTransactionset.GetDataSegmentHeader)
oSegment.DataElementValue(1) = "214" 'Transaction Set Identifier Code
oSegment.DataElementValue(2) = "000077" 'Transaction Set Control Number
'B10 - BEGINNING SEGMENT FOR TRANSPORTATION CARRIER SHIPMENT STATUS ME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("B10"))
oSegment.DataElementValue(1) = "R6514545NA" 'Reference Identification
oSegment.DataElementValue(2) = "00000064631M" 'Shipment Identification Number
oSegment.DataElementValue(3) = "SCAC" 'Standard Carrier Alpha Code
'N1 - NAME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N1"))
oSegment.DataElementValue(1) = "SF" 'Entity Identifier Code
oSegment.DataElementValue(2) = "ABC SHIPFROM Company" 'Name
'N2 - ADDITIONAL NAME INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N2"))
oSegment.DataElementValue(1) = "AKA SHIPFROM Mfg" 'Name
'N3 - ADDRESS INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N3"))
oSegment.DataElementValue(1) = "800 Shipfrom Street" 'Address Information
'N4 - GEOGRAPHIC LOCATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N4"))
oSegment.DataElementValue(1) = "FromCity" 'City Name
oSegment.DataElementValue(2) = "MN" 'State or Province Code
oSegment.DataElementValue(3) = "555500000" 'Postal Code
'N1 - NAME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N1"))
oSegment.DataElementValue(1) = "ST" 'Entity Identifier Code
oSegment.DataElementValue(2) = "DEF SHIPTO Company" 'Name
'N2 - ADDITIONAL NAME INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N2"))
oSegment.DataElementValue(1) = "AKA SHIPTO Mfg" 'Name
'N3 - ADDRESS INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N3"))
oSegment.DataElementValue(1) = "222 Shipto Drive" 'Address Information
'N4 - GEOGRAPHIC LOCATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N4"))
oSegment.DataElementValue(1) = "ToTown" 'City Name
oSegment.DataElementValue(2) = "CA" 'State or Province Code
oSegment.DataElementValue(3) = "999900000" 'Postal Code
'LX - ASSIGNED NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\LX"))
oSegment.DataElementValue(1) = "1" 'Assigned Number
'AT7 - SHIPMENT STATUS DETAILS
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\AT7\AT7"))
oSegment.DataElementValue(1) = "AF" 'Shipment Status Code
oSegment.DataElementValue(2) = "NS" 'Shipment Status or Appointment Reason Code
oSegment.DataElementValue(5) = "20060519" 'Date
oSegment.DataElementValue(6) = "1341" 'Time
oSegment.DataElementValue(7) = "LT" 'Time Code
'MS1 - EQUIPMENT, SHIPMENT, OR REAL PROPERTY LOCATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\AT7\MS1"))
oSegment.DataElementValue(1) = "ToonCity" 'City Name
oSegment.DataElementValue(2) = "CA" 'State or Province Code
'MS2 - EQUIPMENT OR CONTAINER OWNER AND TYPE
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\AT7\MS2"))
oSegment.DataElementValue(1) = "SCAC" 'Standard Carrier Alpha Code
oSegment.DataElementValue(2) = "0067291" 'Equipment Number
oSegment.DataElementValue(3) = "TF" 'Equipment Description Code
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\L11"))
oSegment.DataElementValue(1) = "14781-55060" 'Reference Identification
oSegment.DataElementValue(2) = "SI" 'Reference Identification Qualifier
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\L11(2)"))
oSegment.DataElementValue(1) = "1" 'Reference Identification
oSegment.DataElementValue(2) = "QN" 'Reference Identification Qualifier
'AT8 - SHIPMENT WEIGHT, PACKAGING AND QUANTITY DATA
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\AT8"))
oSegment.DataElementValue(1) = "G" 'Weight Qualifier
oSegment.DataElementValue(2) = "L" 'Weight Unit Code
oSegment.DataElementValue(3) = "16880" 'Weight
oSegment.DataElementValue(4) = "640" 'Lading Quantity
oSegment.DataElementValue(5) = "8" 'Lading Quantity
oSegment.DataElementValue(6) = "E" 'Volume Unit Qualifier
oSegment.DataElementValue(7) = "960" 'Volume
'SPO - SHIPMENT PURCHASE ORDER DETAIL
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\SPO\SPO"))
oSegment.DataElementValue(1) = "202831 REPL" 'Purchase Order Number
oSegment.DataElementValue(2) = "1022" 'Reference Identification
oSegment.DataElementValue(3) = "PC" 'Unit or Basis for Measurement Code
oSegment.DataElementValue(4) = "1008" 'Quantity
oSegment.DataElementValue(5) = "L" 'Weight Unit Code
oSegment.DataElementValue(6) = "40320" 'Weight
'LX - ASSIGNED NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\LX"))
oSegment.DataElementValue(1) = "2" 'Assigned Number
'AT7 - SHIPMENT STATUS DETAILS
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\AT7\AT7"))
oSegment.DataElementValue(1) = "AF" 'Shipment Status Code
oSegment.DataElementValue(2) = "NS" 'Shipment Status or Appointment Reason Code
oSegment.DataElementValue(5) = "20081028" 'Date
oSegment.DataElementValue(6) = "1341" 'Time
oSegment.DataElementValue(7) = "LT" 'Time Code
'MS1 - EQUIPMENT, SHIPMENT, OR REAL PROPERTY LOCATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\AT7\MS1"))
oSegment.DataElementValue(1) = "Carson" 'City Name
oSegment.DataElementValue(2) = "CA" 'State or Province Code
'MS2 - EQUIPMENT OR CONTAINER OWNER AND TYPE
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\AT7\MS2"))
oSegment.DataElementValue(1) = "SCAC" 'Standard Carrier Alpha Code
oSegment.DataElementValue(2) = "0067291" 'Equipment Number
oSegment.DataElementValue(3) = "TF" 'Equipment Description Code
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\L11"))
oSegment.DataElementValue(1) = "12345-asdfgh" 'Reference Identification
oSegment.DataElementValue(2) = "SI" 'Reference Identification Qualifier
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\L11(2)"))
oSegment.DataElementValue(1) = "1" 'Reference Identification
oSegment.DataElementValue(2) = "QN" 'Reference Identification Qualifier
'AT8 - SHIPMENT WEIGHT, PACKAGING AND QUANTITY DATA
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\AT8"))
oSegment.DataElementValue(1) = "G" 'Weight Qualifier
oSegment.DataElementValue(2) = "L" 'Weight Unit Code
oSegment.DataElementValue(3) = "7890" 'Weight
oSegment.DataElementValue(4) = "640" 'Lading Quantity
oSegment.DataElementValue(5) = "8" 'Lading Quantity
oSegment.DataElementValue(6) = "E" 'Volume Unit Qualifier
oSegment.DataElementValue(7) = "960" 'Volume
'SPO - SHIPMENT PURCHASE ORDER DETAIL
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\SPO\SPO"))
oSegment.DataElementValue(1) = "202831 REPL" 'Purchase Order Number
oSegment.DataElementValue(2) = "1022" 'Reference Identification
oSegment.DataElementValue(3) = "PC" 'Unit or Basis for Measurement Code
oSegment.DataElementValue(4) = "1008" 'Quantity
oSegment.DataElementValue(5) = "L" 'Weight Unit Code
oSegment.DataElementValue(6) = "40320" 'Weight
'TRAILING SEGMENTS ARE AUTOMATICALLY CREATED
'DISPLAY EDI STRING
MessageBox.Show(oEdiDoc.GetEdiString, "EDI String")
'SAVE EDI DOCUMENT OBJECT INTO AN EDI FILE.
oEdiDoc.Save(sPath & sEdiFile)
MessageBox.Show(sPath & sEdiFile, "EDI Ouput")
'DESTROYS OBJECTS
oSegment.Dispose()
oTransactionset.Dispose()
oGroup.Dispose()
oInterchange.Dispose()
oSchema.Dispose()
oSchemas.Dispose()
oEdiDoc.Dispose()
End Sub