/[sap_import]/pipe2sap.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /pipe2sap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Mon Mar 24 13:02:30 2003 UTC (21 years ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +1 -1 lines
File MIME type: text/plain
fix LOG

1 #!/usr/bin/perl
2 use strict;
3 use SAP::Rfc;
4 use Data::Dumper;
5 use XML::Simple;
6
7 my $config_file;
8
9 if ($#ARGV < 0) {
10 print "usage: $0 config.xml\n";
11 exit 1;
12 } else {
13 $config_file = $ARGV[0];
14 }
15
16 $|++;
17
18 my $config = XMLin($config_file);
19
20 my $log = $config->{log} || die "config: no <log> defined";
21
22 # open log and redirect die to it...
23 open(LOG,">> $log") || warn "open log $log: $!";
24 local $SIG{__DIE__} = sub { print LOG scalar localtime,$_[0] ; die $_[0] };
25
26 # directory in which files will be left
27 my $outdir = $config->{outdir} || die "config: on <outdir> defined";
28
29 # create output filename
30 my ($ss,$mm,$hh,$dd,$mm,$yy) = localtime(time);
31 $yy += 1900;
32 $mm++;
33 my $outfile = $config_file;
34 $outfile =~ s/\.xml//i;
35 $outfile =~ s/^.*\/([^\/]+)/$1/i; # basename
36 $outfile .= sprintf("_%04d-%02d-%02d_%02d:%02d:%02d_%d",$yy,$mm,$dd,$hh,$mm,$ss,$$);
37
38 my $rfc = new SAP::Rfc(
39 ASHOST => $config->{sap}->{ashost},
40 USER => $config->{sap}->{user},
41 PASSWD => $config->{sap}->{passwd},
42 LANG => $config->{sap}->{lang},
43 CLIENT => $config->{sap}->{client},
44 SYSNR => $config->{sap}->{sysnr},
45 TRACE => $config->{sap}->{trace}
46 ) || die "new: $!";
47
48 $rfc->is_connected || die "FATAL: SAP not connected";
49
50 my $it = $rfc->discover($config->{sap}->{discover}) || die "FATAL: SAP discover: $!";
51
52 foreach my $p ($config->{sap}->{params}) {
53 foreach my $p_name (keys %{$p}) {
54 # print "$p_name --> ",$p->{$p_name},"\n";
55 $it->$p_name($p->{$p_name});
56 }
57 }
58
59 # override FILENAME with my name
60 $it->FILENAME($outfile);
61 print "Using file '$outfile'\n";
62
63 my @data; # array for order
64 my $lines; # number of lines in order
65 my $nr; # order number
66
67 my $first = <STDIN>;
68 push @data,$first;
69 chomp $first;
70 $first=~s/
71 //g;
72 if ($first =~ m/\s+(\d+)\s+(\d+)\w+\s*$/) {
73 ($nr,$lines) = ($1,$2);
74 print "Processing $lines lines order no. $nr\n";
75 } else {
76 die "FATAL: can't find number of lines in first line ($first) of input file.";
77 }
78
79 # suck file in array
80 while(<STDIN>) {
81 push @data,$_;
82 }
83
84 # check integrity of file
85 if ($#data != $lines) {
86 print "FATAL: file integrity check failed: ";
87 if ($#data > $lines) {
88 print "too many ($#data > $lines)";
89 } else {
90 print "too few ($#data < $lines)";
91 }
92 print " lines...\n";
93 } else {
94 print "File integrity checked, saving file...\n";
95 open(OUT, "> $outdir/$outfile") || die "FATAL: can't open '$outdir/$outfile': $!";
96
97 # dump order to file
98 print OUT $first,@data;
99 close(OUT);
100
101 # cludge filename to medika
102 link("$outdir/$outfile","$outdir/medika");
103 chmod 0664,"$outdir/medika";
104 $it->FILENAME("medika");
105
106 # call SAP R/3
107 $rfc->callrfc( $it );
108 }
109
110 $rfc->close();
111

  ViewVC Help
Powered by ViewVC 1.1.26