997 AK5*R*3: ST02 and SE02 control numbers don't match
Every transaction set starts with ST and ends with SE, and both carry the same control number. If the two values differ, even only by leading zeros, the partner rejects the set.
What you see
AK1*QM*418~
AK2*214*0002~
AK5*R*3~
AK9*R*1*1*0~
A close cousin is AK5*R*23: Transaction Set Control Number Not Unique within the Functional Group, which you get when two STs in the same GS use the same number.
What it means
AK502 code 3 (element 718) = Transaction Set Control Number in Header and Trailer Do Not Match. ST02 and SE02 are element 329, a 4-to-9 character string. They're compared character for character, so 0002 and 2 do not match.
Why it happens
- When several 214s are batched in one group, the trailer is written from the previous set's counter (off by one).
- The header is zero-padded (
0002) but the trailer isn't (2), or the other way around. - The control-number counter is reset per file instead of per set, which leads to duplicates (code 23).
The exact fix
- Make
SE02an exact copy ofST02for each transaction set, with the same digits and the same padding. - Give every ST in the same GS group its own number (0001, 0002, 0003...).
- Resend with a new ISA13 interchange control number.
Before and after
ST*214*0002~ B10*PRO88232*5523902*XMPL~ LX*1~ AT7*X3*NS***20261021*0815*CT~ MS1*MOBILE*AL*US~ SE*6*0001~
ST*214*0002~ B10*PRO88232*5523902*XMPL~ LX*1~ AT7*X3*NS***20261021*0815*CT~ MS1*MOBILE*AL*US~ SE*6*0002~
Stop it happening again
- Write SE02 from the same variable that wrote ST02, not from a separate counter.
- Use one fixed padding format for ST02 everywhere.
- Increment the ST control number for each set in the group, and don't reuse numbers within a group.
Not sure this is your error?
Paste your 997, TA1, rejected file, or the broker's error email into the free EDI Reject Checker. It decodes every AK3/AK4/AK5/AK9 and TA1 code and checks counts, control numbers, and dates in seconds. It runs in your browser, so nothing is uploaded.
Fix reports are paid up front; if we can't find the cause, the refund is automatic.
References
- X12, Transaction Sets (997 Functional Acknowledgment)
- Element 718, Transaction Set Syntax Error Code (codes 3 and 23)
- SE segment, 004010 (SE02, element 329)