Mapping loop within a loop - EDIFACT LIN and SEQ structure to CSV

109 views
Skip to first unread message

riverthames

unread,
Apr 23, 2011, 10:01:01 PM4/23/11
to Bots Open Source EDI Translator
New to BOTS this week but struggling with a DIRDEBD96A to CSV mapping
script.

Test message has 3 LINs (Level B) and 2 SEQ in each (at Level 3):

UNH
DTM+137 (at Level A)
LIN
DTM+203 (at Level B)
........
SEQ
DTM+187 (at Level C)
........
UNZ

I have tried various combinations to get appropriate values for each
of the three EDIFACT levels into a single CSV record for validating
test data in Excel but to no avail.

I either get the first LIN+1 value of DTM+203 output as EXECUTEDATE
for all six CSV output records, or the last LIN+3 value of DTM+203 for
all six records, but I have not yet been able to construct the correct
login to cycle through LIN+1, +2 and +3 for both the SEQ+1 and SEQ+2
correctly:

MESSAGEDATE = inn.get({'BOTSID':'UNH'},
{'BOTSID':'DTM','C507.2005':'137','C507.2380':None})
for sin in inn.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'},
{'BOTSID':'SEQ'}):
EXECUTEDATE = inn.get({'BOTSID':'UNH'},{'BOTSID':'LIN'},
{'BOTSID':'DTM','C507.2005':'203','C507.2380':None})

sou = out.putloop({'BOTSID':'HEA'}) #this is needed; it
takes care of initialising a new HEA-record
sou.put({'BOTSID':'HEA','MESSAGEDATE':MESSAGEDATE})
sou.put({'BOTSID':'HEA','EXECUTEDATE':EXECUTEDATE})
sou.put({'BOTSID':'HEA','MANDATEDATE':sin.get({'BOTSID':'SEQ'},
{'BOTSID':'DTM','C507.2005':'187','C507.2380':None})})

Any answers gratefully received?

henk-jan ebbers

unread,
Apr 24, 2011, 3:18:11 AM4/24/11
to bots...@googlegroups.com
hi riverthames,

I certainly do wanna take a look at it, probably just a small thing.
but the email dos something with your indentation.
can you attach the mapping script to your eami.
(as it is easter, I only will be able to answer late tonight ;-)

henk-jan

Jeff Barton

unread,
Apr 24, 2011, 9:43:48 AM4/24/11
to bots...@googlegroups.com, goo...@vadis.net

Hi Henk-Jan,

 

Thanks for your prompt reply - especially over Easter!

 

I attach the test input file, in and out Grammar files and two mapping script attempts:

-   csvDIRDEB_edi2edi_Gives1stLevelBOnly.py gives me 6 records (required amount) but only uses the first LIN+1 value for the DTM+203

-   csvDIRDEB_edi2edi_Gives18Records.py gives me 3 LIN * 3 LIN * 2 SEQ = 18 records but does scan the LIN tree for the values – so I know they are there -just too many times!

 

How to get the best of both?

 

Thanks for your help!

riverthames

TestDIRDEB_20110424.zip

Thomas Wolf

unread,
Apr 24, 2011, 12:05:45 PM4/24/11
to bots...@googlegroups.com
>
> -csvDIRDEB_edi2edi_Gives1stLevelBOnly.py gives me 6 records (required

> amount) but only uses the first LIN+1 value for the DTM+203
>
> -csvDIRDEB_edi2edi_Gives18Records.py gives me 3 LIN * 3 LIN * 2 SEQ = 18
> records but does scan the LIN tree for the values � so I know they are

> there -just too many times!
>
> How to get the best of both?

Hi Jeff,

I think csvDIRDEB_edi2edi_Gives18Records.py is the right approach but
you have to change:

for lin in inn.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'}):


for sin in
inn.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'},{'BOTSID':'SEQ'}):

to:

for lin in inn.getloop({'BOTSID':'UNH'},{'BOTSID':'LIN'}):
for sin in lin.getloop({'BOTSID':'LIN'},{'BOTSID':'SEQ'}):

(Currently, for each LIN you're looping over every SEQ in the file,
instead of every SEQ of the current LIN..)

A short test with this modification resulted in the attached .csv,
I think it looks ok, right?

greetings from Austria
Thomas

2.csv

riverthames

unread,
Apr 24, 2011, 12:51:29 PM4/24/11
to Bots Open Source EDI Translator
Brilliant! Many thanks and as with so many such things it is obvious
once seen!

Happy Easter.
>  2.csv
> 2KViewDownload
Reply all
Reply to author
Forward
0 new messages