Handling X12 856 HL nesting

185 views
Skip to first unread message

Allen Minix

unread,
Oct 1, 2012, 12:00:02 PM10/1/12
to bots...@googlegroups.com
Gentlemen -

Still working with testing Bots and have hit another puzzle.  I have been successfully mapping X12 856 to XML documents where there is s single occurrence of Shipemt-Order-Package-Item at each HL level, but have not finally hit a snag when I have a document containing multiples at each level.  I am now getting Mapping root errors when I hit the second occurrence of an order.  I know that I am not taking the nesting into account in my code, but every time I try to do so it breaks.  This is what I have which worked with single occurrences:

    for lin in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL'}):
        lou = out.putloop({'BOTSID':'OrderStatus'})
        lou.put({'BOTSID':'OrderStatus','PoNumber':lin.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'PRF','PRF01':None})})
        lou.put({'BOTSID':'OrderStatus','OrderNumber':lin.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'REF','REF01':'VN','REF02':None})})
        lou.put({'BOTSID':'OrderStatus','ESD':lin.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'DTM','DTM01':'011','DTM02':None})})
        lou.put({'BOTSID':'OrderStatus','EAD':lin.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'DTM','DTM01':'017','DTM02':None})})
        lou.put({'BOTSID':'OrderStatus','Carrier':lin.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'TD5','TD503':None})})
        lou.put({'BOTSID':'OrderStatus','Waybill':lin.get({'BOTSID':'HL','HL03':'P'},{'BOTSID':'MAN','MAN02':None})})
        lou.put({'BOTSID':'OrderStatus','ShipDate':lin.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'DTM','DTM01':'011','DTM02':None})})
        lou.put({'BOTSID':'OrderStatus','InvoiceNumber':lin.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'GF','GF01':'IV','GF02':None})})
        lou.put({'BOTSID':'OrderStatus','InvoiceAmount':lin.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'GF','GF01':'IV','GF04':None})})

I had tried implementing something similar to what was discussed in this thread to no avail.

The puzzling part to me is how to handle the nested loops considering that the names of the descending levels are the same.

Thank you,

-Allen Minix

henk-jan ebbers

unread,
Oct 1, 2012, 12:27:26 PM10/1/12
to bots...@googlegroups.com
856 is not an easy message...

you are receiving 856 so to see? (rest of my mail assumes this)

this:
for lin in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL'','HL03':'O'}):
will loop over the HL's with order level.
normally the 856 level will point to each other using HL01 (Hierarchical ID Number) and HL02 (Hierarchical Parent ID)

this would be used like:
for ord in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'O'}): #loop over orders
level = ord.get({'BOTSID':'HL','HL01':None}) #get Hierarchical ID Number
out_ordernode = out.putloop({'BOTSID':'OrderHeader'})
out_ordernode.put(....) #adds thing to order header

for lin in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'I','HL02':level}): #get items that point to the Hierarchical Parent ID (for this order)
out_linenode = out_ordernode.putloop({'BOTSID':'OrderHeader'},{'BOTSID':'OrderLine'})
out_linenode.put(....) #add things to line level

hope this helps,

henk-jan
> I had tried implementing something similar to what was discussed in this thread <https://groups.google.com/forum/?fromgroups=#%21searchin/botsmail/nested/botsmail/wCGFabbmuEE/RINjQdnDR5QJ> to no avail.
>
> The puzzling part to me is how to handle the nested loops considering that the names of the descending levels are the same.
>
> Thank you,
>
> -Allen Minix
> --
>
>

Allen Minix

unread,
Oct 1, 2012, 3:45:33 PM10/1/12
to bots...@googlegroups.com
Henk-jan -

Thank you for the quick reply.  That makes sense.  I had initially tried the suggested for loop ( for lin in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL'','HL03':'O'}): )  but kept getting a syntax error.  I will try it again with additional changes and see what happens.

Thank you!

-Allen
Message has been deleted

eppye

unread,
Oct 1, 2012, 6:06:44 PM10/1/12
to bots...@googlegroups.com
mmmh, layout is magled by google groups...

this would be used like:
     for ord in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'O'}): #loop over orders
         level
= ord.get({'BOTSID':'HL','HL01':None})                     #get Hierarchical ID Number
         out_ordernode
= out.putloop({'BOTSID':'OrderHeader'})
         out_ordernode.put(....)        #adds thing to order header
 
         
for lin in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'I','HL02':level}): #get items that point to the Hierarchical Parent ID (for this order)
             out_linenode
= out_ordernode.putloop({'BOTSID':'OrderHeader'},{'BOTSID':'OrderLine'})
             out_linenode
.put(....)       #add things to line level
 
at least this is OK in webbrowser...

henk-jan

Allen Minix

unread,
Oct 2, 2012, 12:48:40 PM10/2/12
to bots...@googlegroups.com
Henk-jan -

