#!/usr/local/bin/perl -s # floodEDI.pl 1.3 10/16/99 mkj # # This perl script is used to generate valid sequential EDI transactions and # can feed the resulting transactions either into an X400 message (mailer), # a SMTP mailbox, or into a text file. # # This script supports 3030 and 3072 TCIF 850 EDI transactions # and will automatically generate both good 850s and 850s that produce either # negative 997 acknowledgements or Fatal Reject 855s. # # The inspiration for this tool was "ift_it3.sh" # require 5.004; # Required USER SET variables #++++++++++++ You may customize these +++++++++++++++++++++++++++++++++++++++ $mailbox="$ENV{HOME}/tst_850_mailbox"; # mailbox name $dest="insert an X400 alias here"; # X400 alias name/address $MaxPerMbox=10; # max messages per mailbox $Negative997Ratio=45; # 1:45 negative 997 ratio $FatalRejectRatio=20; # 1:20 reject ratio #+++++++++++ Don't modify anything below ++++++++++++++++++++++++++++++++++++ # Set required variables here ======== DO NOT CHANGE THESE VALUES =========== $mailer="/opt/IC/usr/lib/pp/cmds/mail"; $tempName="./tmp.850"; $tempBox="./tmpMbox"; $tempHead="./tmpHeader"; # Verify command line arguments and set defaults if ($Help || $help || $what) { &usage; } if ($Start < 1 || $Start eq "") { $Start=1; } if ($Number eq "") { $Number = 1; } if ($Number < 1) { print "Number argument is invalid (must be a positive integer)\n"; &usage; } if ($Output eq "") { $Output = "Files"; } if ($Output != "Mailer" && $Output != "Mailbox" && $Output != "Files") { print "Output argument is invalid (must be one of the following:\n"; print "\tMailer, Mailbox, or Files\n"; &usage; } if ($Version eq "") { $Version = "3030"; } if ($Version != "3030" && $Version != "3072") { print "Version argument is invalid (must be either 3030 or 3072)\n"; &usage; } if ($Customer eq "") { $Customer="Seqential Test"; } # Display Startup Configuration here print "Configuration for this run\n"; print "\tNumber = $Number\n"; print "\tOutput = $Output\n"; print "\tVersion = $Version\n"; print "\tStart = $Start\n"; print "\tCustomer = $Customer\n"; print scalar localtime; # like system("date"); print "\n"; # date & time based variables (only calc once per run) $date8=&genDate8(time); # "19981201" # gen 8 date $date6 = substr($date8,2,8); # gen 6 date $year2 = substr($date8,0,2); # gen 2 year $time6=&genTime6(time); # "091530" # gen 6 time $time4 = substr($time6,0,4); # gen 4 time # gen dueDate = today + 7 days (8 digit date) $DueDate=&genDate8(time+(60*60*24*7)); # gen badDueDate=today - 7 days (8 digit date) $BadDueDate=&genDate8(time-(60*60*24*7)); # Start the big loop for ($counter=$Start; $counter < $Number + $Start; $counter++) { ## &gen_850; if ($Version eq "3030") { &gen_850_3030; } else { &gen_850_3072; } $counter10K = $counter+10000; $system_string = "mv $tempName $counter10K.850"; if ($Output eq "Files") { print "Saving 850\n"; rename($tempName, $counter10K.".850"); } elsif ($Output eq "Mailer") { print "Sending 850\n"; system($system_string); $system_string="cat $counter10K.850 | $mailer $dest -s 850"; system($system_string); } elsif ($Output eq "Mailbox") { print "Adding 850 to mailbox\n"; # generate a SMTP mail header for $tempBox &genHeader; # then write new header and EDI to $tempBox system("cat $tempHead $tempName >> $tempBox"); # add required linefeed to seperate messages in mbox system("echo >> $tempBox"); # if current mbox full or on last mbox then flush if (($counter % $MaxPerMbox) == 0 || $counter == ($Start + $Number) -1 ) { # then we move new mbox if no current mbox print "\n"; while ( -f $mailbox) { print ".\n"; sleep 2; # waiting for mbox to disappear } print "MOVING temp box to $mailbox\n"; system("mv $tempBox $mailbox"); } } } print "\nFinished at "; print scalar localtime; # like system("date"); print "\n"; # clean up after yourself (your Mother dosen't work here) unlink($tempName); unlink($tempBox); unlink($tempHead); exit 0; # eos main sub gen_850 { # Counter based variables (calc every iteration) # gen GS Control Number $GSctl = sprintf("%06d",$counter); # "123456" (6 digits) # gen ST Control Number $STctl = sprintf("%09d",$counter); # "123456789" (9 digits) ##$ISActl = "0$STctl"; # gen ISA Control Number (10 digits) $ISActl = "$STctl"; # gen ISA Control Number (9 digits) $PON = "TST01$STctl-001"; # gen PON Number open(TEMP,"> $tempName") || die "Error: cannot create $tempName: $!"; print "\t$counter PON: $PON ISA: $ISActl\t"; # Figure out type of 850 to generate first $bad850Neg997 = $bad850FatalReject = 0; if (($counter % $Negative997Ratio) == 0) { print "Bad 850 (negative 997)\t"; $bad850Neg997 = 1; } elsif (($counter % $FatalRejectRatio) == 0) { print "Bad 850 (Fatal Reject 855)\t"; $bad850FatalReject = 1; } else { print "Good 850\t\t"; } # regardless of $Output setting always gen an 850 to a temp file $SEcount=41; # number of ST segments in 3030 # EDI header ------------------------------------------------------------ print TEMP "ISA^03^7000 ^00^7001 ^ZZ^"; print TEMP "TP_1 ^ZZ^TP_TWO ^$date6"; if ($Version eq "3030") { print TEMP "^$time4^U^00303^$ISActl^0^T^>\n"; print TEMP "GS^PO^APP1^APP2^$date6^$time4^$GSctl^X^003030\n"; print TEMP "ST^850^$STctl\n"; print TEMP "BEG^00^SS^$PON^^$date6\n"; print TEMP "REF^12^2035556005\n"; } else { print TEMP "^$time4^U^00307^$ISActl^0^T^>\n"; print TEMP "GS^PO^CLECAPP^SNET^$date8^$time4^$GSctl^X^003072\n"; print TEMP "ST^850^$STctl\n"; print TEMP "BEG^00^SS^$PON^^$date8\n"; print TEMP "REF^11^2035556005^ATN\n"; print TEMP "REF^12^2035556005^BAN1\n"; } print TEMP "REF^WO^$PON\n"; print TEMP "PER^OC^CNSC^TE^8005551212\n"; # DTM^150 due date = today + 7 if ($Version eq "3030") { if ($bad850FatalReject == 1) { print TEMP "DTM^150^^^^^D8^$BadDueDate\n"; } else { print TEMP "DTM^150^^^^^D8^$DueDate\n"; } print TEMP "DTM^097^$date6^$time6^21^$year2\n"; print TEMP "SI^TI^AA^C^BO^2037362820\n"; print TEMP "SI^TI^BN^2037362820\n"; } else { if ($bad850FatalReject == 1) { print TEMP "DTM^150^$BadDueDate\n"; } else { print TEMP "DTM^150^$DueDate\n"; } print TEMP "DTM^097^$date8^$time6^ET\n"; print TEMP "SI^TI^AA^C^RE^EB\n"; } print TEMP "PID^S^^TI^AA^^^WLS-YN^Y\n"; print TEMP "PID^S^^TI^AB^^^WLS-YN^Y\n"; print TEMP "PID^S^^TI^AC^^^WLS-YN^N\n"; print TEMP "PID^S^^TI^AE^^^WLS-YN^N\n"; if ($Version eq "3030") { print TEMP "N1^BT^^42^7000\n"; print TEMP "N1^78^^91^TP1\n"; } else { print TEMP "N1^BT^^92^TP1\n"; print TEMP "N1^BY^^25^7000\n"; print TEMP "N1^78^TP1\n"; $SEcount++; } print TEMP "N1^IT^$Customer\n"; if ($Version eq "3030") { print TEMP "N3^10 MAIN ST\n"; print TEMP "N4^ANSONIA^CT^06401\n"; } else { print TEMP "N4^ANSONIA^CT^06401\n"; print TEMP "NX^01^10\n"; print TEMP "NX^02^MAIN ST\n"; $SEcount++; } # start first PO1 Loop -------------------------------------------------- print TEMP "PO1^1^1^EA^^^SH^NP\n"; print TEMP "SI^TI^SA^C\n"; print TEMP "PID^S^^TI^AD^^^WLS-YN^N\n"; print TEMP "SLN^1\n"; print TEMP "SI^TI^SA^A^TN^2035552820^LY^M^CL^R^LX^2037362820\n"; print TEMP "N1^DH^$Customer\n"; print TEMP "N3^10 MAIN ST\n"; print TEMP "N4^ANSONIA^CT^06401\n"; # start second PO1 Loop ------------------------------------------------- print TEMP "PO1^2^1^EA\n"; print TEMP "SI^TI^SA^C\n"; print TEMP "PID^S^^TI^AD^^^WLS-YN^N\n"; print TEMP "SLN^1\n"; print TEMP "SI^TI^SA^D^TN^2035552820^LY^M^CL^R^DB^09101"; print TEMP "^SB^A^LX^2035552820\n"; print TEMP "N1^DH^$Customer\n"; print TEMP "N3^10 MAIN ST\n"; print TEMP "N4^ANSONIA^CT^06401\n"; # start third PO1 Loop -------------------------------------------------- print TEMP "PO1^3^1^EA\n"; if ($Version eq "3030") { print TEMP "SI^TI^SA^C\n"; print TEMP "PID^S^^TI^AD^^^WLS-YN^N\n"; print TEMP "SLN^1\n"; print TEMP "SI^TI^SA^RF^TN^8605551675^SF^3WC^SF^CFW038^SF^SCG014\n"; } else { print TEMP "SI^TI^SA^C^TN^8605551675\n"; print TEMP "PID^S^^TI^AD^^^WLS^-YN^N\n"; print TEMP "SLN^1^C^1^EA\n"; print TEMP "SI^TI^SA^D^SF^3WC\n"; print TEMP "SLN^2^D^1^EA\n"; print TEMP "SI^TI^SA^D^SF^CFW038\n"; print TEMP "SLN^3^D^1^EA\n"; print TEMP "SI^TI^SA^D^SF^SCG014\n"; print TEMP "SLN^4^D^1^EA\n"; $SEcount+=6; } # EDI trailer ----------------------------------------------------------- print TEMP "CTT^3\n"; if ($bad850Neg997 == 1) { $SEcount = 21; # ST segment count should be 41 or 42 } print TEMP "SE^$SEcount^$STctl\n"; print TEMP "GE^1^$GSctl\n"; print TEMP "IEA^1^$ISActl\n"; close(TEMP); return; } # eos gen_850 sub genHeader { open(TEMP,"> $tempHead") || die "Error: cannot create $tempHead: $!"; print TEMP "From test "; print TEMP scalar localtime; # like system("date"); print TEMP "\nReturn-Path: \n"; print TEMP "Received: by frodo. (SMI-8.6/SMI-SVR4)\n"; print TEMP "id KAA14120; Fri, 9 Oct 1999 10:42:19 -0400\n"; print TEMP "Date: Fri, 13 Oct 1999 10:42:19 -0400\n"; print TEMP "From: test (Test TP1)\n"; print TEMP "Message-Id: <199810091442.KAA14120\@frodo.>\n"; print TEMP "To: test\n"; print TEMP "Subject: Sequential EDI 850 Test Case\n"; print TEMP "Content-Length: 1153\n"; print TEMP "Status: O\n"; print TEMP "\n"; close(TEMP); return; } # eos genHeader sub genDate8 { local ($ltime) = @_; ($sec,$min,$hour,$mday,$month,$year) = localtime($ltime); $year = ($year < 200 ? $year+1900 : $year); $month = ($month++ < 10 ? "0" . $month : $month); $mday = ($mday < 10 ? "0" . $mday : $mday); ## print "genDate8: $month / $mday / $year\n"; $genDate8="$year$month$mday"; return $genDate8; } #eos genDate8 sub genTime6 { local ($ltime) = @_; ($sec,$min,$hour,$mday,$month,$year) = localtime($ltime); $hour = ($hour < 10 ? "0" . $hour : $hour); $min = ($min < 10 ? "0" . $min : $min); $sec = ($sec < 10 ? "0" . $sec : $sec); ## print "genTime6: $hour:$min:$sec\n"; $genTime6="$hour$min$sec"; return $genTime6; } #eos genTime6 sub usage { print "Usage: $0 -Number=number -Output=value -Version=value\n"; print "\t-Customer=string -Start=number\n"; print "\t-Shutdown=number\[,number\[...\]\]\] -Help\n\n"; print "-Number=number of EDI message to create (default 1)\n"; print "-Output=where to send EDI messages. Supported values:\n"; print "\tFiles - will create an EDI text file per message\n"; print "\tMailer - will mail edi via X400 to $dest\n"; print "\tMailbox - will build mailbox (and wait til current one is gone)\n"; print "\t(defaults to Files)\n"; print "-Version=EDI 850 version. Supported values: 3030 or 3072 (default 3030)\n"; print "-Customer=test ID (will fill N1 segments in 850) (default \"Seqential Test\")\n"; print "-Start=message count number to start on (default 1)\n"; print "-Help displays this message.\n\n"; print "Example:\n"; print "./floodEDI.pl -Output=Mailbox -Number=65 -Start=40\n"; exit 0; } # eos usage; sub gen_850_3030 { # Counter based variables (calc every iteration) # gen GS Control Number $GSctl = sprintf("%06d",$counter); # "123456" (6 digits) # gen ST Control Number $STctl = sprintf("%09d",$counter); # "123456789" (9 digits) $ISActl = "$STctl"; # gen ISA Control Number (9 digits) $PON = "TST01$STctl-001"; # gen PON Number open(TEMP,"> $tempName") || die "Error: cannot create $tempName: $!"; print "\t$counter PON: $PON ISA: $ISActl\t"; # Figure out type of 850 to generate first $bad850Neg997 = $bad850FatalReject = 0; if (($counter % $Negative997Ratio) == 0) { print "Bad 850 (negative 997)\t"; $bad850Neg997 = 1; } elsif (($counter % $FatalRejectRatio) == 0) { print "Bad 850 (Fatal Reject 855)\t"; $bad850FatalReject = 1; } else { print "Good 850\t\t"; } # regardless of $Output setting always gen an 850 to a temp file $SEcount=41; # number of ST segments in 3030 # EDI header ------------------------------------------------------------ print TEMP "ISA^03^7000 ^00^7001 ^ZZ^"; print TEMP "TP_1 ^ZZ^TP_2 ^$date6"; print TEMP "^$time4^U^00303^$ISActl^0^T^>\n"; print TEMP "GS^PO^APP1^APP2^$date6^$time4^$GSctl^X^003030\n"; print TEMP "ST^850^$STctl\n"; print TEMP "BEG^00^SS^$PON^^$date6\n"; print TEMP "REF^12^2035556005\n"; print TEMP "REF^WO^$PON\n"; print TEMP "PER^OC^CNSC^TE^8005551212\n"; # DTM^150 due date = today + 7 if ($bad850FatalReject == 1) { print TEMP "DTM^150^^^^^D8^$BadDueDate\n"; } else { print TEMP "DTM^150^^^^^D8^$DueDate\n"; } print TEMP "DTM^097^$date6^$time6^21^$year2\n"; print TEMP "SI^TI^AA^C^BO^2035552820\n"; print TEMP "SI^TI^BN^2035552820\n"; print TEMP "PID^S^^TI^AA^^^WLS-YN^Y\n"; print TEMP "PID^S^^TI^AB^^^WLS-YN^Y\n"; print TEMP "PID^S^^TI^AC^^^WLS-YN^N\n"; print TEMP "PID^S^^TI^AE^^^WLS-YN^N\n"; print TEMP "N1^BT^^42^7000\n"; print TEMP "N1^78^^91^TP1\n"; print TEMP "N1^IT^$Customer\n"; print TEMP "N3^10 MAIN ST\n"; print TEMP "N4^ANSONIA^CT^06401\n"; # start first PO1 Loop -------------------------------------------------- print TEMP "PO1^1^1^EA^^^SH^NP\n"; print TEMP "SI^TI^SA^C\n"; print TEMP "PID^S^^TI^AD^^^WLS-YN^N\n"; print TEMP "SLN^1\n"; print TEMP "SI^TI^SA^A^TN^2037555820^LY^M^CL^R^LX^2035552820\n"; print TEMP "N1^DH^$Customer\n"; print TEMP "N3^10 MAIN ST\n"; print TEMP "N4^ANSONIA^CT^06401\n"; # start second PO1 Loop ------------------------------------------------- print TEMP "PO1^2^1^EA\n"; print TEMP "SI^TI^SA^C\n"; print TEMP "PID^S^^TI^AD^^^WLS-YN^N\n"; print TEMP "SLN^1\n"; print TEMP "SI^TI^SA^D^TN^2035552820^LY^M^CL^R^DB^09101"; print TEMP "^SB^A^LX^2035552820\n"; print TEMP "N1^DH^$Customer\n"; print TEMP "N3^10 MAIN ST\n"; print TEMP "N4^ANSONIA^CT^06401\n"; # start third PO1 Loop -------------------------------------------------- print TEMP "PO1^3^1^EA\n"; print TEMP "SI^TI^SA^C\n"; print TEMP "PID^S^^TI^AD^^^WLS-YN^N\n"; print TEMP "SLN^1\n"; print TEMP "SI^TI^SA^RF^TN^8605551675^SF^3WC^SF^CFW038^SF^SCG014\n"; # EDI trailer ----------------------------------------------------------- print TEMP "CTT^3\n"; if ($bad850Neg997 == 1) { $SEcount = 21; # ST segment count should be 41 or 42 } print TEMP "SE^$SEcount^$STctl\n"; print TEMP "GE^1^$GSctl\n"; print TEMP "IEA^1^$ISActl\n"; close(TEMP); return; } # eos gen_850_3030 sub gen_850_3072 { # Counter based variables (calc every iteration) # gen GS Control Number $GSctl = sprintf("%06d",$counter); # "123456" (6 digits) # gen ST Control Number $STctl = sprintf("%09d",$counter); # "123456789" (9 digits) $ISActl = "$STctl"; # gen ISA Control Number (9 digits) $PON = "TST01$STctl-001"; # gen PON Number open(TEMP,"> $tempName") || die "Error: cannot create $tempName: $!"; print "\t$counter PON: $PON ISA: $ISActl\t"; # Figure out type of 850 to generate first $bad850Neg997 = $bad850FatalReject = 0; if (($counter % $Negative997Ratio) == 0) { print "Bad 850 (negative 997)\t"; $bad850Neg997 = 1; } elsif (($counter % $FatalRejectRatio) == 0) { print "Bad 850 (Fatal Reject 855)\t"; $bad850FatalReject = 1; } else { print "Good 850\t\t"; } # regardless of $Output setting always gen an 850 to a temp file $SEcount=32; # number of ST segments in 3072 order # EDI header ------------------------------------------------------------ print TEMP "ISA^03^7000 ^00^7001 ^ZZ^"; print TEMP "TP_1 ^ZZ^TP_2 ^$date6"; print TEMP "^$time4^U^00307^$ISActl^0^T^>\n"; print TEMP "GS^PO^APP1^APP2^$date8^$time4^$GSctl^X^003072\n"; print TEMP "ST^850^$STctl\n"; print TEMP "BEG^00^SS^$PON^^$date8\n"; print TEMP "REF^11^2035551000^ATN\n"; print TEMP "REF^12^2035556005^BAN1\n"; print TEMP "REF^OW^$PON^ORD\n"; print TEMP "REF^SU^C^RTR\n"; print TEMP "PAM^QO^1^EA\n"; print TEMP "DTM^097^$date8^$time6^ET\n"; # DTM^150 due date = today + 7 if ($bad850FatalReject == 1) { print TEMP "DTM^150^$BadDueDate\n"; } else { print TEMP "DTM^150^$DueDate\n"; } print TEMP "SI^TI^AA^A^RE^EB\n"; print TEMP "PID^S^^TI^AC^^^SO-RSQ^N\n"; print TEMP "PID^S^^TI^AD^^^SO-RSQ^N\n"; print TEMP "PID^S^^TI^AF^^^SO-RSQ^N\n"; print TEMP "N9^L1^ORI\n"; print TEMP "MSG^POTS Test-Add 3 Way Calling and PIC/LPIC Freeze.\n"; print TEMP "N1^BY^^25^7000\n"; print TEMP "N1^BT^^92^TP1\n"; print TEMP "N1^IT^$Customer\n"; print TEMP "N4^ANSONIA^CT^06401\n"; print TEMP "NX2^01^10\n"; print TEMP "NX2^02^MAIN\n"; print TEMP "NX2^62^ST\n"; print TEMP "N1^78^TP1\n"; print TEMP "PER^AG^JEFF WALKER^TE^6165554987^FX^6165555106\n"; # start first PO1 Loop -------------------------------------------------- print TEMP "PO1^1^1^EA\n"; print TEMP "SI^TI^SA^A^TN^8605550049^TY^2BF-\n"; print TEMP "SI^TI^SA^A^SF^3WC^FZ^B\n"; print TEMP "REF^IX^1^REFNUM\n"; print TEMP "N1^P9^^41^0763\n"; print TEMP "N1^8V^^41^0763\n"; # EDI trailer ----------------------------------------------------------- print TEMP "CTT^1\n"; if ($bad850Neg997 == 1) { $SEcount = 22; # ST segment count should be 32 } print TEMP "SE^$SEcount^$STctl\n"; print TEMP "GE^1^$GSctl\n"; print TEMP "IEA^1^$ISActl\n"; close(TEMP); return; } # eos gen_850_3072 #EOF floodEDI.pl