Loop Section returns entire document

Comments

5 comments

  • Avatar
    Admin

    Hello,

    Which loops do you need to batch together - on file level, interchange level, group level or transaction level ?

    For small files you can do:

    var x12Stream = getFile(theFile);
    List<Loop_PO1_850> ediItems;

    using (var ediReader = new X12Reader(x12Stream, TemplateFactory.FullTemplateFactory))
    ediItems = ediReader.ReadToEnd().OfType<TS850>().SelectMany(m => m.PO1Loop).ToList();

    ediItems will then hold all PO1 loops across all groups, interchanges and 850 transactions in the file.

    For large files, as I see you must have configured splitting by loop po1 in the template, you can do:

    var x12Stream = getFile(theFile);
    List<Loop_PO1_850> po1Loops = new List<Loop_PO1_850>();

    using (var ediReader = new X12Reader(ediStream, TemplateFactory.FullTemplateFactory))
    {
    while (ediReader.Read())
    if (ediReader.Item is TS850 po)
    po1Loops.AddRange(po.PO1Loop);
    }

    po1Loops holds all PO1 loops across all interchanges, groups and 850 transactions in the file.

     

     

  • Avatar
    Jheminger

    This is helpful and moved me forward.

    Thank you for the fast response!

    Looking around the website I see many examples but, not an API documentation.

    Is there one available and can you give me a link?

    THX

  • Avatar
    Admin

    API Reference

  • Avatar
    Jheminger

    Thank you.

    When grabbing the CTT however I am getting an error ( same basic code )

    [code]

    List<Loop_CTT_850> ctt = new List<Loop_CTT_850>();

    using (var ediReader = new X12Reader(ediStream, LoadFactory, new X12ReaderSettings() { ContinueOnError = true }))
    {
    while (ediReader.Read())
    {
    var _ctt = ediReader.Item as TS850;
    if (_ctt != null)
    {
    ctt.AddRange(_ctt.CTTLoop);
    }
    }
    }

    [/code]

    I find CTTLoop in the 004010 template with Loop_CTT_850.

    I also tried just CTT.

    Thanks for any advice.

    If I can get a proof of concept to work we are definitely going to buy this tool.

  • Avatar
    Admin

    List<Loop_CTT_850> ctt = new List<Loop_CTT_850>();

    using (var ediReader = new X12Reader(ediStream, LoadFactory, new X12ReaderSettings() { ContinueOnError = true }))
    {
    while (ediReader.Read())
    {
    var _ctt = ediReader.Item as TS850;
    if (_ctt != null)
    {
    ctt.Add(_ctt.CTTLoop);
    }
    }
    }

Please sign in to leave a comment.