--- pipe2sap.pl 2002/12/17 19:24:37 1.1 +++ pipe2sap.pl 2003/03/24 13:02:30 1.8 @@ -21,7 +21,7 @@ # open log and redirect die to it... open(LOG,">> $log") || warn "open log $log: $!"; -local $SIG{__DIE__} = sub { print LOG $_[0] ; die $_[0] }; +local $SIG{__DIE__} = sub { print LOG scalar localtime,$_[0] ; die $_[0] }; # directory in which files will be left my $outdir = $config->{outdir} || die "config: on defined"; @@ -29,9 +29,11 @@ # create output filename my ($ss,$mm,$hh,$dd,$mm,$yy) = localtime(time); $yy += 1900; +$mm++; my $outfile = $config_file; $outfile =~ s/\.xml//i; -$outfile .= "_${yy}-${mm}-${dd}_${hh}:${mm}:${ss}_$$"; +$outfile =~ s/^.*\/([^\/]+)/$1/i; # basename +$outfile .= sprintf("_%04d-%02d-%02d_%02d:%02d:%02d_%d",$yy,$mm,$dd,$hh,$mm,$ss,$$); my $rfc = new SAP::Rfc( ASHOST => $config->{sap}->{ashost}, @@ -60,13 +62,15 @@ my @data; # array for order my $lines; # number of lines in order +my $nr; # order number my $first = ; push @data,$first; chomp $first; -if ($first =~ m/\s+(\d+)\w+$/) { - $lines = $1; - print "Processing $lines lines\n"; +$first=~s/ //g; +if ($first =~ m/\s+(\d+)\s+(\d+)\w+\s*$/) { + ($nr,$lines) = ($1,$2); + print "Processing $lines lines order no. $nr\n"; } else { die "FATAL: can't find number of lines in first line ($first) of input file."; } @@ -80,11 +84,11 @@ if ($#data != $lines) { print "FATAL: file integrity check failed: "; if ($#data > $lines) { - print "too many"; + print "too many ($#data > $lines)"; } else { - print "too few"; + print "too few ($#data < $lines)"; } - print " lines ($#data)...\n"; + print " lines...\n"; } else { print "File integrity checked, saving file...\n"; open(OUT, "> $outdir/$outfile") || die "FATAL: can't open '$outdir/$outfile': $!"; @@ -93,6 +97,11 @@ print OUT $first,@data; close(OUT); + # cludge filename to medika + link("$outdir/$outfile","$outdir/medika"); + chmod 0664,"$outdir/medika"; + $it->FILENAME("medika"); + # call SAP R/3 $rfc->callrfc( $it ); }