COMPILE FUNCTION Run_Stage_Wfr(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for Run_Stage window
	
	06/23/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status,obj_WO_Wfr, obj_WO_Wfr_Wip, Post_Event, obj_Run_Stage_Wfr
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, obj_AppWindow, Forward_Event
DECLARE SUBROUTINE End_Window,obj_React_Reads, obj_WO_Mat_Log, obj_WO_Mat, obj_Appwindow, obj_WO_Wfr

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals, obj_WO_Mat_QA, obj_Appwindow, obj_WO_Wfr, obj_React_Run
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_WO_Log, WO_Purge, Set_Property, Create_Dialog, obj_WO_Wfr_Wip, obj_Run_Stage_Wfr

Declare function    Logging_Services, Environment_Services
Declare subroutine  Logging_Services

$INSERT REACT_RUN_EQUATES
$INSERT RUN_STAGE_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT WO_MAT_WFR_EQUATES
$INSERT WO_WFR_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT LSL_USERS_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT TOOL_CLASS_EQUATES
$INSERT RTI_STYLE_EQUATES

$INSERT MSG_EQUATES
$INSERT APPCOLORS

EQU COL$IA_ACTION	TO 1
EQU COL$IA_COMP_BY	TO 2
EQU COL$IA_COMP_DTM TO 3


EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\

ErrTitle = 'Error in Run_Stage_Wfr commuter module'
ErrorMsg = ''
ErrCode  = ''

Result = ''

BEGIN CASE

	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'DELETE'			; GOSUB Delete
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'			; GOSUB Write
			
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
		
	CASE EntID = @WINDOW:'.SKIP_STAGE'		AND Event = 'CLICK'		; GOSUB SkipStage
	CASE EntID = @WINDOW:'.SIGN_COMP'		AND Event = 'CLICK'		; GOSUB SignComp
	CASE EntID = @WINDOW:'.LU_TOOL_ID'		AND Event = 'CLICK'		; GOSUB LUToolID
	CASE EntID = @WINDOW:'.INV_ACTION'		AND Event = 'OPTIONS'	; GOSUB PerformIA
	
	
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result



* * * * * * *
Create:
* * * * * * *

obj_Appwindow('Create',@WINDOW)

InvStyles = Send_Message(@WINDOW:'.INV_ACTION','COLSTYLE',0,'')

InvStyles<COL$IA_ACTION>	= BitOr(InvStyles<COL$IA_ACTION>,DTCS_OPTIONSBUTTON$)
*InvStyles<COL$IA_COMP_BY>	= BitOr(InvStyles<COL$IA_COMP_BY>,DTCS_OPTIONSBUTTON$)

void = Send_Message(@WINDOW:'.INV_ACTION','COLSTYLE',0,InvStyles)


GOSUB Refresh

RETURN


* * * * * * *
Read:
* * * * * * *


RDSNo	= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
ToolID	= Get_Property(@WINDOW:'.TOOL_ID','DEFPROP')
Stage	= Get_Property(@WINDOW:'.STAGE','DEFPROP')
WfrID	= Get_Property(@WINDOW:'.WFR_ID','DEFPROP')

* * *  Check for the Previous Stage completion  * * *

ReactRunRec = XLATE('REACT_RUN',RDSNo,'','X')

WfrStages = ReactRunRec<REACT_RUN_WFR_STAGE$>

LOCATE Stage IN WfrStages USING @VM SETTING Pos ELSE NULL

IF Pos > 1 THEN
	PrevStage = WfrStages<1,Pos - 1>
	PrevStageKey = RDSNo:'*':PrevStage:'*':WfrID
	
	PrevStageStatus = XLATE('RUN_STAGE_WFR',PrevStageKey,'CURR_STATUS','X')
	
	IF PrevStageStatus NE 'COMP' THEN
		Set_Property(@WINDOW:'.INV_ACTION_GROUP','ENABLED',0)
		Set_Property(@WINDOW:'.SIGN_COMP','ENABLED',0)
		Set_Property(@WINDOW:'.SKIP_STAGE','ENABLED',0)
	END ELSE
		Set_Property(@WINDOW:'.INV_ACTION_GROUP','ENABLED',1)
		Set_Property(@WINDOW:'.SIGN_COMP','ENABLED',1)
		Set_Property(@WINDOW:'.SKIP_STAGE','ENABLED',1)
	END
END	;* End of check for First Stage




******************

InvActArray = Get_Property(@WINDOW:'.INV_ACTION','DEFPROP')

TestArray = InvActArray<1>		;* Take first column (INV_ACTIONS)

CONVERT @VM TO '' IN TestArray

IF TestArray = '' THEN

	RDSNo = Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
	Stage = Get_Property(@WINDOW:'.STAGE','DEFPROP')

	IF RDSNo NE '' THEN

		PSNo		= XLATE('REACT_RUN',RDSNo,'PS_NO','X')
		PRSStageRec	= XLATE('PRS_STAGE',PSNo:'*':Stage,'','X')
		
		Set_Property(@WINDOW:'.SPEC_TOOL_CLASS','DEFPROP',PRSStageRec<PRS_STAGE_PROC_TOOL_CLASS$>)
		
		IF InvActArray<COL$IA_ACTION,1> = '' THEN
			InvActArray<COL$IA_ACTION> = PRSStageRec<PRS_STAGE_PROC_INV_ACTION$>
			Set_Property(@WINDOW:'.INV_ACTION','ARRAY',InvActArray)					;* Loads Inv Action Spec Items if null
		END
	
	END

END

GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

SkipUpdate = Get_Property(@WINDOW,'@SKIP_WRITE_UPDATE')		;* Set by the Create NCR and NCRKeysDC events so the window doesn't close!

IF SkipUpdate THEN
	Forward_Event()					;* Performs the Write
	Result = 0
	Set_Property(@WINDOW,'@SKIP_WRITE_UPDATE','')
	RETURN
END

Result = 0						;* Set Flag to stop window POSTEVENT chain 

Forward_Event()					;* Performs the Write

Post_Event(@WINDOW,'CLOSE')


RETURN


* * * * * * *
Clear:
* * * * * * *


GOTO Refresh

RETURN

* * * * * * *
Close:
* * * * * * *

obj_Appwindow('DetailReturn')

RETURN


* * * * * * *
Delete:
* * * * * * *

DEBUG

Result = 0	;* Stops the DELETE event chain 

RETURN


* * * * * * *
Refresh:
* * * * * * *

* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT Line
	
NEXT I



RETURN


* * * * * * *
SkipStage:
* * * * * * *

RecKey = Get_Property(@WINDOW,'ID')

RDSNo		= RecKey[1,'*']
CurrStage	= RecKey[COL2()+1,'*']
WfrID		= RecKey[COL2()+1,'*']

ToolClass 	= Get_Property(@WINDOW:'.SPEC_TOOL_CLASS','DEFPROP')
InvActions	= Get_Property(@WINDOW:'.INV_ACTION','DEFPROP')
CompSig		= Get_Property(@WINDOW:'.COMP_BY','DEFPROP')
CompDTM		= Get_Property(@WINDOW:'.COMP_DTM','DEFPROP')


LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\GaNWIP'
LogDate         = Oconv(Date(), 'D4/')
LogTime         = Oconv(Time(), 'MTS')
LogWfrID        = WfrID
Convert '*' to '_' in LogWfrID
LogFileName     = LogWfrID : '_' : LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '.csv'
Headers         = 'Logging DTM' : @FM : 'User' : @FM : 'Routine / Method' : @FM : 'Service Description'
ColumnWidths    = 20 : @FM : 10 : @FM : 60 : @FM : 300
objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
LoggingDTM      = LogDate : ' ' : LogTime   ; // Logging DTM

Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / SkipStage / Start Event' : @FM : 'ToolClass : ' : ToolClass : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : CurrStage, @RM, @FM)


IF InvActions<1,COL$IA_COMP_DTM> NE '' THEN
	
	Title	 = 'Material Loaded'
	Message  = 'Material Loaded - Stage may not be skipped'
	
	Msg(@WINDOW,TypeOver,'OK','',Title:@FM:Message)
	
	RETURN
END

CurrQueueID = XLATE('TOOL_CLASS',ToolClass,'QIN_LOC_ID','X')
*NextQueueID = XLATE('TOOL_CLASS',ToolClass,'QOUT_LOC_ID','X')

IF ToolClass NE '' THEN
	NextQueueID = obj_React_Run('StageUnloadQ',RDSNo:@RM:'':@RM:CurrStage)		;* Added 2/10/2017 jch & fdr New Method based on actual Run Wafer Stage Sequence
END ELSE
	NextQueueID = ''
END


IF CurrQueueID = '' THEN ErrorMsg = 'Missing Data "CurrQueueID" - contact MES support'

IF NextQueueID = '' THEN
	ErrorMsg  = 'Missing Data "NextQueueID" - contact MES support':CRLF$
	ErrorMsg := 'RDSNo: ':RDSNo:CRLF$
	ErrorMsg := 'CurrStage: ':CurrStage:CRLF$
	ErrorMsg := 'WfrID: ':WfrID
END
	
IF NextQueueID = '' THEN
	NextQueueID = XLATE('TOOL_CLASS',ToolClass,'QOUT_LOC_ID','X')		;* Temp JCH 2/7/2017  * * * * * * * * * * * * * 
END


IF ErrorMsg NE '' THEN RETURN

Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
Valid = Valid<1>

IF NOT(Valid) THEN
	RETURN 0
END

CONVERT '.' TO '*' IN WfrID

IF CompSig NE '' THEN
	EventBy = CompSig
	EventDTM = CompDTM	;******** Check conversion 
END ELSE
	EventBy		= @USER4
	EventDTM	=  OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
END


Parms  = WfrID	:@RM			;* mv
Parms := EventDtm:@RM
Parms := EventBy:@RM
Parms := 'SKIP':@RM				;* Event
Parms := '':@RM					;* mv NewSlotIDs
Parms := '':@RM					;* mv	RunLocs
Parms := '':@RM					;* NCRNo		
Parms := '':@RM					;*TWUse		
Parms := '':@RM					;* mv	CurrSlotIDs
Parms := '':@RM					;* NewToolID	
Parms := '':@RM					;* CurrToolID
Parms := NextQueueID:@RM		;* NewInvLoc	
Parms := CurrQueueID:@RM		;* CurrInvLoc
Parms := 'O':@RM				;* WfrSide	
Parms := '':@RM					;* NewCarrLocs			;* mv
Parms := '':@RM					;* CurrCarrLocs			;* mv
Parms := ''						;* Scribes				;* mv

Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / SkipStage / obj_WO_Wfr(TestAddEvent)' : @FM : 'CurrQueueID : ' : CurrQueueID : ', NextQueueID : ' : NextQueueID : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : CurrStage, @RM, @FM)
obj_WO_Wfr('TestAddEvent',Parms)

IF Get_Status(errCode) THEN
    Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / SkipStage / Error with obj_WO_Wfr(TestAddEvent)' : @FM : 'Error : ' : ErrCode : ', CurrQueueID : ' : CurrQueueID : ', NextQueueID : ' : NextQueueID : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : CurrStage, @RM, @FM)
	ErrMsg(ErrCode)
	RETURN
END

IF CompSig = '' THEN			
	Set_Property(@WINDOW:'.COMP_BY'  , 'DEFPROP' , EventBy)
	Set_Property(@WINDOW:'.COMP_DTM' , 'DEFPROP' , EventDTM)
END

Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / SkipStage / End Event' : @FM : 'ToolClass : ' : ToolClass : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : CurrStage, @RM, @FM)

Send_Event(@WINDOW,'CLEAR')
obj_Appwindow('LoadFormKeys',@WINDOW:@RM:RDSNo:'*':CurrStage:'*':WfrID)

RETURN





* * * * * * *
SignComp:
* * * * * * *

* PreChecks will go in this section with 
* error handlers

RDSNo 		= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
Stage 		= Get_Property(@WINDOW:'.STAGE','DEFPROP')
CharWfrID	= Get_Property(@WINDOW:'.CHAR_WFR_ID','DEFPROP')

IF RDSNo = '' THEN RETURN
IF Stage = '' THEN RETURN

/*
ReactRunRec = XLATE('REACT_RUN',RDSNo,'','X')

WONo	= ReactRunRec<REACT_RUN_WO_NO$>
WOStep	= ReactRunRec<REACT_RUN_WO_STEP$>
CassNo	= ReactRunRec<REACT_RUN_CASS_NO$>

WOMatKey = XLATE('REACT_RUN',RDSNo,'WO_MAT_KEY','X')
*/

Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
Valid = Valid<1>

IF NOT(Valid) THEN
	RETURN 0
END

SigDTM		= OCONV( Date(), 'D4/' ):' ':OCONV( Time(), 'MTS' )
		
Set_Property(@WINDOW:'.COMP_BY'  , 'DEFPROP' , @USER4)
Set_Property(@WINDOW:'.COMP_DTM' , 'DEFPROP' , SigDTM)
	

RETURN



* * * * * * *
LUToolID:
* * * * * * * 

ToolClass = Get_Property(@WINDOW:'.SPEC_TOOL_CLASS','DEFPROP')

IF ToolClass = '' THEN RETURN


ToolIDs = XLATE('TOOL_CLASS',ToolClass,TOOL_CLASS_TOOL$,'X')

TypeOver = ''
TypeOver<PMODE$>	= 'K'
TypeOver<PDISPLAY$>	= ToolIDs


IF INDEX(ToolIDs,@VM,1) THEN

	ToolID = Popup(@WINDOW,TypeOver,'TOOLS')

	IF Get_Status(errCode) THEN DEBUG

	IF ToolID = CHAR(27) OR ToolID = '' THEN RETURN
	
END ELSE

	ToolID = ToolIDs
	
END

obj_AppWindow('LUValReturn',ToolID:@RM:@WINDOW:'.TOOL_ID')

RETURN


* * * * * * *
PerformIA:
* * * * * * *

CtrlEntID = @WINDOW:'.INV_ACTION'


* Section added 9/21/2016 JCH & DKK to prevent blowing through the signature steps.


LastIATm = Get_Property(@WINDOW,'@LAST_IA_TM')

IF LastIATm NE '' THEN

	IF Time() < LastIATm + 10 THEN				;* IF Time is less than 10 seconds after the previous IA time, make them wait
		Msg(@WINDOW,'','IA_INTERVAL')
		RETURN
	END
	
END

RDSNo		= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
Stage		= Get_Property(@WINDOW:'.STAGE','DEFPROP')
RwsWfrID	= Get_Property(@WINDOW:'.WFR_ID','DEFPROP')
ToolID		= Get_Property(@WINDOW:'.TOOL_ID','DEFPROP')

IF RDSNo = '' THEN RETURN
IF Stage = '' THEN RETURN
IF RwsWfrID = '' THEN RETURN

IF ToolID = '' THEN
	ErrMsg('ToolID must be selected prior ton Inventory transactions.')
	RETURN
END



WfrID = RwsWfrID

CONVERT '.' TO '*' IN WfrID


LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\GaNWIP'
LogDate         = Oconv(Date(), 'D4/')
LogTime         = Oconv(Time(), 'MTS')
LogWfrID        = WfrID
Convert '*' to '_' in LogWfrID
LogFileName     = LogWfrID : '_' : LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '.csv'
Headers         = 'Logging DTM' : @FM : 'User' : @FM : 'Routine / Method' : @FM : 'Service Description'
ColumnWidths    = 20 : @FM : 10 : @FM : 60 : @FM : 300
objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
LoggingDTM      = LogDate : ' ' : LogTime   ; // Logging DTM

IAList = Get_Property(CtrlEntID,'LIST')

CurrPos = Get_Property(CtrlEntID,'SELPOS')

CurrRow = CurrPos<2>

CurrAction = IAList<CurrRow,COL$IA_ACTION,1>


Set_Property(@WINDOW,'@LAST_IA_TM', Time() )									;* Added 9/21/2016 JCH


ToolClass = Get_Property(@WINDOW:'.SPEC_TOOL_CLASS','DEFPROP')
		
ToolClassRec = XLATE('TOOL_CLASS',ToolClass,'','X')

QIn = ToolClassRec<TOOL_CLASS_QIN_WH$>:'*':ToolClassRec<TOOL_CLASS_QIN_LOC$>


Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / Start Event' : @FM : 'CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)

