'This is an example program that shows how to translate an EDI X12 204 using the Framework EDI component in VB6 Dim oEdiDoc As Fredi.ediDocument Dim oSchema As Fredi.ediSchema Dim oSchemas As Fredi.ediSchemas Dim oSegment As Fredi.ediDataSegment Dim sSegmentID As String Dim sLoopID As String Dim nArea As Integer Dim sValue As String Dim sQlfr As String Dim sLoopN1Qlfr As String Command1.Enabled = False 'CREATES EDI DOCUMENT OBJECT Set oEdiDoc = New Fredi.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 TRANSLATE THE EDI FILE. Set oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = False 'THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType = Cursor_ForwardOnly 'LOADS THE SEF FILE Set oSchema = oEdiDoc.LoadSchema("204_4010.SEF", 0) 'LOADS THE EDI FILE oEdiDoc.LoadEdi "204.x12" 'GETS THE FIRST DATA SEGMENT IN THE EDI FILE Set oSegment = oEdiDoc.FirstDataSegment 'LOOP THAT WILL TRAVERSE THRU EDI FILE FROM FIRST SEGMENT TO LAST SEGMENT Do While Not oSegment Is Nothing 'DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA '(OR TABLE) NUMBER THAT THEY ARE IN. sSegmentID = oSegment.ID sLoopID = oSegment.LoopSection nArea = oSegment.Area If nArea = 0 Then If sLoopID = "" Then If sSegmentID = "ISA" Then 'ONCE SEGMENT HAS BEEN IDENTIFIED, ITS DATA ELEMENTS ARE READ sValue = oSegment.DataElementValue(1) 'Authorization Information Qualifier sValue = oSegment.DataElementValue(2) 'Authorization Information sValue = oSegment.DataElementValue(3) 'Security Information Qualifier sValue = oSegment.DataElementValue(4) 'Security Information List1.AddItem oSegment.DataElement(5).Description & " = " & oSegment.DataElementValue(5) 'Interchange ID Qualifier List1.AddItem oSegment.DataElement(6).Description & " = " & oSegment.DataElementValue(6) 'Interchange Sender ID sValue = oSegment.DataElementValue(7) 'Interchange ID Qualifier sValue = oSegment.DataElementValue(8) 'Interchange Receiver ID sValue = oSegment.DataElementValue(9) 'Interchange Date sValue = oSegment.DataElementValue(10) 'Interchange Time sValue = oSegment.DataElementValue(11) 'Interchange Control Standards Identifier List1.AddItem oSegment.DataElement(12).Description & " = " & oSegment.DataElementValue(12) 'Interchange Control Version Number List1.AddItem oSegment.DataElement(13).Description & " = " & oSegment.DataElementValue(13) 'Interchange Control Number sValue = oSegment.DataElementValue(14) 'Acknowledgment Requested sValue = oSegment.DataElementValue(15) 'Usage Indicator sValue = oSegment.DataElementValue(16) 'Component Element Separator ElseIf sSegmentID = "GS" Then sValue = oSegment.DataElementValue(1) 'Functional Identifier Code sValue = oSegment.DataElementValue(2) 'Application Sender's Code sValue = oSegment.DataElementValue(3) 'Application Receiver's Code sValue = oSegment.DataElementValue(4) 'Date sValue = oSegment.DataElementValue(5) 'Time List1.AddItem oSegment.DataElement(6).Description & " = " & oSegment.DataElementValue(6) 'Group Control Number sValue = oSegment.DataElementValue(7) 'Responsible Agency Code sValue = oSegment.DataElementValue(8) 'Version / Release / Industry Identifier Code End If 'sSegmentID End If 'sLoopID ElseIf nArea = 1 Then If sLoopID = "" Then If sSegmentID = "ST" Then sValue = oSegment.DataElementValue(1) 'Transaction Set Identifier Code List1.AddItem oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2) 'Transaction Set Control Number ElseIf sSegmentID = "B2" Then sValue = oSegment.DataElementValue(1) 'Tariff Service Code sValue = oSegment.DataElementValue(2) 'Standard Carrier Alpha Code sValue = oSegment.DataElementValue(3) 'Standard Point Location Code List1.AddItem oSegment.DataElement(4).Description & " = " & oSegment.DataElementValue(4) 'Shipment Identification Number sValue = oSegment.DataElementValue(5) 'Weight Unit Code sValue = oSegment.DataElementValue(6) 'Shipment Method of Payment sValue = oSegment.DataElementValue(7) 'Shipment Qualifier ElseIf sSegmentID = "B2A" Then sValue = oSegment.DataElementValue(1) 'Transaction Set Purpose Code sValue = oSegment.DataElementValue(2) 'Application Type ElseIf sSegmentID = "L11" Then 'MULTIPLE INSTANCES OF SEGMENTS CAN BE FURTHER IDENTIFIED FROM EACH OTHER 'BY READING THEIR QUALIFIER sQlfr = oSegment.DataElementValue(2) 'Reference Identification Qualifier If sQlfr = "CO" Then 'Customer Order Number List1.AddItem "Customer Order NUmber = " & oSegment.DataElementValue(1) ElseIf sQlfr = "14" Then 'Master Account Number List1.AddItem "Master Account Number = " & oSegment.DataElementValue(1) End If End If 'Segment ID ElseIf sLoopID = "N7" Then If sSegmentID = "N7" Then sValue = oSegment.DataElementValue(1) 'Equipment Initial List1.AddItem oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2) 'Equipment Number End If 'sSegmentID End If 'sLoopID ElseIf nArea = 2 Then If sLoopID = "S5" Then If sSegmentID = "S5" Then sValue = oSegment.DataElementValue(1) 'Stop Sequence Number sValue = oSegment.DataElementValue(2) 'Stop Reason Code sValue = oSegment.DataElementValue(3) 'Weight sValue = oSegment.DataElementValue(4) 'Weight Unit Code sValue = oSegment.DataElementValue(5) 'Number of Units Shipped sValue = oSegment.DataElementValue(6) 'Unit or Basis for Measurement Code ElseIf sSegmentID = "L11" Then sQlfr = oSegment.DataElementValue(2) 'Reference Identification Qualifier If sQlfr = "RU" Then List1.AddItem "Route Number = " & oSegment.DataElementValue(1) 'Reference Identification End If ElseIf sSegmentID = "G62" Then sValue = oSegment.DataElementValue(1) 'Date Qualifier sValue = oSegment.DataElementValue(2) 'Date End If 'Segment ID ElseIf sLoopID = "S5;N1" Then 'If loop has more that one instance, then you should check for the qualifier that differentiates the loop instances. If sSegmentID = "N1" Then sLoopN1Qlfr = oSegment.DataElementValue(1) 'In most cases the loop entity identifier is the first element of the first segment in the loop, but not necessarily End If If sLoopN1Qlfr = "SF" Then 'Ship From If sSegmentID = "N1" Then sValue = oSegment.DataElementValue(1) 'Entity Identifier Code List1.AddItem "Ship From Name = " & oSegment.DataElementValue(2) 'Name sValue = oSegment.DataElementValue(3) 'Identification Code Qualifier sValue = oSegment.DataElementValue(4) 'Identification Code ElseIf sSegmentID = "N3" Then List1.AddItem "Ship From Address = " & oSegment.DataElementValue(1) 'Address Information sValue = oSegment.DataElementValue(2) 'Address Information ElseIf sSegmentID = "N4" Then sValue = oSegment.DataElementValue(1) 'City Name sValue = oSegment.DataElementValue(2) 'State or Province Code sValue = oSegment.DataElementValue(3) 'Postal Code ElseIf sSegmentID = "G61" Then sQlfr = oSegment.DataElementValue(1) 'Contact Function Code If sQlfr = "IC" Then List1.AddItem "Ship From Contact = " & oSegment.DataElementValue(2) 'Name End If End If 'Segment ID ElseIf sLoopN1Qlfr = "CN" Then 'Consignee If sSegmentID = "N1" Then sValue = oSegment.DataElementValue(1) 'Entity Identifier Code List1.AddItem "Consignee Name = " & oSegment.DataElementValue(2) 'Name sValue = oSegment.DataElementValue(3) 'Identification Code Qualifier sValue = oSegment.DataElementValue(4) 'Identification Code ElseIf sSegmentID = "N3" Then List1.AddItem "Consignee Address = " & oSegment.DataElementValue(1) 'Address Information sValue = oSegment.DataElementValue(2) 'Address Information ElseIf sSegmentID = "N4" Then sValue = oSegment.DataElementValue(1) 'City Name sValue = oSegment.DataElementValue(2) 'State or Province Code sValue = oSegment.DataElementValue(3) 'Postal Code ElseIf sSegmentID = "G61" Then sQlfr = oSegment.DataElementValue(1) 'Contact Function Code If sQlfr = "IC" Then List1.AddItem "Consignee Contact = " & oSegment.DataElementValue(2) 'Name End If End If 'Segment ID End If ElseIf sLoopID = "S5;OID" Then If sSegmentID = "OID" Then List1.AddItem oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1) 'Reference Identification List1.AddItem oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2) 'Purchase Order Number sValue = oSegment.DataElementValue(3) 'Reference Identification sValue = oSegment.DataElementValue(4) 'Unit or Basis for Measurement Code sValue = oSegment.DataElementValue(5) 'Quantity sValue = oSegment.DataElementValue(6) 'Weight Unit Code sValue = oSegment.DataElementValue(7) 'Weight ElseIf sSegmentID = "LAD" Then List1.AddItem oSegment.DataElement(1).Description & " = " & oSegment.DataElementValue(1) 'Packaging Form Code List1.AddItem oSegment.DataElement(2).Description & " = " & oSegment.DataElementValue(2) 'Lading Quantity sValue = oSegment.DataElementValue(3) 'Weight Unit Code sValue = oSegment.DataElementValue(4) 'Unit Weight sValue = oSegment.DataElementValue(5) 'Weight Unit Code sValue = oSegment.DataElementValue(6) 'Weight sValue = oSegment.DataElementValue(7) 'Product/Service ID Qualifier List1.AddItem oSegment.DataElement(8).Description & " = " & oSegment.DataElementValue(8) 'Product/Service ID sValue = oSegment.DataElementValue(9) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(10) 'Product/Service ID sValue = oSegment.DataElementValue(11) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(12) 'Product/Service ID List1.AddItem oSegment.DataElement(13).Description & " = " & oSegment.DataElementValue(13) 'Lading Description End If 'sSegmentID End If 'sLoopID ElseIf nArea = 3 Then If sLoopID = "" Then If sSegmentID = "L3" Then sValue = oSegment.DataElementValue(1) 'Weight sValue = oSegment.DataElementValue(2) 'Weight Qualifier sValue = oSegment.DataElementValue(3) 'Freight Rate sValue = oSegment.DataElementValue(4) 'Rate/Value Qualifier sValue = oSegment.DataElementValue(5) 'Charge sValue = oSegment.DataElementValue(6) 'Advances sValue = oSegment.DataElementValue(7) 'Prepaid Amount sValue = oSegment.DataElementValue(8) 'Special Charge or Allowance Code sValue = oSegment.DataElementValue(9) 'Volume sValue = oSegment.DataElementValue(10) 'Volume Unit Qualifier sValue = oSegment.DataElementValue(11) 'Lading Quantity End If 'sSegmentID End If 'sLoopID End If 'nArea 'GETS THE NEXT DATA SEGMENT Set oSegment = oSegment.Next Loop 'DESTROY OBJECTS Set oEdiDoc = Nothing Set oSchema = Nothing Set oSchemas = Nothing Set oSegment = Nothing MsgBox "Done"