« BizTalk EDI Validation Errors: Invalid Character | Nested loops to Single Loop » |
Understanding X12 error messages in BizTalk
Understanding errors that occur when parsing X12 messages is difficult even if you understand X12 syntax rules, and extremely difficult when you have little or no experience with X12 standards.
This blog entry examines a few common errors that occur when parsing X12 messages in BizTalk and explains why they occur and offers possible solutions. We use the properly formed transaction below, an X12 855 PO Acknowledgement. This is a simple instance of an X12 message.
ST*855*000000001
BAK*00*AD*P439254*20100204
PO1*1*4*CA***IN*5710503
PID*F****BULK S1050
PO1*2*25*CA***IN*5710503
PID*F****BULK S1050
PO1*3*8*CA***IN*5710503
PID*F****BULK S1050
PO1*4*16*CA***IN*5710503
PID*F****BULK S1050
PO1*5*1*CA***IN*5710503
PID*F****MT ELITE S309
PO1*6*1*CA***IN*5710503
PID*F****NO POWDER S860
CTT*6
SE*16*000000001
ERROR ONE
The first error we will introduce is one of the most, if not the most, common parsing error occurring with X12 -- the Invalid Code error. To cause the error, we will change the BAK segment by replacing the valid code "00" with the invalid code "xx".
BAK*xx*AD*P439254*20100204
When we pass the modified 855 through the EDI pipeline we get the error message:
Invoking component...
LINE 1: E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855badcode.edi: error BEC2004: Non Segment level: [5] >X12_00401_855\\BAK\\BAK01\\ The element has an invalid value according to its data type.
LINE 2: E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855badcode.edi: error BEC2004: Segment level : Segment ID - BAK : Position - 2 [8] Segment Has Data Element Errors
LINE 3: E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855badcode.edi: error BEC2004: Segment level : Field Error : Segment ID - BAK : Field Position - 1 Current value - xx [7] Invalid code value
LINE 4: E:\\SOLUTIONS\\BLOG\\X12Errors\\X12_00401_855.xsd: error BEC2004: Validate Instance failed for schema X12_00401_855.xsd, file: <file:///E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855badcode.edi>
Component invocation succeeded.
Line numbers (e.g., LINE 1:) were added for clarity.
Lines 1-3 of the error each contain a number in brackets -- [5], [8], and [7] to be specific. These numbers identify the error message string. They do not apply to the X12 transaction, nor are they useful in resolving the error.
LINE 1 tells us that the error is at the segment level ("Non Segment level". This means that the problem is with an X12 element. LINE 1 also identifies the name of the element in which the error occurs ("BAK01") and indicates that element contains an ("invalid value according to its data type"). This is a misleading statement, since the value in the BAK01 is the correct data type.
LINE 2 identifies the specific BAK segment that contains the error by giving the position of the segment in the message ("BAK : Position - 2"). This indicates that the error occurred in the second segment in the message.
LINE 3 gives us the specific error. The element affected is the first element in the segment ("Field Postion - 1") . The error is that the value in that element is invalid ("[7] Invalid Code Value"). Finally, the error indicates that the value in the element is ("xx").
LINE 4 is extraneous text that serves no real value as it provides no information pertinent to the error (except the filename path, which is also given in every other line).
Fundamentally then, this error listing says this 855 message contained a BAK segment in the second line of the message which contained an invalid code value of ("xx") in the first element (BAK01.)
So what does that mean? In X12, some elements are limited as to which values they may contain. The BAK01 is one such element. You can see the acceptable values by looking at the (Collection) list under Enumeration in the element properties in the schema. Your choices for repairing this problem are either to put a valid value in that field in the message or to add the invalid value to the code list.
ERROR TWO
Now let''s remove the BSN segment and see what happens. The message now appears:
ST*855*000000001
PO1*1*4*CA***IN*5710503
PID*F****BULK S1050
PO1*2*25*CA***IN*5710503
PID*F****BULK S1050
PO1*3*8*CA***IN*5710503
PID*F****BULK S1050
PO1*4*16*CA***IN*5710503
PID*F****BULK S1050
PO1*5*1*CA***IN*5710503
PID*F****MT ELITE S309
PO1*6*1*CA***IN*5710503
PID*F****NO POWDER S860
CTT*6
SE*16*000000001
When we validate the this 855 we get the following error:
Invoking component...
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855 missingseg.edi: error BEC2004: Non Segment level : [4] Number of included segments do not match
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855 missingseg.edi: error BEC2004: Non Segment level: [5] X12_00401_855\\ The element ''X12_00401_855'' in namespace ''http://schemas.microsoft.com/BizTalk/EDI/X12/2006'' has invalid child element ''PO1Loop1'' in namespace ''http://schemas.microsoft.com/BizTalk/EDI/X12/2006''. List of possible elements expected: ''http://schemas.microsoft.com/BizTalk/EDI/X12/2006:BAK''.
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855 missingseg.edi: error BEC2004: Segment level: Segment ID - BAK : Position - 2 : [3] Mandatory Segment Missing
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855 missingseg.edi: error BEC2004: Segment level : Segment ID - PO1 : Position - 2 : [2] Unexpected segment
E:\\SOLUTIONS\\BLOG\\X12Errors\\X12_00401_855.xsd: error BEC2004: Validate Instance failed for schema X12_00401_855.xsd, file: file:///E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855missingseg.edi>
Component invocation succeeded.
Frankly, this error message is difficult to interpret because only one of the five lines actually refers to the specific issue that caused this error.
Line 1 tells us that an error occurred at the element level ("Non Segment level") and that the error was ("[4] Number of included segments do not match"). The error message does not tell you what caused this or where the problem is.
You must understand X12 syntax in order to interpret this statement. X12 syntax requires the SE01 element to contain the count of the number of segments in the message, from ST to SE, inclusive. In this case, the SE01 contains the value ("16") but due to the missing BSN segment there are only fifteen segments in the message
Line 2 adds to the confusion as it also reports a secondary error, ("invalid child element ''POLoop1''"). The PO1Loop1 element is not a valid construct in the X12 message but is a node in the XML schema. Here is where an X12 knowledgeable person may become confused as this error does not reference the contents of the 855
At this point, nothing has pointed to the exact error in the 855. Line 3 is the first line that does so. Line 3 states precise information about the error. First, the type of error is identified as ("[3] Mandatory Segment Missing"). Second, the location of the missing segment is given as ("Position - 2"), indicating that the missing segment should have been the second line in the 855. Finally the name of the missing segment ("BAK") is provided.
Line 4 reports another secondary error, the X12 version of the XML error reported in Line 2. Line 4 tells us that the PO1 segment found in line two 0f the 855 should not be there ("Segment ID - PO1 : Position - 2 : [2] Unexpected segment").
<p>Line five is superfluous.
Why the confusing list of errors? Well, BizTalk tries to report all errors found in a message. Some engines stop parsing at the first error; others are able to report all errors correctly. BizTalk does not take into account previously discovered errors when continuing to parse the message and report errors. Once the mandatory BAK segment is found to be missing, BizTalk should report this error and then continue to parse the 855 as if the BAK were there.
Note that an error such as this must be reported to the sending party so that they can resubmit the 855.
ERROR THREE
Finally, let''s modify the fifth PID segment in the 855 so that a mandatory element is missing. The new PID is:
PID*****MT ELITE S309
And here is the error produced when we run the 855 with this segment:
Invoking component...
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855missingele.edi: error BEC2004: Non Segment level : [5] X12_00401_855\\PO1Loop1\\PIDLoop1\\PID_2\\ The element ''PID_2'' in namespace ''http://schemas.microsoft.com/BizTalk/EDI/X12/2006'' has invalid child element ''PID05''. List of possible elements expected: ''PID01''.
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855missingele.edi: error BEC2004: Segment level: Segment ID - PID : Position - 12 : [8] Segment Has Data Element Errors
E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855missingele.edi: error BEC2004: Segment level: Field Error : Segment ID - PID : Field Position - 1 : Current value - : [1] Mandatory data element missing
E:\\SOLUTIONS\\BLOG\\X12Errors\\X12_00401_855.xsd: error BEC2004: Validate Instance failed for schema X12_00401_855.xsd, file: <file:///E:\\SOLUTIONS\\BLOG\\X12Errors\\Sample855missingele.edi>.
Component invocation succeeded.
Line 1 almost gets the error correct, but not quite. The line indicates that the error is at the element level ("Non Segment Level"), that the error occurs in a PID segment ("[5] X12_00401_855\\PO1Loop1\\PIDLoop1\\PID_2"), and that the error is that an ("invalid child element") was found and that this element was a ("PID05") . Oops, this last is incorrect. All the PID05 elements in this 855 are correct. Line 1 does state that the ("PID01 was expected"), but this is a poorly stated. Notice that the XML path is reported rather than using the X12 syntax, which adds confusion.
Line 2 is a simple, correct statement. It says that the PID segment ("Segment ID - PID"), the 12th segment ("Position - 12") in the 855, has an error in one or more of its data elements ("[8] Segment has data element errors").
Line 3 says that the first element ("Field Position - 1") of the subject PID segment is the problem in that the elment is mandatory but missing ("Mandatory data element missing"). However, line 3 throws in a very confusing statement by saying that the current value is...well, who knows? The problem is that the statement ("current value -") does not give a current value. Of course that is because there is no value in the element. Because Line 3 doesn't show an empty value, many folks read the line incorrectly as ("current value - [1]") which seems to say that the bad value is "1". That is a problem with the syntax of the error message.
Line 4 is superfluous.
SUMMARY
These three examples show how difficult reading the error messages may be. You can make the process easier by:
- Never assuming that the error message lines are in the correct order.
Never assuming that all the lines are related to the same error.
Always reading through all lines to identify the actual error that has occurred.
Being cautious of the "current value -" problem where there is no value.