* CREATES EDIDOC OBJECT oEdiDoc = createobject("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. oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = .F. * THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType = 1 * LOADS THE SEF FILE oEdiDoc.LoadSchema("810_X12-4010.SEF", 0) * LOADS THE EDI FILE oEdiDoc.LoadEdi("810_X12-4010.TXT") * GETS THE FIRST DATA SEGMENT oSegment = oEdiDoc.FirstDataSegment * LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM do while !isnull(oSegment) * 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 do case case nArea = 0 do case case sLoopID == "" do case case sSegmentID = "ISA" 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 sValue = oSegment.DataElementValue(5) && Interchange ID Qualifier sValue = 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 sValue = oSegment.DataElementValue(12) && Interchange Control Version Number sValue = 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 case sSegmentID = "GS" 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 sValue = oSegment.DataElementValue(6) && Group Control Number sValue = oSegment.DataElementValue(7) && Responsible Agency Code sValue = oSegment.DataElementValue(8) && Version / Release / Industry Identifier Code endcase && sSegmentID endcase && sLoopID case nArea = 1 do case case sLoopID == "" do case case sSegmentID = "ST" sValue = oSegment.DataElementValue(1) && Transaction Set Identifier Code sValue = oSegment.DataElementValue(2) && Transaction Set Control Number case sSegmentID = "BIG" sValue = oSegment.DataElementValue(1) && Date sValue = oSegment.DataElementValue(2) && Invoice Number sValue = oSegment.DataElementValue(3) && Date sValue = oSegment.DataElementValue(4) && Purchase Order Number endcase && sSegmentID case sLoopID == "N1" * If loop has more that one instance, then you should check for the qualifier that differentiates the loop instances here e.g. * If sSegmentID = "N1" then * sLoopQlfr = oSegment.DataElementValue(1) && In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily * EndIf * If sLoopQlfr = "QualifierValue" then do case case sSegmentID = "N1" sValue = oSegment.DataElementValue(1) && Entity Identifier Code sValue = oSegment.DataElementValue(2) && Name sValue = oSegment.DataElementValue(3) && Identification Code Qualifier sValue = oSegment.DataElementValue(4) && Identification Code case sSegmentID = "N3" sValue = oSegment.DataElementValue(1) && Address Information case sSegmentID = "N4" sValue = oSegment.DataElementValue(1) && City Name sValue = oSegment.DataElementValue(2) && State or Province Code sValue = oSegment.DataElementValue(3) && Postal Code endcase && sSegmentID endcase && sLoopID case nArea = 2 do case case sLoopID == "IT1" do case case sSegmentID = "IT1" sValue = oSegment.DataElementValue(1) && Assigned Identification sValue = oSegment.DataElementValue(2) && Quantity Invoiced sValue = oSegment.DataElementValue(3) && Unit or Basis for Measurement Code sValue = oSegment.DataElementValue(4) && Unit Price sValue = oSegment.DataElementValue(5) && Basis of Unit Price Code sValue = oSegment.DataElementValue(6) && Product/Service ID Qualifier sValue = oSegment.DataElementValue(7) && Product/Service ID endcase && sSegmentID case sLoopID == "IT1;PID" do case case sSegmentID = "PID" sValue = oSegment.DataElementValue(1) && Item Description Type sValue = oSegment.DataElementValue(2) && Product/Process Characteristic Code sValue = oSegment.DataElementValue(3) && Agency Qualifier Code sValue = oSegment.DataElementValue(4) && Product Description Code sValue = oSegment.DataElementValue(5) && Description endcase && sSegmentID endcase && sLoopID case nArea = 3 do case case sLoopID == "" do case case sSegmentID = "TDS" sValue = oSegment.DataElementValue(1) && Amount case sSegmentID = "CAD" sValue = oSegment.DataElementValue(1) && Transportation Method/Type Code sValue = oSegment.DataElementValue(2) && Equipment Initial sValue = oSegment.DataElementValue(3) && Equipment Number sValue = oSegment.DataElementValue(4) && Standard Carrier Alpha Code sValue = oSegment.DataElementValue(5) && Routing endcase && sSegmentID case sLoopID == "ISS" do case case sSegmentID = "ISS" sValue = oSegment.DataElementValue(1) && Number of Units Shipped sValue = oSegment.DataElementValue(2) && Unit or Basis for Measurement Code endcase && sSegmentID endcase && sLoopID endcase && nArea * GETS THE NEXT DATA SEGMENT oSegment = oSegment.Next enddo