@Echo off
 REM #LUp: 09.02.2017
 REM #EXA: Create ERR and STOP       if "%Test%" neq "OK" call ErrorHandel "S" "#Key#:ERR #ShortMSG#" "ERR.description"
 REM #EXA: Create ERR and Pause-STOP if "%Test%" neq "OK" call ErrorHandel "PS" "#Key#:ERR #ShortMSG#" "ERR.description"
 REM #EXA: Create ERR and CONTINUE   if "%Test%" neq "OK" call ErrorHandel "C" "#Key#:ERR #ShortMSG#" "ERR.description"
 call ColorSet ERR
 set JobMgr_ProcERR_DPNE=%~dp0__ProcessERROR_log.txt
 Set JobMgr_ERRKey=%~2
 Set JobMgr_ERRDescr=%~3

 if not exist "%JobMgr_ProcERR_DPNE%" (
  CALL :ErrLogHeaderWrite
 ) else (
  CALL :GenericERR
 )
 REM run Evaluation and Stops process via EXIT
 if "%~1" equ "S"  Call :ResEvaluate_ERR_AND_STOP
 if "%~1" equ "PS" Call :ResEvaluate_ERR_AND_STOP "PAUSE"

REM  if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
REM   set toRunForPrint=%toRun:"='%
REM   call Echo "#Step...........................: after fccCheck"
REM   call Echo "---------------------------------------------------------------------------"
REM   pause
REM  :JumbOverDebug

goto :eof

REM ####### ------------ Standard Subroutines ---------------------- ###########
REM ============================================================================
:GenericERR
 setlocal
   set JobMgr_ERRKeyPrint=%JobMgr_ERRKey%.......................................
   set JobMgr_ERRKeyPrint=%JobMgr_ERRKeyPrint:~0,32%
   CALL Echo "%JobMgr_ERRKeyPrint%: %JobMgr_ERRDescr%" "%JobMgr_ProcERR_DPNE%"
 endlocal
goto :eof

REM ============================================================================
:ErrLogHeaderWrite
 REM writes ERR Header
 Call Echo "--------------------------------------------------------------------------" "%JobMgr_ProcERR_DPNE%"
 Call Echo "JobProcess ERROR Report created.: %date% %time%" "%JobMgr_ProcERR_DPNE%"
 Call Echo "Computer........................: %ComputerName%" "%JobMgr_ProcERR_DPNE%"
 Call Echo "User............................: %UserName%" "%JobMgr_ProcERR_DPNE%"
 Call Echo "ERR.Key.........................: %JobMgr_ERRKey%" "%JobMgr_ProcERR_DPNE%"
 Call Echo "ERR.Descr.......................: %JobMgr_ERRDescr%" "%JobMgr_ProcERR_DPNE%"
 goto :eof

REM ============================================================================
:ErrLogFooterWrite
 REM writes ERR Footer
 Call Echo "--------------------------------------------------------------------------" "%JobMgr_ProcERR_DPNE%" "NOECHO"
 Call Echo "Environ Info of:\\%ComputerName%"
 Call Echo "-- Path Environ ----------------------------------------------------------"  "%JobMgr_ProcERR_DPNE%" "NOECHO"
 set PATH>>"%JobMgr_ProcERR_DPNE%"
 Call Echo "-- NX*/UG* Environ -------------------------------------------------------"  "%JobMgr_ProcERR_DPNE%" "NOECHO"
 set NX>>"%JobMgr_ProcERR_DPNE%"
 set UG>>"%JobMgr_ProcERR_DPNE%"
 Call Echo "-- TC*/IMAN*/SPLM* Environ -----------------------------------------------" "%JobMgr_ProcERR_DPNE%" "NOECHO"
 set TC>>"%JobMgr_ProcERR_DPNE%"
 set IMAN>>"%JobMgr_ProcERR_DPNE%" 2>nul
 set SPLM>>"%JobMgr_ProcERR_DPNE%"
 Call Echo "-- All Environ -----------------------------------------------------------" "%JobMgr_ProcERR_DPNE%" "NOECHO"
 set >>"%JobMgr_ProcERR_DPNE%"
 goto :eof

REM ============================================================================
:ResEvaluate_ERR_AND_STOP
 rem Writes for all Objects ERR case in JobResults
 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "JobDataEdit_2012_09"
 set toRun=%toRun% -SubAction "JobData2ResultsSetProcessValue"
 set toRun=%toRun% -ObjProcessResultCode "JM-999101"
 set toRun=%toRun% -ObjProcessState  "D.NP.ERR"
 set toRun=%toRun% -ObjProcessResultMsg "[%JobMgr_ERRKey%]"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -JobData2ResultsDoPrint
 call %toRun%

 rem #New:18.07.2019/J.Fes deactivates JobComputer to aviod that JobComputer get new Jobs
 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "JobControl_2018_10"
 set toRun=%toRun% -SubAction "ControlActivStatus"
 set toRun=%toRun% -Type "JobComputer"
 set toRun=%toRun% -Name "%ComputerName%"
 set toRun=%toRun% -Status "OFF"
 set toRun=%toRun% -Description  "%JobMgr_ERRKey%"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 call %toRun%


 if /I "%~1" equ "PAUSE" (
  Echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Echo after press enter you will see the error reason in cmd window.......
  Echo ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ---  ----
  Type "%JobMgr_ProcERR_DPNE%"
  Echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  pause
 )

 call :ErrLogFooterWrite
 REM view result on  JC if uses Debug Mode
 if /i "%JobMgr_Debug%" neq "ON" goto :ResEvaluate_ERR_AND_STOP_end
 Echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Echo after press enter you will see the error reason in text-editor.......
 Echo Info: explorer start's with dir %temp%
 Echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 pause
 set Editor_DPNE=%BinPublic_DP%\PSPad editor\PSPad.exe
 if not exist "%Editor_DPNE%" set Editor_DPNE=Notepad.exe
 start "Text Editor" "%Editor_DPNE%" "%JobMgr_ProcERR_DPNE%"
 start "Explorer" Explorer "%temp%"
 Call Echo "Hint: type 'exit' then script and process exits"
 Echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 cmd

:ResEvaluate_ERR_AND_STOP_end
 Exit
goto :eof
