/[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.3 - (show annotations)
Mon Feb 3 14:24:55 2003 UTC (21 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.2: +8 -3 lines
File MIME type: text/plain
cludged version to nark.0004

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 $_[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 .= "_${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
66 my $first = <STDIN>;
67 push @data,$first;
68 chomp $first;
69 $first=~s/
70 //g;
71 if ($first =~ m/\s+(\d+)\s+(\d+)\w+\s*$/) {
72 my ($nr,$lines) = ($1,$2);
73 print "Processing $lines lines order no. $nr\n";
74 } 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 print "too many";
88 } else {
89 print "too few";
90 }
91 print " lines ($#data)...\n";
92 } 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
100 # cludge filename to nark.0004
101 rename "$outdir/$outfile", "$outdir/nark.0004";
102 $it->FILENAME("nark.0004");
103
104 # call SAP R/3
105 $rfc->callrfc( $it );
106 }
107
108 $rfc->close();
109

  ViewVC Help
Powered by ViewVC 1.1.26