This project has moved and is read-only. For the latest updates, please go here.

Is this the most efficient way to process all the LIN segments in an 832 file?

Nov 7, 2013 at 2:47 AM
Edited Nov 7, 2013 at 2:51 AM
I have to deal with large price files and have the parsing working but would appreciate any input as to if this is the most efficient way to process the line item segments in an 832 file. No error checking here since just a minimal example. Mostly want to make sure I am not causing the file to be parsed more than once by accessing the CTT segment and then processing the LIN segments, since I have no idea if the entire file is pre-parsed into memory or not. Thanks, Dave
        // get the x12 Interchanges
        List<Interchange> lInterchanges = lParser.ParseMultiple(fstream); // there is normally only one Interchange?

    // process each Interchange
        foreach (Interchange lInterchange in lInterchanges)
            FunctionGroup lFirstFunctionGroup = lInterchange.FunctionGroups.First();
            Transaction lFirstTransaction = lFirstFunctionGroup.Transactions.First();
            // should return lots of segments from the LIN loop
            var lLinSegments = lTransactionSegments.Where(s => s.SegmentId == "LIN");
            // transaction total should match the count of LIN segments
            var lCttSegment = lTransactionSegments.Where(s => s.SegmentId == "CTT");

            // check the LIN segment count is accurate
            int lLinCount = lLinSegments.Count();
            int lCttTotalCount = int.Parse(lCttSegment.First().GetElement(1)); // no 0 element
            if (lLinCount != lCttTotalCount)
                AppSupport.WriteLog(LogLevel.Error, "LIN segment count '{0}' does not match total transaction count '{1}'.", lLinSegments.Count(), lCttTotalCount);

            foreach (Segment lLinSegment in lLinSegments)
                var lFirstLinSegmentElement1 = lLinSegment.GetElement(1);
                var lFirstLinSegmentElement2 = lLinSegment.GetElement(2);
                var lFirstLinSegmentElement3 = lLinSegment.GetElement(3);
                var lFirstLinSegmentElement4 = lLinSegment.GetElement(4);
                var lFirstLinSegmentElement5 = lLinSegment.GetElement(5);
                var lFirstLinSegmentElement6 = lLinSegment.GetElement(6);
                var lFirstLinSegmentElement7 = lLinSegment.GetElement(7);

                // do something with the LIN segment elements!
Nov 7, 2013 at 3:00 PM
According to, the LIN is a loop under the transaction, so you would probably need to loop through the child loops to get to the LIN segments.

You could also try loading the file into a SQL server database with the ImportX12 tool.
Nov 7, 2013 at 3:33 PM
I need to use the object model for various reasons so don't want to use any command line tool.

I actually get all the LIN segments just fine. My concern is if I'm causing the x12 file to be parsed more than once since I fetched the CTT segment to check the count before processing the LIN segments.

Thanks, Dave