#!/bin/ksh
###############################################################################
#
# verify_jobstatus
#
###############################################################################
#
# Executes BEGINJOB if the macro has not been executed.                
#
###############################################################################
. beginjob.${EBMSYS}.${JON}
if [ ! -f "jobstatus.${EBMSYS}.${JON}" ]
then
   print_message "Warning:  BEGINJOB macro is not the first statement in jobstream"
   BEGINJOB
fi

calling_macro=`basename $0`;export calling_macro

case $BATCH_MODE in

   MVS)
      if [ -f bypassfile.${EBMSYS}.${JON} ]
      then
         case $calling_macro in
            
            ASSGNDD|EXECPGM|EXECPROC)
	       #
	       # for performance just exit if in restart or goto
	       # (bypassfile exists) and one of the above macros
	       # has been called.  we will never want to execute
	       # them in this scenario.
	       #
               #. check_bypass_step
               #if [ "$BYPASS" = "YES" ]
               #then
               #  exit 0
               #fi
	       exit 0
            ;;

            *)
               break
            ;;
         esac
      fi
   ;;

   VSE)
      if [ -f restart.vse.${EBMSYS}.${JON} ]
      then
         case $calling_macro in

	    LABEL)
	       # must always execute label to see if we have
	       # reached the target of a restart
	       break
            ;;

            DISPLAY|LOGMSG|EBMSYSCMD|EXECPGM|EXECPROC|GOTO|IF|PAUSE|THEN)
               exit 0
            ;;

	    *)
	    #
	    # all other macros should be executed in restart mode
	    # to allow for file and device assignments.  this is 
	    # because vse allows for those assignments to be carried
	    # forward to other steps (as opposed to mvs which requires
	    # a step's assignments to be made in that step).
	    #
	    break
	    ;;
         esac
      else
         if [ -f bypassfile.${EBMSYS}.${JON} ]
         then
             case $calling_macro in
         
                LABEL)
                   # must always execute label to see if we have
                   # reached the target of a restart
                   break
                ;;

                DISPLAY|LOGMSG|EBMSYSCMD|EXECPGM|EXECPROC|GOTO|IF|PAUSE|THEN)
                   # if in GOTO mode, the above will be bypassed
                   # from the start since we will not want to execute
                   # them anyway
		    exit 0
                ;;
         
                #
                # the following macros will all execute as normal
                # for the time being.  they are all identified to
                # ease maintenance if we decide to add some to the
                # group of those being bypassed above.
                #
		ASSGNDD|BEGINJOB|BEGINPROC|ENDJOB|ENDPROC|LASTRC|LIBDEF)
		   break
                ;;
          
                LIBDROP|LIBLIST|MAXRC|ONCONDCODE|ONRETCODE|SETDATE)
                   break
                ;;

                SETPARM|SETPGMSW|SETPRINT)
                   break
                ;;
                #
                # end of completed list of macros to be executed
                #

                *)
                   # any other calling_macro should be in error
                   print_message verify_jobstatus "INVALID CALLING MACRO"
                   set_jobstatus_abort
                   exit 0
                ;;
             esac

         fi  # if [ -f bypassfile.${EBMSYS}.${JON} ]

      fi  # if [ -f restart.vse.${EBMSYS}.${JON} ]
   ;;

esac
