#!/usr/bin/qsh
##
##
##  IBM Confidential OCO Source Material
##
##  5724-I63, 5724-H88, 5655-N02, 5733-W70 (C) COPYRIGHT International Business Machines Corp. 2005
##
##  The source code for this program is not published or otherwise divested
##  of its trade secrets, irrespective of what has been deposited with the
##  U.S. Copyright Office.
##
## ----------------------------------------------------------------------------

## Script that creates the fast purge stored procedure

## Define variables for the library, file and member that will hold the source physical file 
## with the SQL commands that will be run with the RUNSQLSTM command.

CURRENT_DIR=`dirname $0`
if [ "$CURRENT_DIR" = "." ] ; then
   CURRENT_DIR=`pwd`
fi

IFS_FILE=$CURRENT_DIR/cr_stpr.db2
SRC_LIB=##collection#
SRC_FILE=STPC
SRC_MBR=STPC  

## Define variables for parameters to the CPYFRMSTMF command.  This will copy the contents of the IFS file holding
## the SQL statements to an iSeries source physical file so that they can be executed using the RUNSQLSTM command.
QSYS=QSYS.LIB
QLIB=${SRC_LIB}.LIB
QFILE=${SRC_FILE}.FILE
QMBR=${SRC_MBR}.MBR  
                  
## Issue the CL commands to the iSeries to eventually create the stored procedure for the fast delete.  
system "CRTLIB ${SRC_LIB}"
system "CRTSRCPF FILE(${SRC_LIB}/${SRC_FILE}) RCDLEN(240) MBR($SRC_MBR)" 
system "CPYFRMSTMF FROMSTMF('''${IFS_FILE}''') TOMBR('''/${QSYS}/${QLIB}/${QFILE}/${QMBR}''') MBROPT(*REPLACE)"
system "RUNSQLSTM SRCFILE(${SRC_LIB}/${SRC_FILE}) SRCMBR(${SRC_MBR}) COMMIT("'*'"NONE) NAMING("'*'"SQL)"         
