Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem parsing - ideas needed #51

Closed
irobayna opened this issue Aug 17, 2014 · 4 comments
Closed

Problem parsing - ideas needed #51

irobayna opened this issue Aug 17, 2014 · 4 comments

Comments

@irobayna
Copy link
Collaborator

When I first implemented message RA 820 v3010, I was getting lots of non-deterministic problems and with your guidance we collapse some loops and items and both tools: edi-pp and edi-ed parse the data correctly.

My problem is that if I manually traverse the tree, I get to a loop of N1 items which belong to a particular segment and the parser parses all the N1 not just the ones that belong to the parent.

Here is my code:

      edi_data.first.flatmap do |isa|
        isa.iterate(:GS) do |gs|
          gs.iterate(:ST) do |st|
            gs.find(:ST).flatmap{|x| x.find(:BPS) }
            .tap do |bps|
            end
            gs.find(:ST).flatmap{|x| x.find(:REF,'R2') }
            .tap do |ref|
            end
            gs.find(:ST).flatmap{|x| x.find(:DTM) }
            .tap do |dtm|
            end
            gs.find(:ST).flatmap{|x| x.find(:N1,'SU') }
            .tap do |n1|
            end
            gs.find(:ST).flatmap{|x| x.find(:LS,'A') }
            .tap do |ls|
              ls.iterate(:N1, 'HH') do |n1|
                puts "N1 HH #{n1.element(2).map(&:node).fetch(0)}"
                n1.find(:N1, 'HH').flatmap{|x| x.find(:RMT,'IV') }
                .tap do |rmt|
                 @seller_invoice_number  = "#{rmt.element(2).map(&:node).fetch(0)}"
                  @total_gross_amount     = "#{rmt.element(3).map(&:node).fetch(0)}"
                  puts "RMT IV [$#{@total_gross_amount}] #{@seller_invoice_number}"
                  puts "==========================="
             end
                  n1.iterate(:N1, 'LI') do |n11|
                    puts "N1 LI #{n11.element(2).map(&:node).fetch(0)}"
                  end

The problem is on the last item N1 LI which it iterates through all the LI on the file, not the ones just belonging to the parent N1

@irobayna
Copy link
Collaborator Author

@kputnam I have tried the last two days to recreate the guide and transaction set definition for message RA820 as out of the messages I have implemented the one that appears to not be behaving correctly (the parsing that is). If I follow the implementation details as per the guide I get non deterministic and edi-pp never returns even with -N so I have end up back where I started.

When originally implementing this message we were getting a lot of NonDeterministic errors and you suggested collapsing some loops. This worked in the sense edi-pp is able to parse the message correctly. But somehow when I traverse the tree I get odd results. My main concern is getting the N1 LI segments in order that are associated with N1 HH segment

@kputnam
Copy link
Owner

kputnam commented Aug 26, 2014

Can you email me a sample document and tell me which branch you're working in? I have a vague understanding of the problem but not enough to troubleshoot.

@kputnam
Copy link
Owner

kputnam commented Aug 26, 2014

PS: In your example you're looping over ST segments, but in the body of the loop you are discarding the "current" ST segment and re-finding the first ST after GS each time. Instead of gs.find(:ST) should you be referring to st instead?

@kputnam
Copy link
Owner

kputnam commented Aug 26, 2014

This example seems unusual to me, so let me know if I've misunderstood. Here's my translation:

First, start at GS and then find ST, from here find LS*A. From LS*A, loop over each N1*HH occurrence, call it n1, and print out it's second element. Then from this n1 find the _next_ N1*HH called x, and from here find the next occurrence of RMT*IV.

Print the RMT segment's second and third element and start the loop over. When the loop starts again, it will find the N1*HH segment we previously called x, but it will be known as n1 in this iteration.

            gs.find(:ST).flatmap{|x| x.find(:LS,'A') }
            .tap do |ls|
              ls.iterate(:N1, 'HH') do |n1|
                puts "N1 HH #{n1.element(2).map(&:node).fetch(0)}"
                n1.find(:N1, 'HH').flatmap{|x| x.find(:RMT,'IV') }
                .tap do |rmt|
                 @seller_invoice_number  = "#{rmt.element(2).map(&:node).fetch(0)}"
                  @total_gross_amount     = "#{rmt.element(3).map(&:node).fetch(0)}"
                  puts "RMT IV [$#{@total_gross_amount}] #{@seller_invoice_number}"
                  puts "==========================="
             end

I suspect you have one too many traversals, and n1.find(:N1, 'HH').flatmap{|x| x.find(:RMT, 'IV' } should be instead n1.find(:RMT, 'IV'), but I might be mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants