Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Edifact anyone?

by Skeeve (Vicar)
on Dec 16, 2013 at 10:42 UTC ( #1067304=perlquestion: print w/ replies, xml ) Need Help??
Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

Dear fellow monks,

I'm trying to learn how to understand EDIFACT messages and so installed http://search.cpan.org/~colinsc/Business-Edifact-Interchange/

But when I run it, I get warnings and error messages.

given is experimental at C:/strawberry/perl/site/lib/Business/Edifact/ +Interchange.pm line 114. when is experimental at C:/strawberry/perl/site/lib/Business/Edifact/I +nterchange.pm line 115. when is experimental at C:/strawberry/perl/site/lib/Business/Edifact/I +nterchange.pm line 119. when is experimental at C:/strawberry/perl/site/lib/Business/Edifact/I +nterchange.pm line 124. when is experimental at C:/strawberry/perl/site/lib/Business/Edifact/I +nterchange.pm line 128. when is experimental at C:/strawberry/perl/site/lib/Business/Edifact/I +nterchange.pm line 132. Modification of non-creatable array value attempted, subscript -1 at C +:/strawberry/perl/site/lib/Business/Edifact/Message.pm line 603, <DAT +A> line 1.

The warnings I t hink I can live with, but what about the error message?

Here my self contained program with data:

#!perl use strict; use warnings; use Business::Edifact::Interchange; use Data::Dumper; my $edifact_message = <DATA>; chomp($edifact_message); my $foo = Business::Edifact::Interchange->new(); my $x=$foo->parse($edifact_message); print Dumper $x->messages; __DATA__ UNA:+.? 'UNB+UNOC:3+1234567890123:14+3210987654321:14+131021:1523+391' +UNH+1+INVOIC:D:96A:UN:EAN008'BGM+380+1077642090+9'DTM+137:20111020:10 +2'DTM+35:20111020:102'FTX+AAK+1+ST2++DE'FTX+SUR+1++DAS LEISTUNGSDATUM + ENTSPRICHT DEM RECHNUNGSDATUM+DE'RFF+ON:2330-35573'RFF+DQ:283506034' +DTM+171:20111018:102'RFF+ABO:1087211625'DTM+171:20111020:102'NAD+BY+3 +210987654321::9'RFF+VA:230/5740/0622'RFF+API:3508566'NAD+DP+405096402 +3306::9'NAD+SU+1234567890123::9'RFF+VA:DE220564280'TAX+7+VAT+++:::7+S +'CUX+2:EUR:4'LIN+1++1234567654321:EN'PIA+1+03460262:SA::91'IMD+A++::: +NESLR Focaccia (24x400g) DE'IMD+C++IN'QTY+47:1:PCE'MOA+203:32.65'MOA+ +131:-12.95'PRI+AAB:45.6:::1:PCE'ALC+A+1++1+DI'MOA+8:12.95'RTE+1:12.95 +'LIN+2++1234567654321:EN+1:1'IMD+C++CU'QTY+59:1:PCE'UNS+S'MOA+77:34.9 +4'MOA+79:32.65'MOA+125:32.65'MOA+124:2.29'TAX+7+VAT+++:::7+S'MOA+79:3 +2.65'MOA+124:2.29'TAX+7+VAT+++:::7+S'MOA+125:32.65'UNT+44+1'UNH+2+INV +OIC:D:96A:UN:EAN008'BGM+393+1087211625+9'DTM+137:20111020:102'NAD+CPE ++3210987654321::9'RFF+FC:230/5740/0622'NAD+SU+1234567890123::9'RFF+VA +:DE220564280'NAD+PR+3210987654321::9'NAD+PE+1234567890123::9'TAX+7+VA +T+++:::7+S'CUX+2:EUR:4'PAT+3'DTM+13:20111025:102'UNS+S'MOA+86:34.94'M +OA+9:34.94'MOA+124:2.29'MOA+125:32.65'UNT+19+2'UNZ+2+391'

Update

The author fixed the warning messages and the bug in V0.06.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Comment on Edifact anyone?
Select or Download Code
Re: Edifact anyone?
by Anonymous Monk on Dec 16, 2013 at 11:31 UTC

    The warnings I t hink I can live with, but what about the error message?

    ;) ... self contained program (with data) to reproduce ... then fix it :)

      As it's real customer data, I couldn't provide. Will see...

      (later) Update my post with requested information


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Edifact anyone?
by kcott (Abbot) on Dec 16, 2013 at 15:53 UTC

    G'day Skeeve,

    The warnings are explained in "perl5180delta: The smartmatch family of features are now experimental".

    As you indicated "it's real customer data", I'll assume production code. I'd caution against using experimental features in production code.

    I see you've raised a bug report (#91446). This would have been useful information in your OP as an update.

    It also appears the module author has provided a fix. Again, useful information for an update to your OP. When you upgrade and test the fix, please also indicate the outcome.

    -- Ken

      I'd caution against using experimental features in production code.

      You're not alone, but you don't say why?

        "You're not alone, but you don't say why?"

        Skeeve's been here for 10 years and has made 799 posts. He probably knows "why". He certainly knows how to ask if he doesn't.

        -- Ken

      Sorry for not updating the OP, but it was a bit busy yesterday. Thanks for linking it. I also did not see the fix yet.

      It might become production data and so I did not want to "reinvent the wheel" but stick to existing modules. The "experimental" warnings scared me a bit, but looking at the code, I think It could be rewritten as:

      given(something) -> SWITCH: for(something) when(/test/) -> /test/ && do {

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Edifact anyone?
by GotToBTru (Chaplain) on Dec 16, 2013 at 16:16 UTC

    EDI Translators are expensive, but worth it if you have more than just a very few trading partners. I would suggest that approach before writing your own.

    Secondly, if I was going to expend the effort to write my own translator, I would be run, not walk, away from any module that generated warnings saying something in it is 'experimental'. Is it something that is going to change functionality or just go away in a future release? Is all my hard work going to be wasted?

    Is your test data well formed? I work with X12, not EDIFACT, so I can't tell just by looking. That might be the source of the error. If not, I think you need to open up the module and go to the line indicated and see what it was trying to do.

      I would be run, not walk, away from any module that generated warnings saying something in it is 'experimental'. Is it something that is going to change functionality or just go away in a future release? Is all my hard work going to be wasted?

      Reason before panic friend :)

      I have no real trading partner. I just need to extract some information for reports.

      The other stuff about X12 - sorry - I don't really understand that yet. Just started learning yesterday.


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
        Hi Skeeve.

        Until you mentioned it, I had never heard of EDIFact.

        I am not sure why something that is supposed to be an ANSI ISO standard doesn't have a free API. It sounds like it is the equivalent to charging for the IP protocol. Maybe I am wrong here. Maybe the charges are for variations that orginzations add to EDI.

        I did some poking around and it looks like there are many translators for sale on the net.

        See references on this page for 'TrueCommerce' and 'B2B Gateway' http://www.sleeter.com/blog/2012/04/quickbooks-edi/

        I also came across some viewers. I am not sure if they will help you or not. Hopefully they will.

        As with the library you found, as it was mentioned earlier, I would shy away from something that was potentially cobbled together. Espcially when working with production data.

        Copy and paste EDI code into the page. This one does translate the code you posted, but I am not sure if it is useful. http://www.edifactviewer.com/

        EDIFACT Viewer http://sourceforge.net/projects/edifactviewer/

        I only mention X12 to say that I know EDI. It's what I do at my job, all day, every day.

        You have no trading partner? Okay, but somebody you know does! Nobody messes around with EDIFACT unless they have to. So, you aren't writing a translator, just trying to understand the structure, and maybe learn some new perl skills along with it. I understand that. For my own work, I have not explored any of the EDI perl modules. We use a translator. I do have half a dozen awk scripts I use to make quick reports from EDI and application data files.

