#!/bin/ksh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


########################################################################
# ENDPROC                                                              #
# EBM BATCH JOB MACRO :     ENDPROC                                    #
# Purpose             :     Define the end of a procedure              #
########################################################################
. verify_jobstatus
. beginjob.${EBMSYS}.${JON}
. current_proc_level.${EBMSYS}.${JON}

for argument in $*
do
  i=`eval echo $argument`
  case $i in
    verbose*)
      VERBOSE=YES
      export VERBOSE 
      ;;
    *)
      print_message ENDPROC "Invalid parameter specified :   $i" 
      . set_jobstatus_abort
      break
      ;;
  esac
done

if [ $BATCH_MODE = VSE ]
then
   . endproc.update_callers_parms
fi

if [ "a$PROCNAME" != "a" ]
then
      print_message_PROCNAME=$PROCNAME; export print_message_PROCNAME
fi

#------------------------------------------------------------------------------
# if we never satisfied a procedure step restart 
# (PRESTART != BeginProc)
# abort.
#------------------------------------------------------------------------------
PRESTART=`cat prestart.${EBMSYS}.${JON}`
if [ "$PRESTART" != "BeginProc" ]
then
   . set_jobstatus_abort
fi

#------------------------------------------------------------------------------
# Remove all files local to this nesting level
#------------------------------------------------------------------------------
#
# macro workfiles:

rm -f *.${EBMSYS}.${JON}.${PROC_LEVEL}

# Instream files local to this procedure level:
rm -f LN_*.${JON}.${PROC_LEVEL}    
rm -f SYSIN.${JON}.${PROC_LEVEL}    
rm -f execproc_nullify_pgmprms.${EBMSYS}.${JON}.${PROC_LEVEL} 
rm -f ./${JON}_PROC_RETCOD_${PROC_LEVEL}
rm -f ./${JON}_PROC_RETCOD_${PROC_LEVEL}.back

cat <$DEVNULL  > current_proc_level.${EBMSYS}.${JON}
echo "PROC_LEVEL=`expr $PROC_LEVEL - 1` ; export PROC_LEVEL" >>current_proc_level.${EBMSYS}.${JON}

if [ "$VERBOSE" = "YES" ]
then  
   print_message ENDPROC "Exiting Procedure"
fi
exit 0
