Code:
###########################################################################
# Description: This perl does the following:
# 1.Checks if the target load has completed successfully.If so,
# truncates the stage table.
# 2.Mails the no. of records loaded in case the target load has happened.
##############################################################################l
#
# Modification History:
#
#
###############################################################################
$Program = $0 ; $Program =~ s/.*\/// ;
$MyDir = $0 ; $MyDir =~ s/[^\/]*$// ;
push ( @INC, "$ENV{Samp_COMMON_SCR}" ) ;
push (@INC, "$ENV{Samp_SCR}") ;
$SIG{'INT'} = "sub_handle" ;
$SIG{'TERM'} = "sub_handle" ;
require "getopts.pl" ;
require "Samp_misc.pl" ;
require "Samp_exit.pl" ;
require "Samp_db.pl";
require "Samp_job.pl";
require "Samp_log_error.pl";
require "www_gi_date_ext.pl";
###############################################################################
# Get user input.
###############################################################################
&Getopts ( "j:h" ) ;
if ( defined ( $opt_h ) )
{
&print_help_msg ;
&sub_exit ( 0 ) ;
}
if ( !defined ( $opt_j ) )
{
&Samp_msg("Option j - Autosys Job name required",ERROR);
&sub_exit(9) ;
}
else
{
$job_name = $opt_j;
&Samp_msg("Reading autosys job name - $job_name","",INFO,$job_name);
$jobname = $job_name;
}
###############################################################################
# Creates connection to Database.
###############################################################################
if ( ! ( $dbh = &Samp_user_ora_connect ) )
{
&Samp_msg ( "*** Failed to open connection to $ENV{'Samp_ORA_SID'}***","",ERROR,$job_name ) ;
&sub_exit ( 9 ) ;
}
#=============================================================================#
# Pre-load. Makes an entry in job_run table and job_step_run table
#=============================================================================#
#$res=&Samp_ins_job_run('I',$job_name);
#if ($res) { &Samp_db_close(\$dbh); &sub_exit ( 9 ) ; }
#$res=&Samp_insupd_job_step_run('I',$job_name,'fiusicanlt_qt_ramp_chk','I');
#if ($res) { &Samp_db_close(\$dbh); &sub_exit ( 9 ) ; }
#$res=&Samp_insupd_job_step_run('I',$job_name,'wwww_LDING_CNT_VALIDN','I');
#if ($res) { &Samp_db_close(\$dbh); &sub_exit ( 9 ) ; }
# declaring the count to 5
##################Get records loaded from file generated by Informatica #############
#change the directory to $Samp_RECEIVE
cd $Samp_RECEIVE ;
# see the files that start with feedmgr.usfed.tips
$CycleDate = &fi_get_curr_date('US','batch','PROCESS');
@filelist = `head -1 GNM_GEO.DAT.EMBS* |grep -v GNM_GEO.DAT.EMBS | awk '{$4 $5}'`;
foreach $item (@filelist)
{
&Samp_msg (" item is equal to ","",INFO,$item ) ;
$filedate = `$item | awk '{ $2}'`;
if ($filedate = $CycleDate)
{
###############################################################################
# Call procedure wwww_LDING_CNT_VALIDN
###############################################################################
&Samp_msg (" Job Name: $job_name ","",INFO,$job_name ) ;
$sql_header= "BEGIN Metric.IDX_wwww_LOADING_PKG.wwww_LDING_CNT_VALIDN(
:pv_out_stg_rowcount,
:pv_out_tgt_rowcount,
:pv_out_cnt_matched,
:pv_in_tgt_rowcount,
:pv_in_jobname
);
:st :=0;
EXCEPTION
WHEN OTHERS THEN
:st:=1;
:st_err_no:=-1 *sqlcode;
:st_err:=sqlerrm;
END;";
my $sth = $dbh->prepare($sql_header);
$sth->bind_param_inout(":pv_out_stg_rowcount",\$stg_count,15);
$sth->bind_param_inout(":pv_out_tgt_rowcount",\$tgt_count,15);
$sth->bind_param_inout(":pv_out_cnt_matched",\$matched,15);
$sth->bind_param(":pv_in_jobname",$job_name);
$sth->bind_param(":pv_in_tgt_rowcount",$rec_cnt);
$sth->bind_param_inout(":st_err_no",\$errno,10);
$sth->bind_param_inout(":st",\$status,5);
$sth->bind_param_inout(":st_err",\$err_msg,1000);
$sth->bind_param_inout(":st",\$status,5);
$sth->execute();
&Samp_msg(" Stage Records processed $stg_count","",INFO,$job_name);
&Samp_msg("Target record count $tgt_count","",INFO,$job_name);
&Samp_msg("The matched flag:$matched","",INFO,$job_name);
&Samp_msg("Error message:$err_msg","",INFO,$job_name);
&Samp_msg(" Mailing flag $mail_ind","",INFO,$job_name);
&Samp_msg(" Status:$status","",INFO,$job_name);
}
else
{
&Samp_msg ( "Received SAT Ctrl-C from the user. Aborting.","",ERROR ) ;
&sub_exit (9) ;
}
}
###############################################################################
# The End.
###############################################################################
&sub_exit ( 0 ) ;
###############################################################################
sub sig_handle
###############################################################################
{
my ( $signame ) = @_ ;
if ( $signame eq "INT" )
{ &Samp_msg ( "Received SAT Ctrl-C from the user. Aborting.","",ERROR ) ; }
if ( $signame eq "TERM" )
{ &Samp_msg ( "Received termination signal (15). Aborting.","",ERROR ) ; }
$res=&Samp_upd_job_run('U',$jobname,'F');
&Samp_db_close(\$dbh);
&sub_exit ( 9 ) ;
}
###############################################################################
sub print_help_msg
#
# Description: Prints the usage information for the script.
# Input: None.
# Output: The usage information is written to STDERR.
###############################################################################
{
print STDERR "
Usage:
\$Samp_PERL \$Samp_SCR/$Program -j<Job name> [-h help]
where,
-h Print this message and exit.
-j Jobname corresponding to the perl script
" ;
}