This is a typical 997 EDI file. Generally 997's are the smallest average size of all EDI files, although some can be quite large. The 997 is called a Functional Acknowledgment, and in practice they are used to confirm acceptance or rejection of a file, or to give acceptance or rejection notice of all transaction sets contained in the file.
ISA*00* *00* *ZZ*112233 *10*998877 *040622*2308*U*00304*000000001*0*T*~GS*FA*112233*998877A*040622*230855*1*X*003040~ST*997*0001~AK1*RQ*200154068~AK2*840*1678~AK5*A~
AK9*A*1*1*1~SE*6*0001~GE*1*1~IEA*1*000000001~
Please note - The file above has no line breaks in it, so it shows as just a jumble of characters. A segment is what normal people would regard as a line (after the file has been broken into segments)
While this file looks pretty complicated, it's actually quite easy to read, and like all X12 files, it starts with "ISA" and ends with the "IEA" segment. Below is just the "ISA" segment plus one extra character (because it's extremely important).
ISA*00* *00* *ZZ*112233 *10*998877 *040622*2308*U*00304*000000001*0*T*~
The ISA is important because it is the only fixed length segment in the standard, and as such, it can be parsed and used without knowing what else is in the file.The ISA segment is probably the most important segment for a a parser, because it tells the parser how to read the next segment and how to break the file into segments.
The ISA segment MUST be 106 characters. There is a min/max definition of each element. If you don't have enough data to fill that element it should be padded with spaces on the right to make it the maximum size. The ISA02 and ISA04 are commonly empty elements, but need to be padded to make up the fixed length width of the segment. Sender IDs and Receiver IDs are commonly less than 15 characters, and therefore must be padded.
The ISA (Interchange Control Header) segment is always the first segment in an EDI ANSII X12 document. It's always exactly 106 characters long, and it's purpose is to give information about how to read this file, who the file is coming from, and who it's intended for.
Here's how you program to read the ISA segment
- Read the first 3 characters of the file. If they aren't "ISA", this either isn't an ANSII X12 document, or it's not properly formatted. Your EDI framework should save the file to your "error documents" directory, update the edi_incoming database entry to set the read_attempts to 1, the read_successful to 0, set the read_date_time to the current time.
- Now read the 4th character. It is the Element Delimiter. Throughout the file it is the character you will use to separate the elements. The Element Delimiter cannot be contained in the element data. IE. in this file the element delimiter is * . That character must not appear in the data anywhere. While the EDI spec does have a way to escape this character in the data, most companies EDI systems are not setup to deal with escaping data, so standard practice is to make sure this character does not appear anywhere in the data.
- Before the year 2000, it was common practice to pluck the data out of the ISA segment by reading a substring. In PHP, that would be something like:
$AuthorizationInformationQualifier = substr(4,2); (read the 5th and 6th characters)
$AuthorizationInformation = substr(7, 10) (read the 8th through 17th characters)
and continue until all the elements were read.
However, some companies needed a 4 digit year, not just a 2 digit year, so they broke the EDI spec and required a 4 digit year. To adjust for that, it's easier now to just take a substring of 108 characters, then using the Element Delimiter (* in this file) break off the first element, and keep doing that until you get to the 9th element (which is the Interchange Date) , then check to see if the 9th element is 6 or 8 characters long. If it's 6 characters the year is 2 characters, if it's 8 characters, the year is 4 characters long. Of course, all dates in EDI files should be 20?? now, so if the year is 2 characters just prepend a "20" to it. Then continue breaking off the first element until you get to the 15th element (the Interchange Usage Indicator, either "T" or "P"), strip the Element Delimiter, and the next character is the Segment Terminator. You will use the Segment Terminator to break the entire file into segments (what normal people think of as lines).
Now, you need to verify all the data you have just collected. Each element should be verified to be the correct size, and spaces should be stripped off the ends of all elements (remember they are right-padded). Then you should verify you have an EDI record that uses that Interchange Sender ID and that Interchange Receiver ID, you might need to check the Interchange Control Number to make sure this file hasn't already been read, or the number is unique (depending on the implementation, check your trading partner specs).
Anyway, that's how to program the ISA segment (simple isn't it?). I could provide more details, but if you need to know more, ask a question in our forum or send us a message. I will try to add the PHP function we use for stripping elements off the segments.
© EDI Shack 2024 http://edishack.com