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

Annotation of /dir2sap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Mon Mar 24 16:35:39 2003 UTC (21 years, 1 month ago) by dpavlin
Branch: MAIN
Changes since 1.1: +23 -4 lines
File MIME type: text/plain
lims changes

1 dpavlin 1.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 dpavlin 1.2 use Fcntl; # For O_RDWR
11     use NDBM_File;
12 dpavlin 1.1
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 dpavlin 1.2 local $SIG{__DIE__} = sub { print LOG scalar localtime," ",$_[0] ; die $_[0] };
31 dpavlin 1.1
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 dpavlin 1.2 tie %dbmhash, "NDBM_File", $dbm, O_RDWR, 0666 || die "tie: can't tie to '$dbm': $!";
40 dpavlin 1.1
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 dpavlin 1.2
53     print STDERR "Using '$indir' as input directory...\n";
54    
55     opendir(DIR, $indir) || die "can't opendir $indir: $!";
56     my @files = grep { !/^\./ && -f "$indir/$_" } readdir(DIR);
57     closedir DIR;
58    
59     print LOG scalar localtime," Found ",$#files+1," files in directory...\n";
60    
61     foreach my $file (@files) {
62     if ($dbmhash{$file}) {
63     print LOG scalar localtime," New file '$file', processing...\n";
64     $dbmhash{$file}++;
65     } else {
66     print STDERR scalar localtime," Skipping file '$file'\n";
67     }
68     }
69    
70     exit 1; # fix
71 dpavlin 1.1
72     my $it = $rfc->discover($config->{sap}->{discover}) || die "FATAL: SAP discover: $!";
73    
74     foreach my $p ($config->{sap}->{params}) {
75     foreach my $p_name (keys %{$p}) {
76     # print "$p_name --> ",$p->{$p_name},"\n";
77     $it->$p_name($p->{$p_name});
78     }
79     }
80    
81     ## FIX
82     my $file="foobar";
83    
84     # override FILENAME with my name
85     $it->FILENAME($file);
86     print "Using file '$file'\n";
87    
88     # call SAP R/3
89     $rfc->callrfc( $it );
90    
91     $rfc->close();
92    

  ViewVC Help
Powered by ViewVC 1.1.26