Académique Documents
Professionnel Documents
Culture Documents
#***************************************************************
#!/bin/ksh
echo `date +'%m_%d_%y%h:%m:%s'` "******************begin of bteq
task******************* "
stage_database="$1"
stage_table="$2"
target_database="$3"
target_table="$4"
bteq_file="$5"
rpt_data="$6"
bteq <<eofbteq
`/bin/cat $rpt_pass`
.export file=$max_date_file
sel coalesce(max(dw_eff_dt),cast('0001-01-01'as date)) (format 'yyyymmdd') (title
'') from $target_database.$target_table;
.export reset
.quit;
eofbteq
# catch the return code
err1=$?
if [ $err1 -ne 0 ]
then
echo `date +'%m_%d_%y%h:%m:%s'` "error while getting max(dw_eff_dt) from
$target_database.target_table"
exit 1
else
echo `date +'%m_%d_%y%h:%m:%s'` "max(dw_eff_dt) exported successfully"
fi
#put in a variable the max date
max_date=`/bin/cat $max_date_file`
echo "max_date = $max_date"
if [ $max_date == '00010101' ]
then
echo "no max_date in $target_database.$target_table"
else
echo "get the 3rd business day of the month of max(dw_eff_dt)"
business_day3_file=/opt/idw/pr/data/business3.dat
rm -f $business_day3_file
bteq <<eofbteq
`/bin/cat $rpt_pass`
.export file=$business_day3_file
.export reset
.quit;
eofbteq
business_day3=`/bin/cat $business_day3_file`
if [ -z $business_day3 ]
then
echo "error in retrieving 3rd business day from the date dimension table"
exit 1
else
echo "3rd business day =$business_day3"
fi
if [ $max_date == $business_day3 ]
then
echo "max date from monthly table same as the 3rd business day for the month"
else
bkp=$target_table'_bk'
bteq<<eofbteq
`/bin/cat $rpt_pass`
.set errorlevel 3108 severity 0;
drop table $stage_database.$bkp;
.set errorlevel 3108 severity 8;
sed -e "s/\$stage_database/$stage_database/g" -e
"s/\$target_database/$target_database/g" $bteq_file >$temp_bteq
# concatenate passwd file and temp bteq file to a combined temp file
cat $rpt_pass $temp_bteq > $comb_bteq
# call bteq to load target table
bteq <$comb_bteq
if [ $err1 -ne 0 ]
then
echo `date +'%m_%d_%y%h:%m:%s'` "error while loading records from staging
table to target table"
exit 1
else
echo `date +'%m_%d_%y%h:%m:%s'` "records loaded from stage table to target
table $target_database.$target_table"
fi
echo `date +'%m_%d_%y%h:%m:%s'` "****************end of bteq task ***************
"