/[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.2 - (hide 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 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     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 dpavlin 1.2 $outfile =~ s/^.*\/([^\/]+)/$1/i; # basename
35 dpavlin 1.1 $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 dpavlin 1.2 $first=~s/ //g;
69     if ($first =~ m/\s+(\d+)\w+\s*$/) {
70 dpavlin 1.1 $lines = $1;
71     print "Processing $lines lines\n";
72     } else {
73     die "FATAL: can't find number of lines in first line ($first) of input file.";
74     }
75    
76     # suck file in array
77     while(<STDIN>) {
78     push @data,$_;
79     }
80    
81     # check integrity of file
82     if ($#data != $lines) {
83     print "FATAL: file integrity check failed: ";
84     if ($#data > $lines) {
85     print "too many";
86     } else {
87     print "too few";
88     }
89     print " lines ($#data)...\n";
90     } else {
91     print "File integrity checked, saving file...\n";
92     open(OUT, "> $outdir/$outfile") || die "FATAL: can't open '$outdir/$outfile': $!";
93    
94     # dump order to file
95     print OUT $first,@data;
96     close(OUT);
97    
98     # call SAP R/3
99     $rfc->callrfc( $it );
100     }
101    
102     $rfc->close();
103    

  ViewVC Help
Powered by ViewVC 1.1.26