Wednesday 27 May 2015

Shell Script to Call the PL/SQL Package

#!/bin/ksh
#------------------------------------------------------------------------------
#   Filename    :    XXERPCSAMPLE.prog
#   Description :    This shell script process Transaction Files
#   Copyright   :    ERPC Corporation 2015
#----+------------+---------+--------------------+-----------------------------
#--  |Date        |Version  |Author Name         |Description
#----+------------+---------+--------------------+-----------------------------
#--  |18-May-2015 | 1.0     |Prasad Bheemavarapu |Initial creation
#----+------------+---------+--------------------+-----------------------------
l_program_name=$0
l_oracle_id=$1
l_user_id=$2
l_request_id=$4
l_operating_unit=$5
l_file_name=$6
l_rice_id=$7
l_resp_id=$8
l_exit=0

l_file_dir=`sqlplus  -s $1 <<!
                       set heading off
                       set pagesize 0
                       set newpage none
                       set termout off
                       set echo off
                       set recsep off
                       set linesize 1024
                       set feedback off
                       set serveroutput on
                       declare
                       l_path VARCHAR2(100);
                       begin
                            SELECT  attribute4
                            INTO   l_path
                            FROM   fnd_lookup_values
                            WHERE  lookup_type = 'XX_IEXP_611_CC_FILE_MAPPING'
                            AND    attribute1 = $l_operating_unit
                            AND    LANGUAGE = 'US';
                            dbms_output.put_line(l_path);
                       end;
                       /
                      EXIT
!
`

echo "Inbound File Directory : "$l_file_dir

l_file_dir=`echo $l_file_dir/$l_file_name`

echo "Inbound File Directory File Name: "$l_file_dir

for file in $(find $l_file_dir -name "*.*")
do          
echo -e "\n=====================================================\n" 

    l_file_path=""
    l_file_name=""
    l_error_code=2;
    l_file_path=$file
    l_bfile_name=`basename $file`;
    l_file_name=$l_file_path
    echo "Base File Name: "$l_bfile_name
    echo "File Path: "$l_file_path

#Calling the Package to Submit Oracle Standard Programs.
   
    l_return_status=`sqlplus  -s $1 <<!
                           set heading off
                           set pagesize 0
                           set newpage none
                           set termout off
                           set echo off
                           set recsep off
                           set linesize 1024
                           set feedback off
                           set serveroutput on
                           begin                            xx_ap_cc_trxn_int_pkg.cc_trx_files_processer('$l_operating_unit'
                                            ,'$l_file_name'
                                            ,'$l_user_id'
                                           ,'$l_resp_id');
                           end;
                           /
                          EXIT
    !
    `

#Fetching the Request_id and Request Status

    l_req_status=`echo $l_return_status | cut -d' ' -f1`
    l_request_id=`echo $l_return_status | cut -d' ' -f2`

    echo "Request Id     : "$l_request_id
    echo "Request Status : "$l_req_status

#Fetching the Request_id log path

    l_log_path=`sqlplus  -s $1 <<!
                           set heading off
                           set pagesize 0
                           set newpage none
                           set termout off
                           set echo off
                           set recsep off
                           set linesize 1024
                           set feedback off
                           set serveroutput on
                           declare
                           l_log_path VARCHAR2(200);
                           begin
                                SELECT  LOGFILE_NAME
                                INTO   l_log_path
                                FROM   fnd_concurrent_requests
                                WHERE  request_id = '$l_request_id';
                                dbms_output.put_line(l_log_path);
                           end;
                           /
                          EXIT
    !
    `

 # Searching the Log File and check Whether the transactions get loaded

    l_trx_status=""

    l_trx_status=`cat $l_log_path | grep "No credit card transactions were uploaded"`

    echo "Trx Status : "$l_trx_status

    # Archive the datafile post load to the archive directory

    if [ "$l_req_status" == "Error" ];then
        echo "File Not Archived, Error while processeing..."
        elif [ "$l_trx_status" == "No transactions were uploaded." ];then
        echo "Credit Card Transactions Not Processed, Error while processeing..."
        else
        DATFILE=`echo $l_bfile_name | cut -f1 -d'.'`
        EXTN=`echo $l_bfile_name | cut -f2 -d'.'`
        now=$(date +"%Y%m%d%s")
        echo $DATFILE"_"$now"."$EXTN
        echo "File Archived : "$file
    fi   
done

exit 0;

Package Referenc: Get Transaction Details

No comments:

Post a Comment