unit Unit1;
// This is just an example to show how to acknowledge an EDI file, and create
// a Functional Acknowledgment 997 in Delphi with Framework EDI component.

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, OleServer, FREDI_TLB,
  StdCtrls;

type
  TForm1 = class(TForm)
    cmdTranslate: TButton;
    cmdClose: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure cmdTranslateClick(Sender: TObject);
    procedure cmdCloseClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.cmdTranslateClick(Sender: TObject);
var
   oEdiDoc : IediDocument;
   oAck : IediAcknowledgment;
   oSchemas : IediSchemas;
   oSegment : IediDataSegment;

   sPath : string;
   sSefFile : string;
   sEdiFile : string;
   sAckFile : string;

begin
   cmdTranslate.Enabled := False;

   sPath := Trim(GetCurrentDir) + '\';

   oEdiDoc := CoediDocument.Create();

   //change cursor type from dynamic (default) to ForwardOnly to improve performance
   oEdidoc.CursorType := Cursor_ForwardOnly;

   //Disable standard reference.  Use SEF file only
   oSchemas := oEdidoc.GetSchemas as IediSchemas;
   oSchemas.EnableStandardReference := false;

   //Load SEF files
   //for reading 810 EDI file
   oEdidoc.LoadSchema(spath + '810_4010.SEF',0);
   //for writing 997 EDI file
   oEdidoc.LoadSchema(spath + '997_4010.SEF',0);

   //Enable acknowledgment
   oAck := oEdiDoc.GetAcknowledgment as IediAcknowledgment;
   oAck.EnableFunctionalAcknowledgment := true;

   //Do not show segments AK2, AK3, AK5 if transaction set is accepted (AK501 = "A")
   oAck.Option[OptAcknowledgment_ShowReportingLevel] := 0;

   //Set starting point of EDI Ack control numbers
   oAck.Property_[PropertyAck_StartInterchangeControlNum]:= 1010;
   oAck.Property_[PropertyAck_StartGroupControlNum]:= 10;
   oAck.Property_[PropertyAck_StartTransactionSetControlNum]:= 1;


   //Property to specify that the transaction set is accepted even with errors
   //oAck.AcceptSetWithErrors = True ;

    //Property to specify that the group set is accepted even with errors
    //oAck.AcceptGroupWithErrors = True ;

   //Load EDI file to be acknowledged
   oEdiDoc.LoadEdi(sPath + '810.X12');

   //When the cursor type is set to ForwardOnly, make sure to traverse through all segments to allow FREDI to validate them.
   oSegment := oEdiDoc.FirstDataSegment as IediDataSegment;
   while oSegment <> Nil do begin
        oSegment := oSegment.Next as IediDataSegment;
   end;

   //save acknowledgment file
   oAck.Save(sPath + '997_810.X12');

   ShowMessage('997 done');
   cmdTranslate.Enabled := true;

end;

procedure TForm1.cmdCloseClick(Sender: TObject);
begin
   Close;
end;

end.