Translation of an error message.

Sep 18, 2013 at 5:10 PM
I frequently get the following messages;

Message: Hierarchical Loop 21 expects Parent ID 31 which did not occur preceding it.
Message: Hierarchical Loop 14 expects Parent ID 44 which did not occur preceding it.
Message: Hierarchical Loop 14 expects Parent ID 28 which did not occur preceding it.
Many others....

They are followed by a message saying I can change these to warnings, if I want.

Before I change these to a warning, I would like to work with the vendor providing the data and if they have a problem with their software, see if they can identify and correct it. In order to do that I need to be able to translate these messages into something they might understand (as well as me).

Is there something that I can reference that will translate these messages into ANSI 837/5010 terminology?
Coordinator
Sep 18, 2013 at 10:45 PM
Edited Sep 19, 2013 at 11:21 AM
See here for spec on HL: https://www.disa.org/apps/workbook/X12_October_2012/se/se_HL.htm.

The hieriarchical loop defines a unique section in a transaction (between ST and SE) segments. A transaction doesn't have to have hierarchical loops, but if it does the ID of each must be unique within the transaction and all segments following the HL segment is assumed to be part of that loop until another HL segment is encountered.
The 1st element in the HL segment is its ID, but the second element is it's parent ID and must point to another HL in the transaction.

Though it is not a hard and fast rule that the parent ID occurs before it, this is typically how it works: each HL is sequential numbered and the child HLs appear after the parent HL.

The fact that the parent ID has a higher number than the ID is suspect. This could still be a valid file if the HL segment 31 actually does occur after the HL 21. You can check the file for this first. Most likely, the file is invalid and perhaps that just reversed the ID and parent ID. The fact that you have Loop 14 throwing an exception that it has parent 44 and parent 28 is also suspect. The loop should only have one parent, thus it's hierarchical.
Sep 19, 2013 at 1:55 PM
Dannie, thanks again for your timely help and patience with a dilettante.

I am working on a program that will generate readable output for these files that have issues. I think I would like to create HTML. I was going to use your example (converted to VB of course);
 var htmlService = new X12HtmlTransformationService(new X12EdiParsingService(suppressComments: false));

  Stream ediFile = new FileStream("c:\\5010_Example1_HealthInsurance.txt", FileMode.Open, FileAccess.Read);

  string html = htmlService.Transform(new StreamReader(ediFile).ReadToEnd());
Is there a way of passing the parameter to convert the errors into warnings to X12HtmlTransformationService? so that I would get HTML that looks reasonable for a file with these types of syntax errors?
Sep 19, 2013 at 2:45 PM
I have a second question regarding the HTML generation program I am trying to write. How do I pass the "encoding" parameter? Some of my files are UNICODE, and some are UTF8. Here is my code so far;
Imports System.IO
Imports OopFactory.X12.Parsing
Imports OopFactory.X12.Transformations

Module Module1

    Sub Main()
        Dim strArgument As String
        Dim aryArgument As Array
        Dim strInputFile As String = ""
        Dim strOutputFile As String = ""
        For Each strArgument In Environment.GetCommandLineArgs()
            '            Console.WriteLineLine(strArgument)
            aryArgument = strArgument.Split("=")
            Select Case aryArgument(0).ToString.ToLower
                Case "inputfile"
                    strInputFile = aryArgument(1)
                Case "outputfile"
                    strOutputFile = aryArgument(1)
            End Select
        Next strArgument
        If strOutputFile = "" _
        Then
            strOutputFile = strInputFile.Substring(0, strInputFile.LastIndexOf(".")) & ".html"
        End If

        Dim fsTemp As FileStream = New FileStream(strInputFile, FileMode.Open)
        Dim strHeader(106) As Byte
        fsTemp.Read(strHeader, 0, 106)
        fsTemp.Close()
        fsTemp.Dispose()
        fsTemp = Nothing
        Dim bolChunkified As Boolean = False
        If strHeader(105) <> 13 And strHeader(105) <> 10 _
        Then
            For i = 0 To 104
                bolChunkified = (bolChunkified Or (strHeader(i) = 10 Or strHeader(i) = 13))
            Next
        End If
        Dim encoding As Text.Encoding
        Dim strEncoding As String
        If (strHeader(1) = 0 And strHeader(3) = 0 And strHeader(5) = 0) _
        Then
            encoding = Text.Encoding.Unicode
            strEncoding = "UNICODE"
        Else
            encoding = Text.Encoding.UTF8
            strEncoding = "UTF8"
        End If

        Dim inStream As FileStream

        inStream = New FileStream(strInputFile, FileMode.Open, FileAccess.Read)
        Dim rdrTemp As StreamReader = New StreamReader(inStream)
        Dim strTemp As String = rdrTemp.ReadToEnd
        inStream.Close()
        inStream.Dispose()
        inStream = Nothing
        If bolChunkified _
        Then
            strTemp = Replace(Replace(strTemp, vbCr, ""), vbLf, "")
        End If
        Dim baTemp As Byte()
        baTemp = Text.Encoding.UTF8.GetBytes(strTemp)
        Dim memStream As New MemoryStream(baTemp)

        Dim htmlService = New X12HtmlTransformationService(New X12EdiParsingService(suppressComments:=False))
        Dim strHTML As String = htmlService.Transform(New StreamReader(memStream).ReadToEnd())
        Dim objWriter As New System.IO.StreamWriter(strOutputFile)
        objWriter.Write(strHTML)
    End Sub

End Module
It bombs saying "First segment must start with ISA" because the file I am trying to process is UNICODE. I have the code to identify if it is unicode, but I don't know how to get it to the parser.
Sep 23, 2013 at 1:35 PM
Dannie, is what I am trying to do (get an HTML view of a file with syntax errors) reasonable?
Oct 2, 2013 at 1:48 PM
Dannie, Is there a way to produce the HTML version of the ANSI-837 file using your API with the following conditions?

A) The incoming file is unicode, not utf-8.
B) The file has syntax errors, specifically Loop Hierarchy errors.

If there is documentation that I can read that defines how to call the API to do what I need, I will gladly read it, just tell me where to go:)