Re: Edifact anyone?
by Anonymous Monk on Dec 16, 2013 at 23:15 UTC
    Well, I've made progress, naturally , not knowing anything about the format, I made guesses (copy/paste) ... but most of the methods that do stuff like parse don't return values ... so here you go
    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; use Business::Edifact::Interchange; sub Business::Edifact::Message::handle_ftx { package Business::Edifact::Message; my ( $self, $data_arr ) = @_; #~ ::dd( data_arr => $data_arr , lines => $self->{lines} ); my $lines = $self->{lines}; if( not @$lines ){ my $line = { line_number => $data_arr->[0]->[0], action_req => $data_arr->[1]->[0], item_number => $data_arr->[2]->[0], item_number_type => $data_arr->[2]->[1], additional_product_ids => [], item_description => [], monetary_amount => [], }; if ( $data_arr->[3]->[0] ) { $line->{sub_line_info} = $data_arr->[3]; } push @$lines, Business::Edifact::Message::LineItem->new($line) +; } $self->{lines}->[-1]->{free_text} = { qualifier => $data_arr->[0]->[0], # LIN/LNO reference => $data_arr->[2], }; if ( $data_arr->[3] ) { $self->{lines}->[-1]->{free_text}->{text} = join q{ }, @{ $data_arr->[3] }; } return; } my $edifact_message = q{UNA:+.? 'UNB+UNOC:3+1234567890123:14+321098765 +4321:14+131021:1523+391'UNH+1+INVOIC:D:96A:UN:EAN008'BGM+380+10776420 +90+9'DTM+137:20111020:102'DTM+35:20111020:102'FTX+AAK+1+ST2++DE'FTX+S +UR+1++DAS LEISTUNGSDATUM ENTSPRICHT DEM RECHNUNGSDATUM+DE'RFF+ON:2330 +-35573'RFF+DQ:283506034'DTM+171:20111018:102'RFF+ABO:1087211625'DTM+1 +71:20111020:102'NAD+BY+3210987654321::9'RFF+VA:230/5740/0622'RFF+API: +3508566'NAD+DP+4050964023306::9'NAD+SU+1234567890123::9'RFF+VA:DE2205 +64280'TAX+7+VAT+++:::7+S'CUX+2:EUR:4'LIN+1++1234567654321:EN'PIA+1+03 +460262:SA::91'IMD+A++:::NESLR Focaccia (24x400g) DE'IMD+C++IN'QTY+47: +1:PCE'MOA+203:32.65'MOA+131:-12.95'PRI+AAB:45.6:::1:PCE'ALC+A+1++1+DI +'MOA+8:12.95'RTE+1:12.95'LIN+2++1234567654321:EN+1:1'IMD+C++CU'QTY+59 +:1:PCE'UNS+S'MOA+77:34.94'MOA+79:32.65'MOA+125:32.65'MOA+124:2.29'TAX ++7+VAT+++:::7+S'MOA+79:32.65'MOA+124:2.29'TAX+7+VAT+++:::7+S'MOA+125: +32.65'UNT+44+1'UNH+2+INVOIC:D:96A:UN:EAN008'BGM+393+1087211625+9'DTM+ +137:20111020:102'NAD+CPE+3210987654321::9'RFF+FC:230/5740/0622'NAD+SU ++1234567890123::9'RFF+VA:DE220564280'NAD+PR+3210987654321::9'NAD+PE+1 +234567890123::9'TAX+7+VAT+++:::7+S'CUX+2:EUR:4'PAT+3'DTM+13:20111025: +102'UNS+S'MOA+86:34.94'MOA+9:34.94'MOA+124:2.29'MOA+125:32.65'UNT+19+ +2'UNZ+2+391'}; my $edi = Business::Edifact::Interchange->new(); $edi->parse($edifact_message); dd( $edi ); __END__

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1067304]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-22 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (156 votes), past polls