I tried the suggested changes but am still getting the same error.  I'm now wondering if it is because of my destination syntax.  My mapping now looks like:

    for ship in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'S'}):
        out_shipnode = out.putloop({'BOTSID':'OrderStatus'})
        out_shipnode.put({'BOTSID':'OrderStatus','ESD':ship.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'DTM','DTM01':'011','DTM02':None})})
        out_shipnode.put({'BOTSID':'OrderStatus','EAD':ship.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'DTM','DTM01':'017','DTM02':None})})
        out_shipnode.put({'BOTSID':'OrderStatus','Carrier':ship.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'TD5','TD503':None})})
        out_shipnode.put({'BOTSID':'OrderStatus','ShipDate':ship.get({'BOTSID':'HL','HL03':'S'},{'BOTSID':'DTM','DTM01':'011','DTM02':None})})
        
        for ord in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'O'}):
            level = ord.get({'BOTSID':'HL','HL01':None})                                                
            out_ordernode = out.putloop({'BOTSID':'OrderStatus'})
            out_ordernode.put({'BOTSID':'OrderStatus','PoNumber':ord.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'PRF','PRF01':None})})
            out_ordernode.put({'BOTSID':'OrderStatus','OrderNumber':ord.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'REF','REF01':'VN','REF02':None})})
            out_ordernode.put({'BOTSID':'OrderStatus','InvoiceNumber':ord.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'GF','GF01':'IV','GF02':None})})
            out_ordernode.put({'BOTSID':'OrderStatus','InvoiceAmount':ord.get({'BOTSID':'HL','HL03':'O'},{'BOTSID':'GF','GF01':'IV','GF04':None})})

            for pack in inn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'P','HL02':level}):                                                               
                out_packnode = out_ordernode.putloop({'BOTSID':'OrderStatus'})                             
                out_packnode.put({'BOTSID':'OrderStatus','Waybill':pack.get({'BOTSID':'HL','HL03':'P'},{'BOTSID':'MAN','MAN02':None})})


But I am still getting the mapping root error.  I am taking a single X12 856 document from our mainframe and attempting to create 4 separate XML documents.  The structure of the 856 is as such:

HL:S
-> HL:O
    -> HL:P
        -> HL:I
HL:S
-> HL:O
    -> HL:P
        -> HL:I
-> HL:O
    -> HL:P
        -> HL:I
HL:S
-> HL:O
    -> HL:P
        -> HL:I
 
As you can see, four separate orders were generates, but two fall under a single HL:S loop.

The destination XML syntax is very "flat"  and the customer expects one file per order.  The syntax is as follows:

from bots.botsconfig import *

syntax = {}

structure = [
{ID:'OrderStatus',MIN:0,MAX:99999},
]


recorddefs = {
    'OrderStatus':
        [
        ['BOTSID', 'M', 256, 'AN'],
        ['PoNumber', 'C', 256, 'AN'],
        ['OrderNumber', 'C', 256, 'AN'],
        ['ConfirmationDate', 'C', 256, 'AN'],
        ['CancelDate', 'C', 256, 'AN'],
        ['ESD', 'C', 256, 'AN'],
        ['EAD', 'C', 256, 'AN'],
        ['Carrier', 'C', 256, 'AN'],
        ['Waybill', 'C', 256, 'AN'],
        ['OrderNote', 'C', 256, 'AN'],
        ['ShipDate', 'C', 256, 'AN'],
        ['InvoiceNumber', 'C', 256, 'AN'],
        ['InvoiceDate', 'C', 256, 'AN'],
        ['InvoiceAmount', 'C', 256, 'AN'],
        ],
    }


Is what I'm trying to do even possible?  

Thank you,

-Allen Minix

henk-jan ebbers

unread,
Oct 2, 2012, 6:36:50 PM10/2/12
to bots...@googlegroups.com
will have a look at this.
set in config.bots.ini debug=True
that will give you the line where the error occurs, a good starting point.

henk-jan

On 10/02/2012 06:48 PM, Allen Minix wrote:
> Henk-jan -
>
> forord ininn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'O'}):#loop over orders
> level =ord.get({'BOTSID':'HL','HL01':None})#get Hierarchical ID Number
> out_ordernode =out.putloop({'BOTSID':'OrderHeader'})
> out_ordernode.put(....)#adds thing to order header
>
> forlin ininn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'I','HL02':level}):#get items that point to the Hierarchical Parent ID (for this order)
> out_linenode =out_ordernode.putloop({'BOTSID':'OrderHeader'},{'BOTSID':'OrderLine'})
> out_linenode.put(....)#add things to line level
> --
>
>

henk-jan ebbers

unread,
Oct 2, 2012, 6:41:02 PM10/2/12
to bots...@googlegroups.com
if your xml syntax is like that:
is it correct that one order always contains one P(ackage), and one Package always has one I(tem)?

also: in most 856 I see HL01 and HL02 are used.
Is that also true for your 856?


henk-jan

On 10/02/2012 06:48 PM, Allen Minix wrote:
> Henk-jan -
>
> forord ininn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'O'}):#loop over orders
> level =ord.get({'BOTSID':'HL','HL01':None})#get Hierarchical ID Number
> out_ordernode =out.putloop({'BOTSID':'OrderHeader'})
> out_ordernode.put(....)#adds thing to order header
>
> forlin ininn.getloop({'BOTSID':'ST'},{'BOTSID':'HL','HL03':'I','HL02':level}):#get items that point to the Hierarchical Parent ID (for this order)
> out_linenode =out_ordernode.putloop({'BOTSID':'OrderHeader'},{'BOTSID':'OrderLine'})
> out_linenode.put(....)#add things to line level
> --
>
>

Allen Minix

unread,
Oct 5, 2012, 12:17:03 PM10/5/12
to bots...@googlegroups.com
Henk-jan -

Thanks again for your help on this.  I was out of the office for a couple of days, but now that I'm back, I have learned that the customer wanted everything shipped separately, so this scenario will never make it to production.  To answer your question, yes, it would have been single package, single item, and we do use HL01 and HL02.  Thankfully I don't have to continue down this road as the X12 856's will not have consolidated orders for this trading partner going forward.

Thank you again!

-Allen

henk-jan ebbers

unread,
Oct 5, 2012, 7:38:36 PM10/5/12
to bots...@googlegroups.com
OK!
actually the question of Dominik asked was quite similar to your question, but the answer would be harder because you are using xml.

so it will be a much simpler mapping for the 856?

kind regards,
henk-jan
> --
>
>

Reply all
Reply to author
Forward
0 new messages