/[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.2 - (show annotations)
Mon Feb 3 13:36:52 2003 UTC (21 years, 2 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +3 -1 lines
File MIME type: text/plain
final fixups

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 my $outfile = $config_file;
33 $outfile =~ s/\.xml//i;
34 $outfile =~ s/^.*\/([^\/]+)/$1/i; # basename
35 $outfile .= "_${yy}-${mm}-${dd}_${hh}:${mm}:${ss}_$$";
36
37 my $rfc = new SAP::Rfc(
38 ASHOST => $config->{sap}->{ashost},
39 USER => $config->{sap}->{user},
40 PASSWD => $config->{sap}->{passwd},
41 LANG => $config->{sap}->{lang},
42 CLIENT => $config->{sap}->{client},
43 SYSNR => $config->{sap}->{sysnr},
44 TRACE => $config->{sap}->{trace}
45 ) || die "new: $!";
46
47 $rfc->is_connected || die "FATAL: SAP not connected";
48
49 my $it = $rfc->discover($config->{sap}->{discover}) || die "FATAL: SAP discover: $!";
50
51 foreach my $p ($config->{sap}->{params}) {
52 foreach my $p_name (keys %{$p}) {
53 # print "$p_name --> ",$p->{$p_name},"\n";
54 $it->$p_name($p->{$p_name});
55 }
56 }
57
58 # override FILENAME with my name
59 $it->FILENAME($outfile);
60 print "Using file '$outfile'\n";
61
62 my @data; # array for order
63 my $lines; # number of lines in order
64
65 my $first = <STDIN>;
66 push @data,$first;
67 chomp $first;
68 $first=~s/
69 //g;
70 if ($first =~ m/\s+(\d+)\w+\s*$/) {
71 $lines = $1;
72 print "Processing $lines lines\n";
73 } else {
74 die "FATAL: can't find number of lines in first line ($first) of input file.";
75 }
76
77 # suck file in array
78 while(<STDIN>) {
79 push @data,$_;
80 }
81
82 # check integrity of file
83 if ($#data != $lines) {
84 print "FATAL: file integrity check failed: ";
85 if ($#data > $lines) {
86 print "too many";
87 } else {
88 print "too few";
89 }
90 print " lines ($#data)...\n";
91 } else {
92 print "File integrity checked, saving file...\n";
93 open(OUT, "> $outdir/$outfile") || die "FATAL: can't open '$outdir/$outfile': $!";
94
95 # dump order to file
96 print OUT $first,@data;
97 close(OUT);
98
99 # call SAP R/3
100 $rfc->callrfc( $it );
101 }
102
103 $rfc->close();
104

  ViewVC Help
Powered by ViewVC 1.1.26