+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 12

Thread: Perl: 997 Analyzer

  1. #1
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Perl: 997 Analyzer

    Below is a quick and dirty 997 (Acknowledgment) analyzer. The purpose of the analyzer is to detect failures and send an email alert. I'm currently writing a PHP EDI parser class which will extend into a 997 and 824 analyzer but I needed something quick to send alerts in production now. It may take a week to finish my PHP EDI Parser so here is what I came up with (in Perl):

    [highlight="perl"]
    #!/usr/bin/perl
    # Copyright: Jordan DeLozier
    # Purpose: EDI
    #
    # Description: Send an error email about
    # rejected 997s
    #
    # Author: Jordan DeLozier
    # Date: 9-10-2008
    ################################################
    # Variables
    $input = $ARGV[0]; # File
    $error = 0;
    $type = "";
    $lineSep = "\n"; # Value will change below
    $segSep = "*"; # Value will change below
    $email = "some\@email.com"; # Email or distribution list to receive
    # rejected 997 notices.
    $from = "EDI Translator"; # Email From
    ##################################################
    # Email Subject and Message set lower


    # Open the File
    open(INFO, $input) || die ("Could not open file - $input\n");
    $edi_lines = <INFO>; # Read into array
    close(INFO); # close the file

    # Read the 106th character to determine the
    # line seperator
    $lineSep = substr($edi_lines, 105, 1);
    $segSep = "\\" . substr($edi_lines, 3, 1);

    # Split the lines
    @edi = split(/$lineSep/, $edi_lines);

    # Read Each Line
    foreach $n(@edi) {
    # Split the EDI Lines
    @elements = split(/$segSep/, $n);

    # Determine each segment
    $segment = $elements[0];

    # Grab the type for email Subject
    if ($segment eq "AK2") {
    $type = $elements[1];
    }


    # Check for the Error Codes
    if ($segment eq "AK5") {
    if ($elements[1] eq "R" || $elements[1] eq "E") {
    # Found Error, we only want one email so
    # we will set a flag here instead of sending
    # the email here.
    $error = 1;


    # CLI Output (for debugging)
    print "$n\n";
    }
    }
    }


    #kick off the email
    if ($error == 1)
    {
    # email Variables
    $subject = "$type Rejected!";
    $message = "Hello,\nAn EDI message has been rejected via 997. This problem needs correcting ASAP. Below are the contents of the EDI document.\n\n $edi_lines";
    sendEmail($email, $from, $subject, $message);

    # CLI Output
    print "Email Sent!\n";
    }


    # Simple Email Function
    # ($to, $from, $subject, $message)
    sub sendEmail
    {
    my ($to, $from, $subject, $message) = @_;
    my $sendmail = '/usr/lib/sendmail';
    open(MAIL, "|$sendmail -oi -t");
    print MAIL "From: $from\n";
    print MAIL "To: $to\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "$message\n";
    close(MAIL);
    }
    [/highlight]

    Usage:
    # ./analyze997.pl /path/to/997/file

    Sample Rejection 997:
    Code:
    ISA*00*          *00*          *01*01      *01*02 *080909*1730*U*00200*000001789*0*P*:
    GS*FA*05*02*080909*1730*1789*X*002001
    ST*997*1789
    AK1*SH*17
    AK2*856*0017
    AK5*R*3
    AK9*R*1*1*0
    SE*6*1789
    GE*1*1789
    IEA*1*000001789
    Feel free to change, use, distribute or anything you like. I've added it as an attachment as well.
    Attached Files
    Last edited by Jordan; 09-10-2008 at 07:51 PM.

  2. #2
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25

    Re: Perl: 997 Analyzer

    Can you either attach the files or disable the GeSHi line numbers (or toggle the line numbers) - its a pain in the arse to copy / paste the code.

  3. #3
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    Quote Originally Posted by John View Post
    Can you either attach the files or disable the GeSHi line numbers (or toggle the line numbers) - its a pain in the arse to copy / paste the code.
    I thought I did attach it but I will once I get back on my laptop.

    Posted via CodeCall Mobile

  4. #4
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Perl: 997 Analyzer

    There you go, attached.

  5. #5
    Guru morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice
    Join Date
    Jan 2008
    Posts
    1,724
    Blog Entries
    4

    Re: Perl: 997 Analyzer

    Jordan,

    Why would you write the emailer in perl or php for errors in another programming language? Wouldn't an EDI error be best found in EDI itself? Is EDI capable of emailing errors to someone? I'm kind of perplexed.

  6. #6
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97
    Quote Originally Posted by morefood2001 View Post
    Jordan,

    Why would you write the emailer in perl or php for errors in another programming language? Wouldn't an EDI error be best found in EDI itself? Is EDI capable of emailing errors to someone? I'm kind of perplexed.
    EDI is like xml, it is just information. The EDI mapper software is code but it is probably less useful than basic in DOS 3.1. It doesn't have the ability to email or do complex algos.

    Posted via CodeCall Mobile

  7. #7
    Guru morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice
    Join Date
    Jan 2008
    Posts
    1,724
    Blog Entries
    4

    Re: Perl: 997 Analyzer

    Thanks for the explanation. If EDI is basically xml, why don't you and your company port over to more modern languages that are more powerful?

  8. #8
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Perl: 997 Analyzer

    It is not dictated by us. It is an automotive standard(Ford, GM, Chrysler, etc) who tell us we have to use it in order to do business with them. Other industries also use it like Walmart, for instance.

  9. #9
    Guru morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice morefood2001 is just really nice
    Join Date
    Jan 2008
    Posts
    1,724
    Blog Entries
    4

    Re: Perl: 997 Analyzer

    Quote Originally Posted by Jordan View Post
    It is not dictated by us. It is an automotive standard(Ford, GM, Chrysler, etc) who tell us we have to use it in order to do business with them. Other industries also use it like Walmart, for instance.
    Wow, I can't believe how technologically outdated many modern companies are!

  10. #10
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: Perl: 997 Analyzer

    I believe EDI is about 40 years old but in all that time it is still a very a very rare and unknown skill. For instance, before you met me, did you ever hear of EDI?

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. opinions- Perl or PHP for sendmail?
    By zeroradius in forum PHP Forum
    Replies: 16
    Last Post: 05-24-2008, 01:03 PM
  2. Perl Programming: Pack()..bit of hex
    By noobjason in forum Perl
    Replies: 0
    Last Post: 05-06-2008, 04:41 AM
  3. Perl text parse help (noob)
    By dfp in forum Perl
    Replies: 4
    Last Post: 11-23-2007, 01:57 PM
  4. Perl is Dead. Long live Perl.
    By Kernel in forum News
    Replies: 3
    Last Post: 08-10-2007, 10:49 AM
  5. Perl Tutorial Course for Windows
    By priorityone in forum Perl
    Replies: 22
    Last Post: 02-11-2007, 12:57 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts