azoner/pyx12

ST_LOOP does not work in x12xml

Closed this issue · 4 comments

Multiple ST/SE's are not parsed in x12xml.
Got this error while processing EDI 832. Tests using sample 820 and 830 (maps present in pyX12) results in the same.

Some pointers on source of the issue would be helpful. Will certainly contribute back on fix.

It is parsed as -
<loop id='GS_LOOP'> <seg id='GS'> <ele id='GS01'>XX</ele> <ele id='GS02'>XXXXXXXXXX</ele> <ele id='GS03'>XXXXXXXXX</ele> <ele id='GS04'>20121228</ele> <ele id='GS05'>XXXX</ele> <ele id='GS06'>XXXX</ele> <ele id='GS07'>X</ele> <ele id='GS08'>004010</ele> </seg> <seg id='GS'> - This is actually ST data which should be inside ST_LOOP <ele id='GS01'>820</ele> - (832/830) <ele id='GS02'>XXXXXXX</ele> </seg> <loop id='ST_LOOP'>....

I am not able to reproduce your example. Perhaps we could start with a concrete example. From what I can see, the ST segments do repeat properly. There is only one instance of an ST loop though. Is that your complaint?

https://gist.github.com/azoner/5286718

Please have a look at these (both are 4010) -
https://gist.github.com/deepakstrigent/5291427
https://gist.github.com/deepakstrigent/5291438

For 832 the maps are newly written (included in gist). 830 is already present in pyX12
Have a look at second segment in GS_LOOP for both cases
The ST information is parsed as GS and it occurs outside of ST_LOOP

Also tried a sample 820 with the same result.

I get the same error while parsing both -

2013-04-02 16:13:35,852 ERROR No current segment in error_handler. Line:3 SEG:1 - Segment ST*832 not found.  Started at /ISA_LOOP/GS_LOOP/GS[SC]
2013-04-02 16:13:35,869 ERROR No current segment in error_handler. Line:46 SEG:3 - Mandatory segment "Transaction Set Header" (ST) missing
Traceback (most recent call last):
  File "/home/xxxx/envs/xxxx1/bin/x12xml", line 9, in <module>
    load_entry_point('pyx12==2.0.0', 'console_scripts', 'x12xml')()
  File "/home/xxxx/envs/xxxx1/local/lib/python2.7/site-packages/pyx12/scripts/x12xml.py", line 112, in main
    fd_997=None, fd_html=None, fd_xmldoc=fd_xml)
  File "/home/xxxx/envs/xxxx1/local/lib/python2.7/site-packages/pyx12/x12n_document.py", line 185, in x12n_document
    errh.close_st_loop(node, seg, src)
  File "/home/xxxx/envs/xxxx1/local/lib/python2.7/site-packages/pyx12/error_handler.py", line 318, in close_st_loop
    self.cur_st_node.close(node, seg, src)
AttributeError: 'NoneType' object has no attribute 'close'

John,
Was able to fix the above issue. Not sure how good the fix is - https://gist.github.com/deepakstrigent/5300411
Had to add the walker to stop it to throw ST not found exception.

Now single instance of ST_LOOP is definitely an issue. Again have a stop gap wrapper written around to solve it. But could it be possible to have ST_LOOP per transaction set?

This is a general issue of loop xml elements not being generated for loop repeats - not limited to ST_LOOP.