var oEdiDoc: IediDocument; oSchema: IediSchema; oSchemas: IediSchemas; oSegment: IediDataSegment; sSegmentID: String; sLoopID: String; nArea: Integer; sValue: String; begin // CREATES EDIDOC OBJECT oEdidoc := coedidocument.Create; // 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 as IediSchemas; oSchemas.EnableStandardReference := false; // 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 as IediDataSegment; // LOOP THAT WILL TRAVERSE THRU THE EDI FILE FROM TOP TO BOTTOM while oSegment <> Nil do begin // DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA // (OR TABLE) NUMBER THAT THEY ARE IN. nArea := oSegment.Area; sLoopID := oSegment.LoopSection; sSegmentID := oSegment.ID; if nArea = 0 then begin if sLoopID = '' then begin if sSegmentID = 'ISA' then begin sValue := oSegment.DataElementValue[1,0]; // Authorization Information Qualifier sValue := oSegment.DataElementValue[2,0]; // Authorization Information sValue := oSegment.DataElementValue[3,0]; // Security Information Qualifier sValue := oSegment.DataElementValue[4,0]; // Security Information sValue := oSegment.DataElementValue[5,0]; // Interchange ID Qualifier sValue := oSegment.DataElementValue[6,0]; // Interchange Sender ID sValue := oSegment.DataElementValue[7,0]; // Interchange ID Qualifier sValue := oSegment.DataElementValue[8,0]; // Interchange Receiver ID sValue := oSegment.DataElementValue[9,0]; // Interchange Date sValue := oSegment.DataElementValue[10,0]; // Interchange Time sValue := oSegment.DataElementValue[11,0]; // Interchange Control Standards Identifier sValue := oSegment.DataElementValue[12,0]; // Interchange Control Version Number sValue := oSegment.DataElementValue[13,0]; // Interchange Control Number sValue := oSegment.DataElementValue[14,0]; // Acknowledgment Requested sValue := oSegment.DataElementValue[15,0]; // Usage Indicator sValue := oSegment.DataElementValue[16,0]; // Component Element Separator end else if sSegmentID = 'GS' then begin sValue := oSegment.DataElementValue[1,0]; // Functional Identifier Code sValue := oSegment.DataElementValue[2,0]; // Application Sender's Code sValue := oSegment.DataElementValue[3,0]; // Application Receiver's Code sValue := oSegment.DataElementValue[4,0]; // Date sValue := oSegment.DataElementValue[5,0]; // Time sValue := oSegment.DataElementValue[6,0]; // Group Control Number sValue := oSegment.DataElementValue[7,0]; // Responsible Agency Code sValue := oSegment.DataElementValue[8,0]; // Version / Release / Industry Identifier Code end; //sSegmentID end; //sLoopID end else if nArea = 1 then begin if sLoopID = '' then begin if sSegmentID = 'ST' then begin sValue := oSegment.DataElementValue[1,0]; // Transaction Set Identifier Code sValue := oSegment.DataElementValue[2,0]; // Transaction Set Control Number end else if sSegmentID = 'BIG' then begin sValue := oSegment.DataElementValue[1,0]; // Date sValue := oSegment.DataElementValue[2,0]; // Invoice Number sValue := oSegment.DataElementValue[3,0]; // Date sValue := oSegment.DataElementValue[4,0]; // Purchase Order Number end; //sSegmentID end else if sLoopID = 'N1' then begin // 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 begin // sLoopQlfr := oSegment.DataElementValue[1,0]; // In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily // end; // If sLoopQlfr = 'QualifierValue' then begin if sSegmentID = 'N1' then begin sValue := oSegment.DataElementValue[1,0]; // Entity Identifier Code sValue := oSegment.DataElementValue[2,0]; // Name sValue := oSegment.DataElementValue[3,0]; // Identification Code Qualifier sValue := oSegment.DataElementValue[4,0]; // Identification Code end else if sSegmentID = 'N3' then begin sValue := oSegment.DataElementValue[1,0]; // Address Information end else if sSegmentID = 'N4' then begin sValue := oSegment.DataElementValue[1,0]; // City Name sValue := oSegment.DataElementValue[2,0]; // State or Province Code sValue := oSegment.DataElementValue[3,0]; // Postal Code end; //sSegmentID end; //sLoopID end else if nArea = 2 then begin if sLoopID = 'IT1' then begin if sSegmentID = 'IT1' then begin sValue := oSegment.DataElementValue[1,0]; // Assigned Identification sValue := oSegment.DataElementValue[2,0]; // Quantity Invoiced sValue := oSegment.DataElementValue[3,0]; // Unit or Basis for Measurement Code sValue := oSegment.DataElementValue[4,0]; // Unit Price sValue := oSegment.DataElementValue[5,0]; // Basis of Unit Price Code sValue := oSegment.DataElementValue[6,0]; // Product/Service ID Qualifier sValue := oSegment.DataElementValue[7,0]; // Product/Service ID end; //sSegmentID end else if sLoopID = 'IT1;PID' then begin if sSegmentID = 'PID' then begin sValue := oSegment.DataElementValue[1,0]; // Item Description Type sValue := oSegment.DataElementValue[2,0]; // Product/Process Characteristic Code sValue := oSegment.DataElementValue[3,0]; // Agency Qualifier Code sValue := oSegment.DataElementValue[4,0]; // Product Description Code sValue := oSegment.DataElementValue[5,0]; // Description end; //sSegmentID end; //sLoopID end else if nArea = 3 then begin if sLoopID = '' then begin if sSegmentID = 'TDS' then begin sValue := oSegment.DataElementValue[1,0]; // Amount end else if sSegmentID = 'CAD' then begin sValue := oSegment.DataElementValue[1,0]; // Transportation Method/Type Code sValue := oSegment.DataElementValue[2,0]; // Equipment Initial sValue := oSegment.DataElementValue[3,0]; // Equipment Number sValue := oSegment.DataElementValue[4,0]; // Standard Carrier Alpha Code sValue := oSegment.DataElementValue[5,0]; // Routing end; //sSegmentID end else if sLoopID = 'ISS' then begin if sSegmentID = 'ISS' then begin sValue := oSegment.DataElementValue[1,0]; // Number of Units Shipped sValue := oSegment.DataElementValue[2,0]; // Unit or Basis for Measurement Code end; //sSegmentID end; //sLoopID end; //nArea // GETS THE NEXT DATA SEGMENT oSegment := oSegment.Next as IediDataSegment; end; end;