* This is just an example program to demonstrate how to create a
* Functional Acknowledgment 997 in Foxpro with the Framework EDI component
clear all
sSefFile = "810_4010.SEF"
sSef997File = "997_4010.SEF"
sEdiFile = "810.X12"
sAckfile = "997_" + sEdifile
oEdiDoc = createobject("fredi.ediDocument")
* To support large EDI files without much memory, and improve performance
oEdiDoc.CursorType = 1 && Cursor Forward_Only
* By default, FREDI uses the universal coordinated time (UTC), however you can change it to local time
oEdiDoc.Option(12) = 1 && OptDocument_UseLocalTime
* Stops FREDI from using the internal standard reference
oSchemas = oEdiDoc.GetSchemas
oSchemas.EnableStandardReference = .F.
* Load SEF for EDI document to be acknowledged
oEdiDoc.LoadSchema(sSefFile, 0)
* Load SEF for 997 EDI file
oEdiDoc.LoadSchema(sSef997File, 0)
oAck = oEdiDoc.GetAcknowledgment
* Do not show segments AK2, AK3, AK5 if transaction set is accepted (AK501 = "A")
oAck.Option(0) = 0 && OptAcknowledgment_ShowReportingLevel
* Set starting point of EDI Ack control numbers
oAck.Property(12) = 1010 && PropertyAck_StartInterchangeControlNum
oAck.Property(13) = 10 && PropertyAck_StartGroupControlNum
oAck.Property(14) = 1 && PropertyAck_StartTransactionSetControlNum
* Property to include the TA1 segment in the acknowledgment
oAck.EnableInterchangeAcknowledgment = .T.
* Property that determines whether a 997 acknowledgment is created or not while loading the EDI file.
oAck.EnableFunctionalAcknowledgment = .T.
* Property to specify that the transaction set is accepted even with errors
* oAck.AcceptSetWithErrors = .T.
* Property to specify that the group set is accepted even with errors
* oAck.AcceptGroupWithErrors = .T.
* Load the EDI file
oEdiDoc.LoadEdi(sEdiFile)
* Instantiate oSegment by getting the first segment
oSegment = oEdiDoc.FirstDataSegment
* When the cursor type is set to ForwardOnly, make sure to iterate through all segments to allow FREDI to validate them.
do while !isnull(oSegment)
oSegment = oSegment.Next
EndDo
* Anything in the oAck object that was automtically generated can be changed before saving to file.
* Changing the date and time in the ISA segment of the oAck
* Changing the TA1 segment
oSegment = oAck.GetFirstTA1DataSegment
oSegment = oSegment.GetDataSegmentByPos("\ISA\TA1")
oSegment.DataElementValue(4) = "R"
* Another method of changing the date and time in the GS segment of the oAck
oSegment = oAck.GetFirst997DataSegment
oSegment = oSegment.GetDataSegmentByPos("\ISA\GS\GS")
oSegment.DataElementValue(4) = "20010101" && Change date
oSegment.DataElementValue(5) = "110130" && Change time
* Get last transaction set control number used in auto-generated acknowledgment
sLastTsControlNo = oAck.Property(26) && Get ending control number of the last Transaction Set/Message
* Writes the Acknowledgment to file
oAck.Save(sAckfile)
? "Done"