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


########################################################################
#                                                                      #
# EBM BATCH JOB MACRO :     THEN                                       # 
# Purpose             :     Defines an action to be executed if the    #
#                           condition specified on the preceding IF    # 
#                           macro is true.                             #
#                                                                      #
########################################################################
. verify_jobstatus
. beginjob.${EBMSYS}.${JON}
. current_proc_level.${EBMSYS}.${JON}

if [ -f label.${EBMSYS}.${JON}.${PROC_LEVEL} ]
then
   . label.${EBMSYS}.${JON}.${PROC_LEVEL}
fi

if [ "a$BATCH_MODE" = "aMVS" ]
then
   if [ "a$STEPNAME" != a ]
   then
      . check_bypass_step

      if [ "$BYPASS" = "YES" ]
      then
          exit 0
      fi
   fi
fi

if [ -f beginproc.setparms.${EBMSYS}.${JON}.${PROC_LEVEL} ]
then
   . beginproc.setparms.${EBMSYS}.${JON}.${PROC_LEVEL}
fi

if [ -f setparm.${EBMSYS}.${JON}.${PROC_LEVEL} ]
then
   . setparm.${EBMSYS}.${JON}.${PROC_LEVEL}
fi

ACTION=$* ; export ACTION
if [ -f if.${EBMSYS}.${JON} ]
then
   grep "VERBOSE=YES" if.${EBMSYS}.${JON}  >$DEVNULL 2>&1
   if [ $? -eq 0 ]
   then 
      VERBOSE=YES;export VERBOSE
   fi

   if [ "$VERBOSE" = "YES" -o "a$VALIDATE" = "ay" ]
   then
      tmp="$*"; export tmp
      MSG=`echo $tmp | sed 's/verbose//g'`;export MSG
      MSG=`echo $MSG | sed 's/VERBOSE//g'`;export MSG
      print_message THEN "$MSG"
   fi

   if [ "a$ACTION" != "a" ]
   then
      STATE_THEN="ACTIVE"; export STATE_THEN
      if [ "a$VALIDATE" != "ay" ]
      then
         echo "then" >> if.${EBMSYS}.${JON}
         echo $ACTION >> if.${EBMSYS}.${JON}
         echo "fi" >> if.${EBMSYS}.${JON}
         . if.${EBMSYS}.${JON} 
      else
         print_message "IF/THEN" "in validation mode, no action taken"
      fi
   fi

   rm -f if.${EBMSYS}.${JON}
else
   print_message THEN "an IF condition is not defined"
   if [ "a$VALIDATE" != "ay" ]
   then
      . set_jobstatus_abort
   fi
fi       
STATE_THEN="INACTIVE"; export STATE_THEN
exit 0
