Showing posts with label Unix Scripts. Show all posts
Showing posts with label Unix Scripts. Show all posts

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

Sunday, 24 May 2015

Standard Parameters in Shell Scripting

Shell Script System Parameters

The five standard parameters do not need to be defined on the Concurrent Program Parameters Form:
$0 Name of the Concurrent Program
$1 Oracle User ID/PASSWORD
$2 User ID (numeric representation)
$3 User Name that submitted the request (character representation)
$4 Request ID for the request

Creating a Soft Link

ln -s $FND_TOP/bin/fndcpesr XXCMNLDT

Submitting a Concurrent Program from Shell 


CONCSUB username/pwd RESP_APPL_SHORT_NAME RESP_SHORT_NAME USER_NAME WAIT=N  CONCURRENT APPL_SHORT_NAME CONC_PGM_SHORT_NAME START=SYSDATE 'PARAMETER1' $PARAMETER2

CONCSUB $1 SQLAP 'W - WPC - AP' $3 WAIT=Y CONCURRENT SQLAP APXVVCF4 START='"29-Jul-2010 15:24:00"' '10000' $FILE_DIR;




Friday, 30 January 2015

Shell script to load the data into staging table


#!/bin/sh
#*******************************************************************************#
#  VERSION              : @(#)$Revision: 1.0 $
#
#  DATE                 : @(#)$Date: Thursday, sep 28, 2004 2:24:2 $
#
#  DESCRIPTION          : This is Generic to Load data into staging table
#                         This can be used for all the conversion
#                         Its supports all type of valid Extension Like .csv,.dat,.txt
#
#  PARAMETERS           : 1 - File Name with Extension
#                         2 - Control File Name Without Extension
#
#  MODIFICATION HISTORY :
#    Name               Date         Ver    Description
#    ------------------ -----------  --- --------------------------------------
#    Prasad/Ranjit      30-JAN-2015  1.0    File Creation
#
#******************************************************************************

#pi=$1
#echo $pi
DB_LOGIN=$1
DATFILE1=$5
DATFILE=`echo $DATFILE1 | cut -f1 -d'.'`
EXTN=`echo $DATFILE1 | cut -f2 -d'.' | cut -f1 -d'"'`
CTLFILE=$6
SQLLDR=sqlldr

#
# Collect parameters
#
# the file we're going to SQL*Load
# Data file
#DATFILE=$2
# CTL file to SQL*Load
#CTLFILE=$3

#echo  $CTLFILE $DATFILE


# Set subdirectories
CTLDIR=$XCONV_TOP/bin
#DATDIR=$XBOL_TOP/bin
DATDIR=$XCONV_TOP/datafile/infile
ARCHIVEDIR=$XCONV_TOP/datafile/archive
LOGDIR=$XCONV_TOP/datafile/logfile
BADDIR=$XCONV_TOP/datafile/badfile
#echo $FILEID
echo $CTLFILE
echo $DATFILE1

# Set loader files
LOG=$LOGDIR/${DATFILE}`date +%d%m%Y%H%M%S`.log
BAD=$BADDIR/${DATFILE}`date +%d%m%Y%H%M%S`.bad
DATA=$DATDIR/${DATFILE}.${EXTN}
CTL=$CTLDIR/${CTLFILE}.ctl
#DATA=${DATAFILE}.csv

echo $LOG
echo $BAD
echo $DATA
echo $CTL

# Archive the datafile post load to the archive directory
cp $DATA $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc
echo copied the datafile for archiving to $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc

$SQLLDR userid=$DB_LOGIN control=$CTL  log=$LOG bad=$BAD data=$DATA errors=10000
RESULT=$?

count=`cat $LOG | grep "successfully loaded" | cut -dR -f1`

# Cat the log and bad file if there was an error.
if [ "$RESULT" != "0" ] ; then
  cat $LOG

  if [ -f $BAD ] ; then
    cat $BAD
  fi
#  if [ "$count" != "0" ] ; then
#    exit 225  
#  fi
# Otherwise extract the counts from the
else
count=`cat $LOG | grep "successfully loaded" | cut -dR -f1`
echo "$count Records are loaded"
exit $RESULT
fi

# Archive the datafile post load to the archive directory
#mv $DATA $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc
#echo moved the datafile for archiving to $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc

# Return SQL Load result

# exit $RESULT