procedure TForm1.Button1Click(Sender: TObject); // This is just an example program to demonstrate how to generate multiple interchanges and // INVOIC messages in Delphi with the Framework EDI component var oEdiDoc: Iedidocument; oInterchange: IediInterchange; oGroup: IediGroup; oTransactionset: IediTransactionset; oSegment: IediDataSegment; oSchemas: IediSchemas; sPath: string; sEdiFile: string; sSefFile: string; nIc: integer; nTs: integer; begin button1.Enabled := false; sPath := Trim(GetCurrentDir) + '\'; sEdiFile := 'INVOIC.TXT'; sSefFile := 'INVOIC_S93A.SEF'; //CREATE EDI DOCUMENT OBJECT oEdidoc := coedidocument.Create ; //CHANGE CURSOR TYPE TO FORWARDWRITE TO SAVE RAM AND IMPROVE PERFORMANCE oEdidoc.CursorType := 2; //DISABLE INTERNAL STANDARD REFERENCE LIBRARY TO SAVE RAM AND IMPROVE PERFORMANCE oSchemas := oEdidoc.GetSchemas as IediSchemas; oSchemas.EnableStandardReference := False; //LOAD THE SEF FILE oEdidoc.LoadSchema(sPath + sSefFile,0); //SET TERMINATORS oEdidoc.SegmentTerminator := ''''; oEdidoc.ElementTerminator := '+'; oEdiDoc.CompositeTerminator := ':'; oEdiDoc.ReleaseIndicator := '?'; //Create UNA segment (OptDocument_ServiceSegment) oEdiDoc.Option[5] := 1; //To have multiple interchanges in an EDI file, simply repeat the oEdidoc.CreateInterchange method for nIc := 1 to 2 do begin //CREATE INTERCHANGE HEADER CONTROL SEGMENT oInterchange := oEdidoc.CreateInterchange('UN','S93A') as IediInterchange; oSegment := oInterchange.GetDataSegmentHeader as IediDataSegment; oSegment.DataElementValue[1,1] := 'UNOB'; oSegment.DataElementValue[1,2] := '1'; oSegment.DataElementValue[2,1] := 'PARTNER ID'; oSegment.DataElementValue[2,2] := 'ZZZ'; oSegment.DataElementValue[3,1] := '0038977332'; oSegment.DataElementValue[3,2] := '1'; oSegment.DataElementValue[3,3] := 'MFGB'; oSegment.DataElementValue[4,1] := '020331'; oSegment.DataElementValue[4,2] := '1230'; oSegment.DataElementValue[5,0] := IntToStr(nIc); oSegment.DataElementValue[7,0] := 'INVOIC'; oSegment.DataElementValue[11,0] := '1'; //To have multiple messages in an interchange, simply repeat the oInterchange.CreateTransactionset method for nTs := 1 to 3 do begin //CREATE TRANSACTION SET HEADER CONTROL SEGMENT oTransactionset := oInterchange.CreateTransactionset('INVOIC') as IediTransactionset; oSegment := oTransactionset.GetDataSegmentHeader as IediDataSegment; oSegment.DataElementValue[1,0] := IntToStr(nTs); oSegment.DataElementValue[2,1] := 'INVOIC'; oSegment.DataElementValue[2,2] := 'S'; oSegment.DataElementValue[2,3] := '93A'; oSegment.DataElementValue[2,4] := 'UN'; //BGM oSegment := oTransactionset.CreateDataSegment('BGM') as IediDataSegment; oSegment.DataElementValue[1,1] := '380'; oSegment.DataElementValue[2,0] := '123456'; oSegment.DataElementValue[4,0] := 'NA'; //DTM oSegment := oTransactionset.CreateDataSegment('DTM') as IediDataSegment; oSegment.DataElementValue[1,1] := '137'; oSegment.DataElementValue[1,2] := '20000101'; oSegment.DataElementValue[1,3] := '102'; //CREATE REF SEGMENT IN REF GROUP oSegment := oTransactionset.CreateDataSegment('RFF\RFF') as IediDataSegment; oSegment.DataElementValue[1,1] := 'ON'; oSegment.DataElementValue[1,2] := 'CUST_ORDER_NO'; //CREATE NAD SEGMENT IN NAD GROUP oSegment := oTransactionset.CreateDataSegment('NAD\NAD') as IediDataSegment; oSegment.DataElementValue[1,0] := 'RE'; oSegment.DataElementValue[2,3] := '92'; oSegment.DataElementValue[4,1] := 'MANUFACTURER NAME'; //CREATE RFF SEGMENT IN RFF GROUP NESTED IN NAD GROUP oSegment := oTransactionset.CreateDataSegment('NAD\RFF\RFF') as IediDataSegment; oSegment.DataElementValue[1,1] := 'VA'; oSegment.DataElementValue[1,2] := 'DE12931720 6'; //CREATE CTA SEGMENT IN CTA GROUP NESTED IN NAD GROUP oSegment := oTransactionset.CreateDataSegment('NAD\CTA\CTA') as IediDataSegment; oSegment.DataElementValue[1,0] := 'AR'; oSegment.DataElementValue[2,2] := 'JANE DOE'; //CREATE COM SEGMENT IN CTA GROUP NESTED IN NAD GROUP oSegment := oTransactionset.CreateDataSegment('NAD\CTA\COM') as IediDataSegment; oSegment.DataElementValue[1,1] := '00 49 89 9933-2543'; oSegment.DataElementValue[1,2] := 'TE'; //CREATE NAD SEGMENT IN SECOND INSTANCE OF NAD GROUP oSegment := oTransactionset.CreateDataSegment('NAD(2)\NAD') as IediDataSegment; oSegment.DataElementValue[1,0] := 'ST'; oSegment.DataElementValue[2,3] := '92'; oSegment.DataElementValue[4,1] := 'COMPAQ COMPUTER CORP.'; // CREATE NAD SEGMENT IN THIRD INSTANCE OF NAD GROUP oSegment := oTransactionset.CreateDataSegment('NAD(3)\NAD') as IediDataSegment; oSegment.DataElementValue[1,0] := 'BY'; oSegment.DataElementValue[2,3] := '92'; oSegment.DataElementValue[4,1] := 'COMPAQ COMPUTER CORP.'; //CREATE CUX SEGMENT IN CUX GROUP oSegment := oTransactionset.CreateDataSegment('CUX\CUX') as IediDataSegment; oSegment.DataElementValue[1,1] := '2'; oSegment.DataElementValue[1,2] := 'USD'; oSegment.DataElementValue[1,3] := '4'; //CREATE ALC SEGMENT IN ALC GROUP oSegment := oTransactionset.CreateDataSegment('ALC\ALC') as IediDataSegment; oSegment.DataElementValue[1,0] := 'C'; oSegment.DataElementValue[3,0] := '6'; oSegment.DataElementValue[5,1] := 'ABG'; //CREATE PCD SEGMENT IN PCD GROUP NESTED IN ALC GROUP oSegment := oTransactionset.CreateDataSegment('ALC\PCD\PCD') as IediDataSegment; oSegment.DataElementValue[1,1] := '1'; oSegment.DataElementValue[1,2] := '2.5'; //CREATE MOA SEGMENT IN MOA GROUP NESTED IN ALC GROUP oSegment := oTransactionset.CreateDataSegment('ALC\MOA\MOA') as IediDataSegment; oSegment.DataElementValue[1,1] := '204'; oSegment.DataElementValue[1,2] := '200.00'; //CREATE LIN SEGMENT IN LIN GROUP oSegment := oTransactionset.CreateDataSegment('LIN\LIN') as IediDataSegment; oSegment.DataElementValue[1,0] := '1'; oSegment.DataElementValue[3,1] := '240152'; oSegment.DataElementValue[3,2] := 'SN'; //CREATE LIN SEGMENT IN QTY GROUP oSegment := oTransactionset.CreateDataSegment('LIN\QTY') as IediDataSegment; oSegment.DataElementValue[1,1] := '47'; oSegment.DataElementValue[1,2] := '3.00'; oSegment.DataElementValue[1,3] := 'EA'; //CREATE PRI SEGMENT IN PRI GROUP NESTED IN LIN GROUP oSegment := oTransactionset.CreateDataSegment('LIN\PRI\PRI') as IediDataSegment; oSegment.DataElementValue[1,1] := 'AAA'; oSegment.DataElementValue[1,2] := '1310.00'; oSegment.DataElementValue[1,3] := 'CT'; //UNS oSegment := oTransactionset.CreateDataSegment('UNS') as IediDataSegment; oSegment.DataElementValue[1,0] := 'S'; //CREATE MOA SEGMENT IN MOA GROUP oSegment := oTransactionset.CreateDataSegment('MOA\MOA') as IediDataSegment; oSegment.DataElementValue[1,1] := '77'; oSegment.DataElementValue[1,2] := '4378.28'; oSegment.DataElementValue[1,3] := 'USD'; //CREATE TAX SEGMENT IN TAX GROUP LOCATED IN AREA (TABLE) 3 oSegment := oTransactionset.CreateDataSegment('TAX#3\TAX') as IediDataSegment; oSegment.DataElementValue[1,0] := '7'; oSegment.DataElementValue[2,1] := 'VAT'; oSegment.DataElementValue[5,4] := '15'; oSegment.DataElementValue[6,0] := 'S'; //CREATE MOA SEGMENT IN TAX GROUP LOCATED IN AREA (TABLE) 3 oSegment := oTransactionset.CreateDataSegment('TAX#3\MOA') as IediDataSegment; oSegment.DataElementValue[1,1] := '176'; oSegment.DataElementValue[1,2] := '248.28'; oSegment.DataElementValue[1,3] := 'USD'; end; //nTs end; //nIc //save the edi document object to a file oEdidoc.Save(sPath + sEdiFile,0); ShowMessage('Done. Output = ' + sPath + sEdiFile); end;