procedure TForm1.cmdTranslateClick(Sender: TObject);
//This is just an example program to demonstrate how to create a functional acknowledgment 997 file
//in Delphi using the Framework EDI component

var
   oEdiDoc : IediDocument;
   oAck : IediAcknowledgment;
   oSchemas : IediSchemas;
   oSegment : IediDataSegment;

   sPath : String;
   sSefFile : String;
   sEdiFile : String;
   sAckFile : String;

begin

   cmdTranslate.Enabled := False;

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

   //edi file to be acknowledge
   sEdiFile := '835.X12';

   oEdiDoc := CoediDocument.Create();

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

   //By default, FREDI uses the  universal coordinated time (UTC), however you can change it to local time
   oEdiDoc.Option[12] := 1;

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

   //Load SEF files
   //for reading the EDI file to be acknowledged (in this example it is the 835)
   oEdidoc.LoadSchema(spath + '835_X091.SEF',0);

   //for creating 997 EDI file
   oEdidoc.LoadSchema(spath + '997_4010.SEF',0);

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

   //Property to enable TA1 acknowledgment in the 997
   oAck.EnableInterchangeAcknowledgment := true;

   //Option to combine the TA1 and 997 into one Interchange
   oAck.Option[4] := 1;

   //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 ;

   // Errors that are not automatically included by FREDI in the 997 file can be added
   //  by mapping FREDI's error code number to the 997 error code.
   // In this example, errors caused by leading zeros in numeric data type are mapped to
   // 997 error code 5 (Element too long)
   oAck.MapDataElementLevelError(13209, 5,'','','','');
    
   //Load EDI file to be acknowledged
   oEdiDoc.LoadEdi(sPath + sEdiFile);

   //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;

   // After the entire EDI file has been read, the oAck object that FREDI created automatically
   // can be read or even modified e.g.
 
   // Gets the first data segment of the Acknowledgment 
   // oSegment := oAck.GetFirst997DataSegment as IediDataSegment;

   // Check to see if the acknpwedgment was a rejection
   // oSegment := oSegment.GetDataSegmentByPos('\ISA\GS\ST\AK9')  as IediDataSegment;
   // if oSegment.DataElementValue[1] = "R" then begin  //Reject
   // End;

   //save acknowledgment file
   oAck.Save(sPath + '997_' + sEdiFile);

   ShowMessage('Done.  Output = ' + sPath + '997_' + sEdiFile);
   cmdTranslate.Enabled := true;

End;