IF ToolClass NE '' THEN
	QOut = obj_React_Run('StageUnloadQ',RDSNo:@RM:'':@RM:Stage)					;* Added 2/10/2017 jch & fdr New Method based on actual Run Wafer Stage Sequence
END ELSE
	QOut = ''
END

Set_Property(@WINDOW,'@SKIP_WRITE_UPDATE',1)

Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / Send_Event(Write)' : @FM : 'CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)

Send_Event(@WINDOW,'WRITE')														;* 10/13/2016 JCH


BEGIN CASE
	
	
	CASE CurrAction = 'START'
	
		* Move Material from Current Queue to Tool
		
		CurrDTM =  OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
		
		CurrLocs = obj_WO_Wfr('CurrLoc',WfrID:@RM:'')	;* Added 9/27/2016 JCH
				
		CurrSlotID	= CurrLocs<1,2>						;* Added 9/27/2016 JCH
		CurrTool	= CurrLocs<1,3>						;* Added 9/27/2016 JCH
		CurrInvLoc	= CurrLocs<1,4>						;* Added 9/27/2016 JCH
		
		owwParms	 = WfrID:@RM			;* WfrID
		owwParms	:= CurrDTM:@RM			;* EventDtm
		owwParms	:= @USER4:@RM			;* EventBy
		owwParms	:= 'START':@RM			;* Event
		owwParms	:= '':@RM				;* New Slot ID
		owwParms	:= '':@RM				;* RPZ (RDSNo*Pocket*Zone)
		owwParms	:= '':@RM				;* NCRNo
		owwParms	:= '':@RM				;* TWUse ID 
		owwParms	:= '':@RM				;* Current Slot ID
		owwParms	:= ToolID:@RM			;* New ToolID
		owwParms	:= '':@RM				;* Curr Tool ID
		owwParms 	:= '':@RM				;* NewInvLoc
		owwParms	:= CurrInvLoc:@RM		;* CurrInvLoc
		owwParms 	:= 'O':@RM				;* Wfr Side
		owwParms	:= '':@RM				;* New Carrier SlotID
		owwParms	:= ''					;* CurrCarrier SlotID
		
		Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / obj_WO_Wfr(AddEvent/START)' : @FM : 'CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)
		obj_WO_Wfr('AddEvent',owwParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
			Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / Error with obj_WO_Wfr(AddEvent/START)' : @FM : 'Error : ' : ErrCode : ', CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)
			RETURN
		END
		obj_Run_Stage_Wfr('SetIASig',RDSNo:@RM:Stage:@RM:RwsWfrID:@RM:'START')
		
	CASE CurrAction = 'STOP'
	
		IF QOut = '' THEN
			ErrMsg('Unable to find UnloadQ for RDSNo: ':RDSNo:' Stage: ':Stage:' Wafer ID: ':WfrID)
			RETURN
		END
	
		* Move Material from tool to next Queue
		
		CurrDTM =  OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
		CurrLocs = obj_WO_Wfr('CurrLoc',WfrID:@RM:'')	;* Added 9/27/2016 JCH
		CurrSlotID	= CurrLocs<1,2>						;* Added 9/27/2016 JCH
		CurrTool	= CurrLocs<1,3>						;* Added 9/27/2016 JCH
		CurrInvLoc	= CurrLocs<1,4>						;* Added 9/27/2016 JCH
		
		owwParms	 = WfrID:@RM			;* WfrID
		owwParms	:= CurrDTM:@RM			;* EventDtm
		owwParms	:= @USER4:@RM			;* EventBy
		owwParms	:= 'STOP':@RM			;* Event
		owwParms	:= '':@RM				;* New Slot ID
		owwParms	:= '':@RM				;* RPZ (RDSNo*Pocket*Zone)
		owwParms	:= '':@RM				;* NCRNo
		owwParms	:= '':@RM				;* TWUse ID 
		owwParms	:= '':@RM				;* Current Slot ID
		owwParms	:= '':@RM				;* New ToolID
		owwParms	:= CurrTool:@RM			;* Curr Tool ID
		owwParms 	:= QOut:@RM				;* NewInvLoc
		owwParms	:= CurrInvLoc:@RM		;* CurrInvLoc
		owwParms 	:= 'O':@RM				;* Wfr Side
		owwParms	:= '':@RM				;* New Carrier SlotID
		owwParms	:= ''					;* CurrCarrier SlotID

        Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / obj_WO_Wfr(AddEvent/STOP)' : @FM : 'CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)
		obj_WO_Wfr('AddEvent',owwParms)
		
		IF Get_Status(errCode) THEN
		    Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / Error with obj_WO_Wfr(AddEvent/STOP)' : @FM : 'Error : ' : ErrCode : ', CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)
			ErrMsg(errCode)
			RETURN
		END
		obj_Run_Stage_Wfr('SetIASig',RDSNo:@RM:Stage:@RM:RwsWfrID:@RM:'STOP')
		
END CASE	

Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: 'RUN_STAGE_WFR / PerformIA / End Event' : @FM : 'CurrAction : ' : CurrAction : ', WfrID : ' : WfrID : ', RDSNo : ' : RDSNo : ', Stage : ' : Stage, @RM, @FM)
Logging_Services('AppendLog', objLog, LoggingDTM : @FM : @USER4 : @FM: '-------------------------------------' : @FM : '', @RM, @FM)

obj_Appwindow('LoadFormKeys',@WINDOW:@RM:RDSNo:'*':Stage:'*':RwsWfrID)

RETURN

