COMPILE FUNCTION obj_React_State(Method,Parms)

/*
	Methods for REACT_STATE (Reactor State) table
    
	10/9/2013 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    SetSpecParms(DataStruct)		;* Create new record
	
	
*/


DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, ErrMsg, Database_Services, Mona_Services

DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey, Send_Dyn, Database_Services, Error_Services
Declare function Environment_Services, GetTickCount

$INSERT REACT_STATE_EQUATES
$INSERT PROD_SPEC_EQUATES
$INSERT LOGICAL


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

IsProd = Environment_Services('IsProd')
If IsProd EQ True$ then
	MonaResource = 'GRP_OPENINSIGHT_MES_OP_FE_OBJREACTSTATE'
end else
	MonaResource = 'GRP_OPENINSIGHT_MES_OP_FE_DEV_OBJREACTSTATE'
end

ErrTitle = 'Error in Stored Procedure "obj_React_State"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'ReactRunUnload'			; GOSUB ReactRunUnload
	
	
	CASE 1
		

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


* * * * * * *
ReactRunUnload:
* * * * * * *

StartTick = GetTickCount()
MetricName = 'ReactRunUnload'

* Upadate all parameters set at Reactor Unload signature  *

ReactNo			= Parms[1,@RM]
PSNo			= Parms[COL2()+1,@RM]
RDSNo			= Parms[COL2()+1,@RM]
UnloadDTM		= Parms[COL2()+1,@RM]

IF ReactNo		= '' THEN ErrorMsg = 'Null Parameter "ReactNo" passed to routine. (':Method:')'
IF PSNo			= '' THEN ErrorMsg = 'Null Parameter "PSNo" passed to routine. (':Method:')'
IF RDSNo		= '' THEN ErrorMsg = 'Null Parameter "RDSNo" passed to routine. (':Method:')'
IF UnloadDTM	= '' THEN ErrorMsg = 'Null Parameter "UnloadDTM" passed to routine. (':Method:')'

thisUnloadDTM = ICONV(UnloadDTM,'DT')
IF thisUnloadDTM = '' THEN
	ErrorMsg = 'Invalid "UnloadDTM" value ':QUOTE(UnloadDTM):' passed to routine. (':Method:')'
END

IF ErrorMsg NE '' THEN RETURN

PSRec = XLATE('PROD_SPEC',PSNo,'','X')

IF PSRec = '' THEN
	ErrorMsg = 'Prod Spec record ':QUOTE(PSNo):' is empty! (':Method:')'
	RETURN
END
	

* otParms = 'REACT_STATE':@RM:ReactNo
* RSRec = obj_Tables('ReadRec',otParms)

RSRec = Database_Services('ReadDataRow', 'REACT_STATE', ReactNo)
	
* IF Get_Status(errCode) THEN RETURN

If Error_Services('NoError') then


    RSRec<REACT_STATE_RESTRICTOR$>			= PSRec<PROD_SPEC_WAND_RESTRICTER$>
    RSRec<REACT_STATE_RATIOS$>				= PSRec<PROD_SPEC_RATIOS$>
    RSRec<REACT_STATE_PINNED_SUSCEPTOR$>	= PSRec<PROD_SPEC_PINNED_SUSCEPTOR$>
    RSRec<REACT_STATE_TUBE_PRESSURE$>		= PSRec<PROD_SPEC_TUBE_PRESSURE_TYPE$>
    RSRec<REACT_STATE_DOPANT$>				= XLATE('PROD_SPEC',PSNo,'DOPANT_L1','X')

    RSRec<REACT_STATE_LAST_RDS_NO$>			= RDSNo
    RSRec<REACT_STATE_LAST_UNLOAD_DTM$>		= thisUnloadDTM

    Database_Services('WriteDataRow', 'REACT_STATE', ReactNo, RSRec, True$, False$, True$)
    
end

* otParms = FieldStore(otParms,@RM,4,0,RSRec)
* obj_Tables('WriteRec',otParms)

EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)

RETURN


