/[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

Annotation of /pipe2sap.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 dpavlin 1.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 dpavlin 1.8 local $SIG{__DIE__} = sub { print LOG scalar localtime,$_[0] ; die $_[0] };
25 dpavlin 1.1
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 dpavlin 1.3 $mm++;
33 dpavlin 1.1 my $outfile = $config_file;
34     $outfile =~ s/\.xml//i;
35 dpavlin 1.2 $outfile =~ s/^.*\/([^\/]+)/$1/i; # basename
36 dpavlin 1.5 $outfile .= sprintf("_%04d-%02d-%02d_%02d:%02d:%02d_%d",$yy,$mm,$dd,$hh,$mm,$ss,$$);
37 dpavlin 1.1
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 dpavlin 1.4 my $nr; # order number
66 dpavlin 1.1
67     my $first = <STDIN>;
68     push @data,$first;
69     chomp $first;
70 dpavlin 1.2 $first=~s/ //g;
71 dpavlin 1.3 if ($first =~ m/\s+(\d+)\s+(\d+)\w+\s*$/) {
72 dpavlin 1.4 ($nr,$lines) = ($1,$2);
73 dpavlin 1.3 print "Processing $lines lines order no. $nr\n";
74 dpavlin 1.1 } else {
75     die "FATAL: can't find number of lines in first line ($first) of input file.";
76     }
77    
78     # suck file in array
79     while(<STDIN>) {
80     push @data,$_;
81     }
82    
83     # check integrity of file
84     if ($#data != $lines) {
85     print "FATAL: file integrity check failed: ";
86     if ($#data > $lines) {
87 dpavlin 1.4 print "too many ($#data > $lines)";
88 dpavlin 1.1 } else {
89 dpavlin 1.4 print "too few ($#data < $lines)";
90 dpavlin 1.1 }
91 dpavlin 1.4 print " lines...\n";
92 dpavlin 1.1 } else {
93     print "File integrity checked, saving file...\n";
94     open(OUT, "> $outdir/$outfile") || die "FATAL: can't open '$outdir/$outfile': $!";
95    
96     # dump order to file
97     print OUT $first,@data;
98     close(OUT);
99 dpavlin 1.3
100 dpavlin 1.6 # cludge filename to medika
101     link("$outdir/$outfile","$outdir/medika");
102     chmod 0664,"$outdir/medika";
103     $it->FILENAME("medika");
104 dpavlin 1.1
105     # call SAP R/3
106     $rfc->callrfc( $it );
107     }
108    
109     $rfc->close();
110    

  ViewVC Help
Powered by ViewVC 1.1.26