back-collision in edifact 96A ( no UNS or CNT in message)

123 views
Skip to first unread message

Angelo de Laat

unread,
May 16, 2013, 4:08:25 PM5/16/13
to bots...@googlegroups.com
Hi,

I`m looking for a way to process a message that does not have UNS or CNT.

message:

UNBUNOA3                                   14                2090100000015                      14                1304221445000001                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
BGM380                                         610809                             9  NA                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
DTM13720130422                           102                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
RFFON test EDI                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
NADBY 2090100000015                         9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
NADIV 2090100000015                         9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
NADDP 2090100000015                         9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
CUX2  EUR4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
PAT22                                                                                              5  3  D   30                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
LIN1        02090100000022                     EN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
QTY47               5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
QTY12               5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
MOA203             15.00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
PRIINV        3000.00           1000PCE                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
TAX7  VAT                                                                                 21.00                              S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
LIN2        02090100000039                     EN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
QTY47              10                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
QTY12              10                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
MOA203            350.00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
PRIINV       35000.00           1000PCE                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
TAX7  VAT                                                                                 21.00                              S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
LIN3        02090100000046                     EN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
QTY47               2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
QTY12               2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
MOA203             20.00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
PRIINV       10000.00           1000PCE                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
TAX7  VAT                                                                                 21.00                              S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
MOA79             385.00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
MOA176             80.85                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
MOA77             465.85                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
TAX7  VAT                                                                                 21.00                              S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
MOA125            385.00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
MOA124             80.85   

I have a problem with the LIN ALC segment.
Because the UNB LIN ALC segment as TAX and MOA just as the UNB i would like to let it out.
But when i remove it from the structure (Edifact96A) i get TypeError: unsupported operand type(s) for +: 'int' and 'list'

I have made the LIN PRI and LIN TAX mandatory
But between the LIN TAX and the UNB MOA i have no other segment to use as a mandatory segmet / separator.

    {ID: 'LIN', MIN: 1, MAX: 9999999, LEVEL: [
       
{ID: 'PIA', MIN: 0, MAX: 25},
       
{ID: 'IMD', MIN: 0, MAX: 10},
       
{ID: 'MEA', MIN: 0, MAX: 5},
       
{ID: 'QTY', MIN: 1, MAX: 5},
       
{ID: 'PCD', MIN: 0, MAX: 1},
       
{ID: 'ALI', MIN: 0, MAX: 5},
       
{ID: 'DTM', MIN: 0, MAX: 35},
       
{ID: 'GIN', MIN: 0, MAX: 1000},
       
{ID: 'GIR', MIN: 0, MAX: 1000},
       
{ID: 'QVR', MIN: 0, MAX: 1},
       
{ID: 'EQD', MIN: 0, MAX: 1},
       
{ID: 'FTX', MIN: 0, MAX: 5},
       
{ID: 'MOA', MIN: 1, MAX: 5, LEVEL: [
           
{ID: 'CUX', MIN: 0, MAX: 1},
       
]},
       
{ID: 'PAT', MIN: 0, MAX: 10, LEVEL: [
           
{ID: 'DTM', MIN: 0, MAX: 5},
           
{ID: 'PCD', MIN: 0, MAX: 1},
           
{ID: 'MOA', MIN: 0, MAX: 1},
       
]},
       
{ID: 'PRI', MIN: 1, MAX: 25, LEVEL: [
           
{ID: 'APR', MIN: 0, MAX: 1},
           
{ID: 'RNG', MIN: 0, MAX: 1},
           
{ID: 'DTM', MIN: 0, MAX: 5},
       
]},
       
{ID: 'RFF', MIN: 0, MAX: 10, LEVEL: [
           
{ID: 'DTM', MIN: 0, MAX: 5},
       
]},
       
{ID: 'PAC', MIN: 0, MAX: 10, LEVEL: [
           
{ID: 'MEA', MIN: 0, MAX: 10},
           
{ID: 'PCI', MIN: 0, MAX: 10, LEVEL: [
               
{ID: 'RFF', MIN: 0, MAX: 1},
               
{ID: 'DTM', MIN: 0, MAX: 5},
               
{ID: 'GIN', MIN: 0, MAX: 10},
           
]},
       
]},
       
{ID: 'LOC', MIN: 0, MAX: 9999, LEVEL: [
           
{ID: 'QTY', MIN: 0, MAX: 100},
           
{ID: 'DTM', MIN: 0, MAX: 5},
       
]},
       
{ID: 'TAX', MIN: 1, MAX: 99, LEVEL: [
           
{ID: 'LOC', MIN: 0, MAX: 5},
       
]},
       
{ID: 'NAD', MIN: 0, MAX: 20, LEVEL: [
           
{ID: 'LOC', MIN: 0, MAX: 5},
           
{ID: 'RFF', MIN: 0, MAX: 5, LEVEL: [
               
{ID: 'DTM', MIN: 0, MAX: 5},
           
]},
           
{ID: 'DOC', MIN: 0, MAX: 5, LEVEL: [
               
{ID: 'DTM', MIN: 0, MAX: 5},
           
]},
           
{ID: 'CTA', MIN: 0, MAX: 5, LEVEL: [
               
{ID: 'COM', MIN: 0, MAX: 5},
           
]},
       
]},
       
{ID: 'ALC', MIN: 0, MAX: 1, LEVEL: [
           
{ID: 'ALI', MIN: 0, MAX: 5},
           
{ID: 'DTM', MIN: 0, MAX: 5},
           
{ID: 'QTY', MIN: 0, MAX: 1, LEVEL: [
               
{ID: 'RNG', MIN: 0, MAX: 1},
           
]},
           
{ID: 'PCD', MIN: 0, MAX: 1, LEVEL: [
               
{ID: 'RNG', MIN: 0, MAX: 1},
           
]},
           
{ID: 'MOA', MIN: 0, MAX: 2, LEVEL: [
               
{ID: 'RNG', MIN: 0, MAX: 1},
           
]},
           
{ID: 'RTE', MIN: 0, MAX: 1, LEVEL: [
               
{ID: 'RNG', MIN: 0, MAX: 1},
           
]},
           
{ID: 'TAX', MIN: 0, MAX: 5, LEVEL: [
               
{ID: 'MOA', MIN: 0, MAX: 1},
           
]},
       
]},
       
{ID: 'TDT', MIN: 0, MAX: 10, LEVEL: [
           
{ID: 'LOC', MIN: 0, MAX: 10, LEVEL: [
               
{ID: 'DTM', MIN: 0, MAX: 5},
           
]},
       
]},
       
{ID: 'TOD', MIN: 0, MAX: 5, LEVEL: [
           
{ID: 'LOC', MIN: 0, MAX: 2},
       
]},
       
{ID: 'RCS', MIN: 0, MAX: 100, LEVEL: [
           
{ID: 'RFF', MIN: 0, MAX: 5},
           
{ID: 'DTM', MIN: 0, MAX: 5},
           
{ID: 'FTX', MIN: 0, MAX: 5},
       
]},
   
]},
   
{ID: 'UNS', MIN: 0, MAX: 1},
   
{ID: 'CNT', MIN: 0, MAX: 10},
   
{ID: 'MOA', MIN: 1, MAX: 100, LEVEL: [
       
{ID: 'RFF', MIN: 0, MAX: 1, LEVEL: [
           
{ID: 'DTM', MIN: 0, MAX: 5},
       
]},
   
]},
   
{ID: 'TAX', MIN: 1, MAX: 10, LEVEL: [



For now i just translate it to xmlnocheck based on the plugin demo_one-on-one_edifactorder2xml_20130127-1 because i dont have a mapping.

How can i solve this issue.

kr,
angelo

Angelo de Laat

unread,
May 16, 2013, 4:12:21 PM5/16/13
to bots...@googlegroups.com
http://wiki.bots.googlecode.com/hg-history/a8994abe7e5b11f17e3ef3ca377b34a3ad93df3f/GrammarsHowToGet.wiki
Also this (old wiki) link was very helpful, it would be nice to add this to the new wiki with some extra howto's.


Angelo de Laat

unread,
May 16, 2013, 4:39:10 PM5/16/13
to bots...@googlegroups.com
I just tried to replace MOA79 with UNS /r/n MOA79 using the routescript but this is not a very elegant solution also it does not gives me the result i expected.
generates TypeError: unsupported operand type(s) for +: 'int' and 'list' again.
hmmmm....

henk-jan ebbers

unread,
May 16, 2013, 5:34:48 PM5/16/13
to bots...@googlegroups.com
I once started to document this. I stopped with it ( I documented the easy parts...)
it is dreadful to explain, unless you really understand the limitations of hierarchic nested record structures.
(this has nothing to do with bots. there are edifact and x12 messages with this type of errors errors in them.)


that is why I advise you to use a decent grammar, these are available as downloads.
I took a look at the grammar you are using. there are multiple errors in it. please: dump it.

kind regards,
henk-jan



On 05/16/2013 10:12 PM, Angelo de Laat wrote:
> http://wiki.bots.googlecode.com/hg-history/a8994abe7e5b11f17e3ef3ca377b34a3ad93df3f/GrammarsHowToGet.wiki
> Also this (old wiki) link was very helpful, it would be nice to add this to the new wiki with some extra howto's.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Angelo de Laat

unread,
May 17, 2013, 4:30:43 AM5/17/13
to bots...@googlegroups.com
Hj,

I already did and now use the default EDIFACT 96A INVOIC grammar downloaded from the bots grammar section.
I have changed the UNH to UNB and removed the UNT because this is an internal edifact invoic.

After going deep into the edifact message i found out i have an issue with the LIN ALC MOA and LIN ALC TAX.

As you can see in my internal message i have
LIN
QTY
MOA
PRI
TAX
MOA
TAX
MOA

the default grammar has
UNB
LIN
QTY
MOA
PRI
TAX
ALC
MOA
TAX
MOA
UNS
CNT
MOA
TAX
MOA
UNT

since the ALC is optional the MOA and TAX MOA can be part of the ALC (UNB LIN ALC MOA & UNB LIN ALC TAX MOA) and be part of the UNB MOA, UNB TAX MOA

So i need to define a mandatory separator as provided in example 1 explained in the wiki or remove the UNB LIN ALC.
If i remove the ALC, i get TypeError: unsupported operand type(s) for +: 'int' and 'list' again.
If i add a separator using preprocessing i get the same error.

kr,
angelo

Angelo de Laat

unread,
May 17, 2013, 5:30:12 AM5/17/13
to bots...@googlegroups.com
here are the grammar, incoming files and translation in a plugin.

plugin_fixed_inhouse_to_xml.zip

henk-jan ebbers

unread,
May 17, 2013, 6:10:42 AM5/17/13
to bots...@googlegroups.com
yes, I see the problem.
within the edifact message, the UNS is needed....they stripped it.
so they use the actual information (that we stripped away via preprocessing)

have to think about, what is best solution.


kind regards,
henk-jan

henk-jan ebbers

unread,
May 20, 2013, 6:07:18 AM5/20/13
to bots...@googlegroups.com

angelo,

there are 2 ways to go:
1. use the grp_28 information to set up a grammar. You would need some preprocessing in order to have grp-information as a fixed length field. ( Grp25_QTY would be the qualifier)
(too much work)
2. change the preprocessing slightly to inset a UNS segment. This could be done with the Grp-information
(I think I would go for this one. Test it by inseting the UNS manually, see if that solves the problem)
3. change the grammar making assumptions/using knowledge of the inhouse message

This grammar:
LIN
QTY
MOA
PRI
TAX(1)
MOA
TAX
MOA
If you are absoluty sure PRI is always there, make it mandatory. Should solve the collision.
Same is true for TAX (1)
(I always try to make as few assumptions about this sort of things as possible. There might be less common situations where you assumptions fail, eg article without price (in PRI))


hope this helps,
henk-jan



On 05/17/2013 11:30 AM, Angelo de Laat wrote:
> here are the grammar, incoming files and translation in a plugin.
>

Angelo de Laat

unread,
May 21, 2013, 3:48:43 PM5/21/13
to bots...@googlegroups.com
HJ,

I also went for the second option.
so i changed the first segment below the UNS in the routescript

        for line in fromfile:
           
if not line.strip():
               
continue
            chunks
= textwrap.wrap(line, 640,replace_whitespace=False, expand_tabs=False, drop_whitespace=False)
            lines
= "\r\n".join([chunk.partition('_')[2] for chunk in chunks])
            lines
=lines.replace('MOA79', 'UNS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       \r\nMOA79')
            tofile
.write(lines)

i updated the grammar and in short it looks like this.

{ID: 'UNB', MIN: 1, MAX: 1, LEVEL: [

   
{ID: 'LIN', MIN: 1, MAX: 9999999, LEVEL: [

       
{ID: 'QTY', MIN: 1, MAX: 5},

       
{ID: 'MOA', MIN: 1, MAX: 5, LEVEL: [
           
{ID: 'CUX', MIN: 0, MAX: 1},
       
]},

       
{ID: 'PRI', MIN: 1, MAX: 25, LEVEL: [
           
{ID: 'APR', MIN: 0, MAX: 1},
           
{ID: 'RNG', MIN: 0, MAX: 1},
           
{ID: 'DTM', MIN: 0, MAX: 5},
       
]},

       
{ID: 'TAX', MIN: 1, MAX: 99, LEVEL: [
           
{ID: 'LOC', MIN: 0, MAX: 5},
       
]},

   
{ID: 'UNS', MIN: 1, MAX: 1},

   
{ID: 'CNT', MIN: 0, MAX: 10},
   
{ID: 'MOA', MIN: 1, MAX: 100, LEVEL: [
       
{ID: 'RFF', MIN: 0, MAX: 1, LEVEL: [
           
{ID: 'DTM', MIN: 0, MAX: 5},
       
]},
   
]},
   
{ID: 'TAX', MIN: 1, MAX: 10, LEVEL: [

       
{ID: 'MOA', MIN: 0, MAX: 2},
   
]},



all others are set to MIN: 0

This gives me the right result (as also posted in third message) this solves the collision error but i still have the error TypeError: unsupported operand type(s) for +: 'int' and 'list' again.
What does this mean and how can i solve this?

henk-jan ebbers

unread,
May 22, 2013, 10:28:39 AM5/22/13
to bots...@googlegroups.com
can you provide a plugin for this?

kind regards,
henk-jan

On 05/21/2013 09:48 PM, Angelo de Laat wrote:
> HJ,
>
> I also went for the second option.
> so i changed the first segment below the UNS in the routescript
>
> |
> forline infromfile:
> ifnotline.strip():
> continue
> chunks =textwrap.wrap(line,640,replace_whitespace=False,expand_tabs=False,drop_whitespace=False)
> lines ="\r\n".join([chunk.partition('_')[2]forchunk inchunks])
> lines=lines.replace('MOA79','UNS \r\nMOA79')
> tofile.write(lines)
>
> |
> i updated the grammar and *in short* it looks like this.
>
> |
> {ID:'UNB',MIN:1,MAX:1,LEVEL:[
> {ID:'LIN',MIN:1,MAX:9999999,LEVEL:[
> {ID:'QTY',MIN:1,MAX:5},
> {ID:'MOA',MIN:1,MAX:5,LEVEL:[
> {ID:'CUX',MIN:0,MAX:1},
> ]},
> {ID:'PRI',MIN:1,MAX:25,LEVEL:[
> {ID:'APR',MIN:0,MAX:1},
> {ID:'RNG',MIN:0,MAX:1},
> {ID:'DTM',MIN:0,MAX:5},
> ]},
> {ID:'TAX',MIN:1,MAX:99,LEVEL:[
> {ID:'LOC',MIN:0,MAX:5},
> ]},
> {ID:'UNS',MIN:1,MAX:1},
> {ID:'CNT',MIN:0,MAX:10},
> {ID:'MOA',MIN:1,MAX:100,LEVEL:[
> {ID:'RFF',MIN:0,MAX:1,LEVEL:[
> {ID:'DTM',MIN:0,MAX:5},
> ]},
> ]},
> {ID:'TAX',MIN:1,MAX:10,LEVEL:[
> {ID:'MOA',MIN:0,MAX:2},
> ]},
>
> |
>
>
> all others are set to MIN: 0
>
> This gives me the right result (as also posted in third message) this solves the collision error but i still have the error TypeError: unsupported operand type(s) for +: 'int' and 'list' again.
> What does this mean and how can i solve this?
>

Angelo de Laat

unread,
May 22, 2013, 10:41:49 AM5/22/13
to bots...@googlegroups.com
of course...

plugin_20130522.zip

henk-jan ebbers

unread,
May 22, 2013, 11:39:10 AM5/22/13
to bots...@googlegroups.com
I see the problem.
The implementation assumes fixed fields have no subfields, but this is not checked for in the grammar.
sorry, I did not realize this.

so:
['BOTSID', 'M', 3, 'AN'],
['C543', 'C', [
['C543.7431', 'M', 3, 'AN'],
['C543.7433', 'C', 3, 'AN'],
['C543.1131', 'C', 3, 'AN'],
['C543.3055', 'C', 3, 'AN'],
['C543.7434', 'C', 70, 'AN'],
]],
['9419', 'C', 3, 'AN'],

gets to be:

['BOTSID', 'M', 3, 'AN'],

['C543.7431', 'M', 3, 'AN'],
['C543.7433', 'C', 3, 'AN'],
['C543.1131', 'C', 3, 'AN'],
['C543.3055', 'C', 3, 'AN'],
['C543.7434', 'C', 70, 'AN'],
['9419', 'C', 3, 'AN'],
fro the segment you used in messages.

also, replace 'N' format with 'R'

might be some problems with M/C, but these should be easily solved.

also, use editor with python syntax check, eg scite or geany. This is handy when editing grammars.


kind regards,
henk-jan


On 05/22/2013 04:41 PM, Angelo de Laat wrote:
> of course...

Angelo de Laat

unread,
May 22, 2013, 3:04:38 PM5/22/13
to bots...@googlegroups.com
thanks, first thing on my list this morning.

Angelo de Laat

unread,
May 22, 2013, 4:58:12 PM5/22/13
to bots...@googlegroups.com
HJ,

now i have a new error. I think i have had them all now....

ScriptImportError: Error in "/root/bots-3.0.0/bots/bots.usersys/grammars/fixed.pantheon_invoice", error: TypeError: list indices must be integers, not tuple

i did exactly what you posted.

ps could you also explain why fixed does not check subfield, if i look to sample edifact messages i dont see subfields just as my example.


plugin_20130522.zip

henk-jan ebbers

unread,
May 22, 2013, 5:04:13 PM5/22/13
to bots...@googlegroups.com
yes, I had that as well.

but I told you to use syntax check first ;-))
there are also more debug options, see in wiki.

henk-jan
Reply all
Reply to author
Forward
0 new messages