/[sap_import]/dir2sap.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 /dir2sap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Mon Mar 24 17:12:15 2003 UTC (21 years ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +5 -7 lines
File MIME type: text/plain
oh, a working (semi) version

1 #!/usr/bin/perl -w
2 #
3 # Read files from directory and import them to SAP
4 #
5
6 use strict;
7 use SAP::Rfc;
8 use Data::Dumper;
9 use XML::Simple;
10 use Fcntl; # For O_RDWR
11 use DB_File;
12
13 my $config_file;
14
15 if ($#ARGV < 0) {
16 print "usage: $0 config.xml\n";
17 exit 1;
18 } else {
19 $config_file = $ARGV[0];
20 }
21
22 $|++;
23
24 my $config = XMLin($config_file);
25
26 my $log = $config->{log} || die "config: no <log> defined";
27
28 # open log and redirect die to it...
29 open(LOG,">> $log") || warn "open log $log: $!";
30 local $SIG{__DIE__} = sub { print LOG scalar localtime," ",$_[0] ; die $_[0] };
31
32 # directory in which are files
33 my $indir = $config->{indir} || die "config: no <indir> defined";
34
35 # directory in which are files
36 my $dbm = $config->{dbm} || die "config: no <dbm> defined";
37
38 my %dbmhash;
39 dbmopen %dbmhash, $dbm, 0666 || die "tie: can't tie to '$dbm': $!";
40
41 my $rfc = new SAP::Rfc(
42 ASHOST => $config->{sap}->{ashost},
43 USER => $config->{sap}->{user},
44 PASSWD => $config->{sap}->{passwd},
45 LANG => $config->{sap}->{lang},
46 CLIENT => $config->{sap}->{client},
47 SYSNR => $config->{sap}->{sysnr},
48 TRACE => $config->{sap}->{trace}
49 ) || die "new: $!";
50
51 $rfc->is_connected || die "FATAL: SAP not connected";
52
53 opendir(DIR, $indir) || die "can't opendir $indir: $!";
54 my @files = grep { !/^\./ && -f "$indir/$_" } readdir(DIR);
55 closedir DIR;
56
57 print LOG scalar localtime," Found ",$#files+1," files in directory...\n";
58
59 foreach my $file (@files) {
60 if (exists $dbmhash{$file}) {
61 print STDERR scalar localtime," Skipping file '$file'\n";
62 } else {
63 print LOG scalar localtime," New file '$file', processing...\n";
64 $dbmhash{$file}++;
65 }
66 }
67
68 exit 1; # fix
69
70 my $it = $rfc->discover($config->{sap}->{discover}) || die "FATAL: SAP discover: $!";
71
72 foreach my $p ($config->{sap}->{params}) {
73 foreach my $p_name (keys %{$p}) {
74 # print "$p_name --> ",$p->{$p_name},"\n";
75 $it->$p_name($p->{$p_name});
76 }
77 }
78
79 ## FIX
80 my $file="foobar";
81
82 # override FILENAME with my name
83 $it->FILENAME($file);
84 print "Using file '$file'\n";
85
86 # call SAP R/3
87 $rfc->callrfc( $it );
88
89 $rfc->close();
90

  ViewVC Help
Powered by ViewVC 1.1.26