* CREATES EDIDOC OBJECT oEdiDoc = createobject("fredi.ediDocument") * THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES * NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO VALIDATE THE EDI FILE. * THE VERSION OF THE EDI FILE MUST ALSO MATCH THE VERSION THAT THE SEF FILE SUPPORTS * OTHERWISE IT WILL STOP THE PROGRAM oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = .F. oSchemas.Option(2) = 1 * BECAUSE THE STANDARD REFERENCE HAS BEED DISABLED. YOU MUST LOAD BOTH THE * 997 SEF FILE (FOR FREDI TO CREATE AN EDI 997 FILE), AS WELL AS THE SEF FILE * THAT WILL BE USED TO VALIDATE THE EDI FILE. * PLEASE NOTE THAT YOU MUST LOAD THE CORRECT VERSION OF THE 997 SEF FILE. oEdiDoc.LoadSchema("997_4010.SEF", 0) oEdiDoc.LoadSchema("810_X12-4010.SEF", 0) * THIS OPTIONS STOPS FREDI FROM LOADING ALL OF THE SEGMENTS IN THE EDI FILE INTO MEMORY. oEdiDoc.CursorType = 1 * CREATES THE ACKNOWLEDGMENT OBJECT oAck = oEdiDoc.GetAcknowledgment * ENABLES THE CREATION OF THE FUNCTIONAL ACKNOWLEDGMENT WHEN FREDI LOADS AN EDI FILE. oAck.EnableFunctionalAcknowledgment = 1 * 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) * LOADS THE EDI FILE. NOTE THAT WHEN THE CURSOR TYPE FORWARD IS ENABLED, ONLY THE FIRST * DATA SEGMENT IS LOADED; OTHERWISE THE WHOLE EDI FILE GETS LOADED INTO MEMORY oEdiDoc.LoadEdi("810_X12-4010.TXT") * IF THE CURSOR TYPE FORWARD IS ENABLED, YOU MUST TRAVERSE THRU THE WHOLE EDI FILE * SO THAT IT ALLOWS FREDI TO LOAD EACH SEGMENT AND ANALYZE THEM. (FREDI DOES NOT KEEP * THE SEGMENTS IN MEMORY, BUT DISCARDS THEM ONCE THEY HAVE BEEN READ) oSegment = oEdiDoc.FirstDataSegment Do While !isnull(oSegment) oSegment = oSegment.Next EndDo * ONCE THE WHOLE EDI FILE HAS BEEN READ, CAN YOU THEN MANAGE AND MANIPULATE DATA * OF THE ACK OBJECT THAT FREDI CREATED AUTOMATICALLY. * GETS THE FIRST DATA SEGMENT OF THE ACK OBJECT * oSegment = oAck.GetFirst997DataSegment * oSegment = oSegment.GetDataSegmentByPos("\ISA\GS\ST\AK9") * if oSegment.DataElementValue(1) = "R" then && Reject * endif * WRITES THE ACKNOWLEDGMENT INTO A FILE. oAck.Save("810_X12-4010.ACK.X12")