Hi All,
please help me in understanding this script.
##1./dbopt/mounts/apps/irfora/utils/scr
use DBI;
use lib "$ENV{IRF_ORA_HOME}/utils/scr";
use UTILS_ORA('mailing', 'db_connect');--The script location
/dbopt/mounts/apps/irfora/utils/scr
sub SendErr;
#sub mailing;
my @FN = split /\//, $0;
my $scn = $FN[$#FN];
my $stErr = "";
my $lfe = 0;
my $strFl;
unless (@ARGV) {
print "The program $scn always should run with DMS_Key as an argment!\n";
exit 1;
}
$addr = '[email protected]';
$imid = $ARGV[0]; ### data move key
$loadzone_dir = $ENV{IRF_ORA_LOADZONE};
$run_dir = $ENV{IRF_ORA_LOADZONE}.'/run/acrv';
%cntr_fas = (PAR => [],
CONTROL_PAR => []);
$cdErr = 0;
my %MON = ( JAN => '01',
FEB => '02',
MAR => '03',
APR => '04',
MAY => '05',
JUN => '06',
JUL => '07',
AUG => '08',
SEP => '09',
OCT => '10',
NOV => '11',
DEC => '12');
@els = ();
### get move id by executing "select init_dms_key(<load id>, <source code>,
<load type>) from dual"
$dbh = db_connect($ENV{IRF_ORA_INST_AR}, $ENV{IRF_ORA_DB_LOGIN});
### get control data for Audit 2 from DATA_MOVE_SUMMARY table
$str = "SELECT dms_load_id, dms_loadsource_cd, dms_loadtype,
dms_paypdend_dt,
dms_parrun_dt, dms_filecreate_dt
FROM irfetl.data_move_summary
WHERE dms_key = ".$imid;
$dms_dt = $dbh->selectrow_hashref($str);
@dat = split(/\-/, $$dms_dt{DMS_PAYPDEND_DT});
$pped = "20$dat[2]$MON{$dat[1]}$dat[0]";
unless ($$dms_dt{DMS_PARRUN_DT}){
$dbh->do("call irf_mdmv.ins_move_log($imid, '$scn', 0, 'It si missing PAR
Run Date')");
mailing($addr, "Error in ACRV Audit 2", "It si missing PAR Run Date");
exit 1;
}
open LOG, ">$$dms_dt{DMS_LOADTYPE}.log";
$strFl = `ls $loadzone_dir | grep $imid.ACRV.`;
@fls = split (/\n/, $strFl);
#print "$_\n" foreach (@fls);
unless (@fls) {
$stErr = "The file set of $imid.$$dms_dt{DMS_LOADTYPE}.* is missing in
$loadzone_dir!";
$dbh->do ("call irf_mdmv.ins_move_log($imid, '$scn', 0, '$stErr')");
exit 1;
} elsif (@fls != 2){
$stErr = "The file set of $imid.$$dms_dt{DMS_LOADTYPE}.* is not
consistent in $loadzone_dir!";
$dbh->do ("call irf_mdmv.ins_move_log($imid, '$scn', 0, '$stErr')");
exit 1;
} else {
open(RCF, "<$loadzone_dir/$fls[0]")
or SendErr("Cannot open file $loadzone_dir/$fls[0]!", 1, 0, $fls[0]);
$cln = <RCF>;
close(RCF);
@els = split(/\|\*\|/, $cln);
$lfe = chomp($cln); ### get the length of the line end character.
SendErr("Pay Period End Date is different from table DATA_MOVE_SUMMARY
for $fls[0]!", 1, 0, $fls[0])
if ($els[0] - $pped);
SendErr("The BatchID is different from table DATA_MOVE_SUMMARY for
$fls[0]!", 1, 0, $fls[0])
if ($els[1] - $$dms_dt{DMS_LOAD_ID});
SendErr("The two BatchIDs are different from each other in $fls[0]!
$els[1] - $els[22]", 1, 0, $fls[0])
if ($els[1] - $els[22]);
### write into control data file
open(WCF, ">$run_dir/$imid.CONTROL_PAR.dat")
or SendErr("Cannot open file $run_dir/$imid.CONTROL_PAR!", 1, 0,
"$imid.CONTROL_PAR");
printf(WCF "%10s\|\*\|%s\n", $imid, $cln);
close(WCF);
### insert record into Data move log table
}
unless ($stErr) {
$dbh->do("call irf_mdmv.ins_move_log($imid, '$scn', 1, 'File
$imid.CONTROL_PAR.dat created in $run_dir')");
}
open(RCF, "<$loadzone_dir/$fls[1]")
or SendErr("Cannot open file $loadzone_dir/$fls[1]}!", 1, 0, $fls[1]);
@cdf = <RCF>;
close(RCF);
open(WCF, ">$run_dir/$imid.PAR.dat")
or SendErr("Cannot open file $imid.PAR.dat!", 1, 0, $scn);
for($i=0; $i < @cdf; $i++) {
### gets substring from the line
$dfped = substr($cdf[$i], 33, 8);
$dfbtc = substr($cdf[$i], 1106, 6);
$dfnam = substr($cdf[$i], 60, 30);
$dfbeg = substr($cdf[$i], 0, 60);
$dfend = substr($cdf[$i], 90);
#$dfnam =~ s/\s+//g;
$dfend =~ s/\|\*\|NULL/\|\*\| /g;
### separate last and first name
($ln, $fn) = split(/\,/, $dfnam);
$lln = length($cdf[$i]) - $els[3] - $lfe;
if ($lln) {
SendErr("Inconsistent row length in $fls[1]", 1, 0, $scn);
last;
}
if($dfbtc eq $els[1]) { ### checks for batch
$els[7]--;
} elsif($dfbtc eq $els[22]) { ### checks for batch
$els[24]--;
} else {
stErr("Different BatchID in $fls[1] for linr # $i");
last;
}
printf(WCF "%10s|*|%s%-30s|*|%-30s%s", $imid, $dfbeg, $ln, $fn, $dfend);
}
SendErr("Different number of lines between the number in control file and
$fls[1]", 1, 0, $scn)
if ($els[7] + $els[24]);
SendErr($stErr, 1, 0, $scn) if ($stErr);
close(LOG);
close(WCF);
$dbh->do("call irf_mdmv.ins_move_log($imid, '$scn', 1, 'File $imid.PAR.dat
created in $run_dir')");
unlink "$$dms_dt{DMS_LOADTYPE}.log";
exit 0;
######## SUBS ###############################
### sub SendErr (<Err Msg>, <Exit Cd>, <Succs Flag>, <FileName>)
sub SendErr {
my $str_s = "call irf_mdmv.ins_audit_log($imid, '$_[3]', $_[2], '$_[0]',
'$scn')";
print LOG $_[0], "\n" unless ($_[2]);
$dbh->do($str_s);
if ($_[1]) {
close LOG;
mailing($recp, "Error in FAS audit 2", "temp.log");
unlink "temp.log";
exit $_[1];
} else {
print LOG "$_[0]\n" unless ($_[2]);
}
}
--
with regards
Uday V G
*********************************************************
Don't ask them WHY they hurt you,
because all they'll tell you is lies and excuses.
Just know they were wrong, and try to move on.
**********************************************************