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 'CREATES EDIDOC 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 GENERATE 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 'GET TERMINATORS oEdiDoc.SegmentTerminator = "'" oEdiDoc.ElementTerminator = "+" oEdiDoc.CompositeTerminator = ":" oEdiDoc.ReleaseIndicator = "?" 'LOADS THE SEF FILE Set oSchema = oEdiDoc.LoadSchema("INVOIC_S93A.SEF", 0) 'LOADS THE EDI FILE oEdiDoc.LoadEdi "INVOIC_S93A.EDI" 'GETS THE FIRST DATA SEGMENT Set oSegment = oEdiDoc.FirstDataSegment 'LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM 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 = "UNB" then sValue = oSegment.DataElementValue(1,1) 'Syntax identifier sValue = oSegment.DataElementValue(1,2) 'Syntax version number sValue = oSegment.DataElementValue(2,1) 'Interchange sender identification sValue = oSegment.DataElementValue(2,2) 'Partner identification code qualifier sValue = oSegment.DataElementValue(2,3) 'Interchange sender internal identification sValue = oSegment.DataElementValue(3,1) 'Recipient identification sValue = oSegment.DataElementValue(3,2) 'Partner identification code qualifier sValue = oSegment.DataElementValue(3,3) 'Routing address sValue = oSegment.DataElementValue(4,1) 'Date sValue = oSegment.DataElementValue(4,2) 'Time sValue = oSegment.DataElementValue(5) 'Interchange control reference sValue = oSegment.DataElementValue(6,1) 'Recipient reference/password sValue = oSegment.DataElementValue(6,2) 'Recipient's reference/password qualifier sValue = oSegment.DataElementValue(7) 'Application reference sValue = oSegment.DataElementValue(8) 'Processing priority code sValue = oSegment.DataElementValue(9) 'Acknowledgement request sValue = oSegment.DataElementValue(10) 'Interchange Agreement Identifier sValue = oSegment.DataElementValue(11) 'Test indicator End If 'sSegmentID End If 'sLoopID ElseIf nArea = 1 then If sLoopId = "" then If sSegmentId = "UNH" then sValue = oSegment.DataElementValue(1) 'Message reference number sValue = oSegment.DataElementValue(2,1) 'Message type identifier sValue = oSegment.DataElementValue(2,2) 'Message version number sValue = oSegment.DataElementValue(2,3) 'Message release number sValue = oSegment.DataElementValue(2,4) 'Controlling agency sValue = oSegment.DataElementValue(2,5) 'Association assigned code ElseIf sSegmentId = "BGM" then sValue = oSegment.DataElementValue(1,1) 'Document/message name, coded sValue = oSegment.DataElementValue(1,2) 'Code list qualifier sValue = oSegment.DataElementValue(1,3) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(1,4) 'Document/message name sValue = oSegment.DataElementValue(2) 'Document/message name sValue = oSegment.DataElementValue(3) 'Document/message name ElseIf sSegmentId = "DTM" then sValue = oSegment.DataElementValue(1,1) 'Date/time/period qualifier sValue = oSegment.DataElementValue(1,2) 'Date/time/period sValue = oSegment.DataElementValue(1,3) 'Date/time/period format qualifier End If 'SegmentID ElseIf sLoopId = "RFF" then If sSegmentId = "RFF" then sValue = oSegment.DataElementValue(1,1) 'Reference qualifier sValue = oSegment.DataElementValue(1,2) 'Reference number sValue = oSegment.DataElementValue(1,3) 'Line number sValue = oSegment.DataElementValue(1,4) 'Reference version number End If 'SegmentID ElseIf sLoopId = "NAD" then If sSegmentId = "NAD" then sValue = oSegment.DataElementValue(1) 'Party qualifier sValue = oSegment.DataElementValue(2,1) 'Party identification sValue = oSegment.DataElementValue(2,2) 'Code list qualifier sValue = oSegment.DataElementValue(2,3) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(3,1) 'Name and address line sValue = oSegment.DataElementValue(3,2) 'Name and address line sValue = oSegment.DataElementValue(3,3) 'Name and address line sValue = oSegment.DataElementValue(3,4) 'Name and address line sValue = oSegment.DataElementValue(3,5) 'Name and address line sValue = oSegment.DataElementValue(4,1) 'Party name sValue = oSegment.DataElementValue(4,2) 'Party name sValue = oSegment.DataElementValue(4,3) 'Party name sValue = oSegment.DataElementValue(4,4) 'Party name sValue = oSegment.DataElementValue(4,5) 'Party name sValue = oSegment.DataElementValue(4,6) 'Party name format, coded End If 'SegmentID ElseIf sLoopId = "NAD;RFF" then If sSegmentId = "RFF" then sValue = oSegment.DataElementValue(1,1) 'Reference qualifier sValue = oSegment.DataElementValue(1,2) 'Reference number sValue = oSegment.DataElementValue(1,3) 'Line number sValue = oSegment.DataElementValue(1,4) 'Reference version number End If 'SegmentID ElseIf sLoopId = "NAD;CTA" then If sSegmentId = "CTA" then sValue = oSegment.DataElementValue(1) 'Contact function, coded sValue = oSegment.DataElementValue(2,1) 'Department or employee identification sValue = oSegment.DataElementValue(2,2) 'Department or employee ElseIf sSegmentId = "COM" then sValue = oSegment.DataElementValue(1,1) 'Communication number sValue = oSegment.DataElementValue(1,2) 'Communication channel qualifier End If 'SegmentID ElseIf sLoopId = "CUX" then If sSegmentId = "CUX" then sValue = oSegment.DataElementValue(1,1) 'Currency details qualifier sValue = oSegment.DataElementValue(1,2) 'Currency, coded sValue = oSegment.DataElementValue(1,3) 'Currency qualifier sValue = oSegment.DataElementValue(1,4) 'Currency rate base End If 'SegmentID ElseIf sLoopId = "ALC" then If sSegmentId = "ALC" then sValue = oSegment.DataElementValue(1) 'Allowance or charge qualifier sValue = oSegment.DataElementValue(2,1) 'Allowance or charge number sValue = oSegment.DataElementValue(2,2) 'Charge/allowance description, coded sValue = oSegment.DataElementValue(3) 'Settlement, coded sValue = oSegment.DataElementValue(4) 'Calculation sequence indicator, coded sValue = oSegment.DataElementValue(5,1) 'Special services, coded sValue = oSegment.DataElementValue(5,2) 'Code list qualifier sValue = oSegment.DataElementValue(5,3) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(5,4) 'Special service End If 'SegmentID ElseIf sLoopId = "ALC;PCD" then If sSegmentId = "PCD" then sValue = oSegment.DataElementValue(1,1) 'Percentage qualifier sValue = oSegment.DataElementValue(1,2) 'Percentage sValue = oSegment.DataElementValue(1,3) 'Percentage basis, coded sValue = oSegment.DataElementValue(1,4) 'Code list qualifier sValue = oSegment.DataElementValue(1,5) 'Code list responsible agency, coded End If 'SegmentID ElseIf sLoopId = "ALC;MOA" then If sSegmentId = "MOA" then sValue = oSegment.DataElementValue(1,1) 'Monetary amount type qualifier sValue = oSegment.DataElementValue(1,2) 'Monetary amount sValue = oSegment.DataElementValue(1,3) 'Currency, coded sValue = oSegment.DataElementValue(1,4) 'Currency qualifier sValue = oSegment.DataElementValue(1,5) 'Status, coded End If 'SegmentID ElseIf sLoopId = "LIN" then If sSegmentId = "LIN" then sValue = oSegment.DataElementValue(1) 'Line item number sValue = oSegment.DataElementValue(2) 'Action request/notification, coded sValue = oSegment.DataElementValue(3,1) 'Item number sValue = oSegment.DataElementValue(3,2) 'Item number type, coded sValue = oSegment.DataElementValue(3,3) 'Code list qualifier sValue = oSegment.DataElementValue(3,4) 'Code list responsible agency, coded ElseIf sSegmentId = "QTY" then sValue = oSegment.DataElementValue(1,1) 'Quantity qualifier sValue = oSegment.DataElementValue(1,2) 'Quantity sValue = oSegment.DataElementValue(1,3) 'Measure unit qualifier End If 'SegmentID ElseIf sLoopId = "LIN;PRI" then If sSegmentId = "PRI" then sValue = oSegment.DataElementValue(1,1) 'Price qualifier sValue = oSegment.DataElementValue(1,2) 'Price sValue = oSegment.DataElementValue(1,3) 'Price type, coded sValue = oSegment.DataElementValue(1,4) 'Price type qualifier sValue = oSegment.DataElementValue(1,5) 'Unit price basis sValue = oSegment.DataElementValue(1,6) 'Measure unit qualifier End If 'SegmentID ElseIf sLoopId = "TAX" then If sSegmentId = "TAX" then sValue = oSegment.DataElementValue(1) 'Duty/tax/fee function qualifier sValue = oSegment.DataElementValue(2,1) 'Duty/tax/fee type, coded sValue = oSegment.DataElementValue(2,2) 'Code list qualifier sValue = oSegment.DataElementValue(2,3) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(2,4) 'Duty/tax/fee type sValue = oSegment.DataElementValue(3,1) 'Duty/tax/fee account identification sValue = oSegment.DataElementValue(3,2) 'Code list qualifier sValue = oSegment.DataElementValue(3,3) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(4) 'Duty/tax/fee assessment basis sValue = oSegment.DataElementValue(5,1) 'Duty/tax/fee rate identification sValue = oSegment.DataElementValue(5,2) 'Code list qualifier sValue = oSegment.DataElementValue(5,3) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(5,4) 'Duty/tax/fee rate sValue = oSegment.DataElementValue(5,5) 'Duty/tax/fee rate basis identification sValue = oSegment.DataElementValue(5,6) 'Code list qualifier sValue = oSegment.DataElementValue(5,7) 'Code list responsible agency, coded sValue = oSegment.DataElementValue(6) 'Duty/tax/fee category, coded ElseIf sSegmentId = "MOA" then sValue = oSegment.DataElementValue(1,1) 'Monetary amount type qualifier sValue = oSegment.DataElementValue(1,2) 'Monetary amount sValue = oSegment.DataElementValue(1,3) 'Currency, coded sValue = oSegment.DataElementValue(1,4) 'Currency qualifier sValue = oSegment.DataElementValue(1,5) 'Status, coded EndIf 'sSegmentID EndIf 'sLoopID EndIf 'nArea 'GETS THE NEXT DATA SEGMENT Set oSegment = oSegment.Next Loop 'DESTROY OBJECTS Set oEdiDoc = Nothing Set oSchema = Nothing Set oSegment = Nothing