Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
'This is just an example program to show how to generate an EDI X12 204 file
'using the 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 sSefFile As String
Dim sEdiFile As String
Dim sPath As String
sPath = AppDomain.CurrentDomain.BaseDirectory & "\"
sEdiFile = "204Output.X12"
sSefFile = "204_4010.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 = "~"
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) = "009988777 " 'Interchange Sender ID
oSegment.DataElementValue(7) = "02" 'Interchange ID Qualifier
oSegment.DataElementValue(8) = "PRTA " 'Interchange Receiver ID
oSegment.DataElementValue(9) = "040309" 'Interchange Date
oSegment.DataElementValue(10) = "0009" 'Interchange Time
oSegment.DataElementValue(11) = "U" 'Interchange Control Standards Identifier
oSegment.DataElementValue(12) = "00401" 'Interchange Control Version Number
oSegment.DataElementValue(13) = "000018053" '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) = "SM" 'Functional Identifier Code
oSegment.DataElementValue(2) = "009988777" 'Application Sender's Code
oSegment.DataElementValue(3) = "PRTA" 'Application Receiver's Code
oSegment.DataElementValue(4) = "20040312" 'Date
oSegment.DataElementValue(5) = "0009" 'Time
oSegment.DataElementValue(6) = "2" '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("204"))
ediDataSegment.Set(oSegment, oTransactionset.GetDataSegmentHeader)
oSegment.DataElementValue(1) = "204" 'Transaction Set Identifier Code
oSegment.DataElementValue(2) = "000182983" 'Transaction Set Control Number
'B2 - BEGINNING SEGMENT FOR SHIPMENT INFORMATION TRANSACTION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("B2"))
oSegment.DataElementValue(2) = "PRTA" 'Standard Carrier Alpha Code
oSegment.DataElementValue(4) = "05100" 'Shipment Identification Number
oSegment.DataElementValue(6) = "PP" 'Shipment Method of Payment
oSegment.DataElementValue(7) = "B" 'Shipment Qualifier
'B2A - SET PURPOSE
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("B2A"))
oSegment.DataElementValue(1) = "00" 'Transaction Set Purpose Code
oSegment.DataElementValue(2) = "MF" 'Application Type
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("L11"))
oSegment.DataElementValue(1) = "999964092847000001" 'Reference Identification
oSegment.DataElementValue(2) = "CO" 'Reference Identification Qualifier
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("L11(2)")) 'CREATE SECOND INSTANCE OF L11 SEGMENT
oSegment.DataElementValue(1) = "5551007604" 'Reference Identification
oSegment.DataElementValue(2) = "14" 'Reference Identification Qualifier
'N7 - EQUIPMENT DETAILS
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("N7\N7")) 'CREATE N7 SEGMENT IN LOOP N7
oSegment.DataElementValue(2) = "EQPMNT500" 'Equipment Number
'S5 - STOP OFF DETAILS
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\S5")) 'CREATE S5 SEGMENT IN LOOP S5
oSegment.DataElementValue(1) = "1" 'Stop Sequence Number
oSegment.DataElementValue(2) = "LD" 'Stop Reason Code
oSegment.DataElementValue(3) = "49" 'Weight
oSegment.DataElementValue(4) = "L" 'Weight Unit Code
oSegment.DataElementValue(5) = "1" 'Number of Units Shipped
oSegment.DataElementValue(6) = "PC" 'Unit or Basis for Measurement Code
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\L11")) 'CREATE L11 SEGMENT IN LOOP S5
oSegment.DataElementValue(1) = "20" 'Reference Identification
oSegment.DataElementValue(2) = "RU" 'Reference Identification Qualifier
'G62 - DATE/TIME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\G62")) 'CREATE G62 SEGMENT IN LOOP S5
oSegment.DataElementValue(1) = "78" 'Date Qualifier
oSegment.DataElementValue(2) = "20040312" 'Date
'N1 - NAME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\N1\N1")) 'CREATE N1 SEGMENT IN LOOP N1 NESTED IN LOOP S5
oSegment.DataElementValue(1) = "SF" 'Entity Identifier Code
oSegment.DataElementValue(2) = "Los Angeles XYZ" 'Name
oSegment.DataElementValue(3) = "93" 'Identification Code Qualifier
oSegment.DataElementValue(4) = "805" 'Identification Code
'N3 - ADDRESS INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\N1\N3")) 'CREATE N3 SEGMENT IN LOOP N1 LOOP S5
oSegment.DataElementValue(1) = "19499 Downtown Highway" 'Address Information
oSegment.DataElementValue(2) = "Los Angeles, CA 97230" 'Address Information
'N3 - ADDRESS INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\N1\N3(2)")) 'CREATE SECOND INSTANCE OF N3 SEGMENT IN LOOP N1 NESTED IN LOOP S5
oSegment.DataElementValue(1) = "Los Angeles CA,97230" 'Address Information
'N4 - GEOGRAPHIC LOCATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\N1\N4"))
oSegment.DataElementValue(1) = "Los Angeles" 'City Name
oSegment.DataElementValue(2) = "CA" 'State or Province Code
oSegment.DataElementValue(3) = "97230" 'Postal Code
'G61 - CONTACT
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\N1\G61"))
oSegment.DataElementValue(1) = "IC" 'Contact Function Code
oSegment.DataElementValue(2) = "Retail Company A" 'Name
'OID - ORDER IDENTIFICATION DETAIL
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\OID\OID"))
oSegment.DataElementValue(1) = "334455" 'Reference Identification
oSegment.DataElementValue(2) = "ABCDEF092847000001" 'Purchase Order Number
oSegment.DataElementValue(4) = "PC" 'Unit or Basis for Measurement Code
oSegment.DataElementValue(5) = "1" 'Quantity
oSegment.DataElementValue(6) = "L" 'Weight Unit Code
oSegment.DataElementValue(7) = "49" 'Weight
'LAD - LADING DETAIL
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5\OID\LAD"))
oSegment.DataElementValue(1) = "CTN" 'Packaging Form Code
oSegment.DataElementValue(2) = "1" 'Lading Quantity
oSegment.DataElementValue(3) = "L" 'Weight Unit Code
oSegment.DataElementValue(4) = "49" 'Unit Weight
oSegment.DataElementValue(7) = "UF" 'Product/Service ID Qualifier
oSegment.DataElementValue(8) = "UDFCI0002078$01" 'Product/Service ID
oSegment.DataElementValue(13) = "TEST PRODUCT 1 32OZ." 'Lading Description
'S5 - STOP OFF DETAILS
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\S5")) 'CREATE S5 SEGMENT IN SECOND INSTANCE OF LOOP S5
oSegment.DataElementValue(1) = "2" 'Stop Sequence Number
oSegment.DataElementValue(2) = "UL" 'Stop Reason Code
oSegment.DataElementValue(3) = "49" 'Weight
oSegment.DataElementValue(4) = "L" 'Weight Unit Code
oSegment.DataElementValue(5) = "1" 'Number of Units Shipped
oSegment.DataElementValue(6) = "PC" 'Unit or Basis for Measurement Code
'L11 - BUSINESS INSTRUCTIONS AND REFERENCE NUMBER
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\L11"))
oSegment.DataElementValue(1) = "20" 'Reference Identification
oSegment.DataElementValue(2) = "RU" 'Reference Identification Qualifier
'G62 - DATE/TIME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\G62"))
oSegment.DataElementValue(1) = "78" 'Date Qualifier
oSegment.DataElementValue(2) = "20040312" 'Date
'N1 - NAME
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\N1\N1"))
oSegment.DataElementValue(1) = "CN" 'Entity Identifier Code
oSegment.DataElementValue(2) = "RESP RELIABLE" 'Name
oSegment.DataElementValue(3) = "93" 'Identification Code Qualifier
oSegment.DataElementValue(4) = "3807" 'Identification Code
'N3 - ADDRESS INFORMATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\N1\N3"))
oSegment.DataElementValue(1) = "888 MID WAY" 'Address Information
oSegment.DataElementValue(2) = "FLOOR B" 'Address Information
'N4 - GEOGRAPHIC LOCATION
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\N1\N4"))
oSegment.DataElementValue(1) = "Los Angeles" 'City Name
oSegment.DataElementValue(2) = "CA" 'State or Province Code
oSegment.DataElementValue(3) = "97232" 'Postal Code
'G61 - CONTACT
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("S5(2)\N1\G61"))
oSegment.DataElementValue(1) = "IC" 'Contact Function Code
oSegment.DataElementValue(2) = "OVERSEE SUPER" 'Name
oSegment.DataElementValue(3) = "TE" 'Communication Number Qualifier
oSegment.DataElementValue(4) = "(555) 555-ABCD" 'Communication Number
'L3 - TOTAL WEIGHT AND CHARGES
ediDataSegment.Set(oSegment, oTransactionset.CreateDataSegment("L3"))
oSegment.DataElementValue(1) = "49" 'Weight
oSegment.DataElementValue(2) = "G" 'Weight Qualifier
oSegment.DataElementValue(11) = "1" 'Lading Quantity
'TRAILING SEGMENTS ARE AUTOMATICALLY CREATED
'DISPLAY EDI STRING
MessageBox.Show(oEdiDoc.GetEdiString, "EDI File")
'THE EDIDOC OBJECT INTO AN EDI FILE.
oEdiDoc.Save(sPath & sEdiFile)
MessageBox.Show("Done. Output = " & sPath & sEdiFile)
'DESTROYS OBJECTS
oSegment.Dispose()
oTransactionset.Dispose()
oGroup.Dispose()
oInterchange.Dispose()
oSchema.Dispose()
oSchemas.Dispose()
oEdiDoc.Dispose()
End Sub