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 GENERATE THE EDI FILE. oSchemas := oEdiDoc.GetSchemas as IediSchemas; oSchemas.EnableStandardReference := false; // STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType := 1; // GET TERMINATORS oEdiDoc.SegmentTerminator := ''''; oEdiDoc.ElementTerminator := '+'; oEdiDoc.CompositeTerminator := ':'; oEdiDoc.ReleaseIndicator := '?'; // LOADS THE SEF FILE oEdidoc.LoadSchema('ORDERS_D96A.SEF',0); // LOADS THE EDI FILE oEdiDoc.LoadEdi('ORDERS_D96A.EDI'); // 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 = 'UNB' then begin 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,0]; // Interchange control reference end; //sSegmentID end; //sLoopID end else if nArea = 1 then begin if sLoopID = '' then begin if sSegmentID = 'UNH' then begin sValue := oSegment.DataElementValue[1,0]; // 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 end else if sSegmentID = 'BGM' then begin 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,0]; // Document/message number sValue := oSegment.DataElementValue[3,0]; // Message function, coded end else if sSegmentID = 'DTM' then begin 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; //sSegmentID end else if sLoopID = 'RFF' then begin if sSegmentID = 'RFF' then begin 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; //sSegmentID end else if sLoopID = 'NAD' then begin if sSegmentID = 'NAD' then begin sValue := oSegment.DataElementValue[1,0]; // 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 end; //sSegmentID end else if sLoopID = 'TDT' then begin if sSegmentID = 'TDT' then begin sValue := oSegment.DataElementValue[1,0]; // Transport stage qualifier sValue := oSegment.DataElementValue[2,0]; // Conveyance reference number sValue := oSegment.DataElementValue[3,1]; // Mode of transport, coded sValue := oSegment.DataElementValue[3,2]; // Mode of transport end; //sSegmentID end else if sLoopID = 'TDT;LOC' then begin if sSegmentID = 'LOC' then begin sValue := oSegment.DataElementValue[1,0]; // Place/location qualifier sValue := oSegment.DataElementValue[2,1]; // Place/location identification sValue := oSegment.DataElementValue[2,2]; // Code list qualifier sValue := oSegment.DataElementValue[2,3]; // Code list responsible agency, coded sValue := oSegment.DataElementValue[2,4]; // Place/location end; //sSegmentID end; //sLoopID end else if nArea = 2 then begin if sLoopID = 'LIN' then begin if sSegmentID = 'LIN' then begin sValue := oSegment.DataElementValue[1,0]; // Line item number end; //sSegmentID end else if sLoopID = 'LIN;LOC' then begin if sSegmentID = 'LOC' then begin sValue := oSegment.DataElementValue[1,0]; // Place/location qualifier end else if sSegmentID = 'QTY' then begin sValue := oSegment.DataElementValue[1,1]; // Quantity qualifier sValue := oSegment.DataElementValue[1,2]; // Quantity sValue := oSegment.DataElementValue[1,3]; // Measure unit qualifier end else if sSegmentID = 'DTM' then begin 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; //sSegmentID end else if sLoopID = 'LIN;NAD' then begin if sSegmentID = 'NAD' then begin sValue := oSegment.DataElementValue[1,0]; // 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 end; //sSegmentID end; //sLoopID end else if nArea = 3 then begin if sLoopID = '' then begin if sSegmentID = 'UNS' then begin sValue := oSegment.DataElementValue[1,0]; // Section identification end; //sSegmentID end; //sLoopID end; //nArea // GETS THE NEXT DATA SEGMENT oSegment := oSegment.Next as IediDataSegment; end; end;