COMPILE ROUTINE LOAD_REACT_TUBE_HOURS(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE obj_Schedule,Send_Dyn,Send_Info, Send_Dyn, obj_WO_Step, Set_Status, RList, Send_Dyn
DECLARE FUNCTION Get_Status, Set_Printer, obj_RDS


$INSERT ORDER_DET_EQU
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT RDS_EQU
$INSERT REACT_TUBE_EQUATES
$INSERT REACTOR_LOG_EQU


OPEN 'REACT_TUBE' TO ReactTubeTable ELSE
	DEBUG
	GOTO Bail
END

OPEN 'RDS' TO RDSTable ELSE
	DEBUG
	GOTO Bail
END

OPEN 'REACTOR_LOG' TO ReactLogTable ELSE
	DEBUG
	GOTO Bail
END

CutoffDtm = ICONV('10/31/2005 16:30','DT')


SelectSent = 'SELECT REACTOR_LOG WITH REACT_SERV_ID "240" '

RList(SelectSent,5,'','','')

ReactList = ''

equ COL$REACT_NO			TO 1
EQU COL$START_DTM			TO 2
EQU COL$TUBE_ID				TO 3
EQU COL$START_REACT_HRS		TO 4
EQU COL$START_RL_ID			TO 5
EQU COL$END_DTM				TO 6
EQU COL$END_REACT_HRS		TO 7
EQU COL$END_RL_ID			TO 8

RecCnt = 0
Done = 0

LOOP
	READNEXT RLId ELSE Done = 1
UNTIL Done

	READ RLRec FROM ReactLogTable,RLId THEN
	
		RecCnt += 1
		
		ReactNo			= RLRec<REACTOR_LOG_REACTOR$>
		TubeID			= XLATE('REACTOR_LOG',RLId,'TUBE_ID','X')
		StartDt			= RLRec<REACTOR_LOG_START_DATE$>
		StartTm			= RLRec<REACTOR_LOG_START_TIME$>
		ReactHrsStart	= RLRec<REACTOR_LOG_REACT_HRS_START$>
		ReactHrsEnd		= RLRec<REACTOR_LOG_REACT_HRS_END$>
		ReactCycles		= RLRec<REACTOR_LOG_REACT_CYCLES_READ$>
		
		StartDTM 		= ICONV(OCONV(StartDt,'D4/'):' ':OCONV(StartTm,'MTS'),'DT')
		
		CONVERT @VM TO '' IN TubeID
		
		IF StartDTM NE '' AND TubeID NE '' THEN
		
			LOCATE ReactNO IN ReactList BY 'AR' USING @VM SETTING Pos ELSE
				ReactList = INSERT(ReactList,1,Pos,0,ReactNo)
				
			END
				
			READ RTRec FROM ReactTubeTable,ReactNo THEN
				NULL
			END ELSE
				RTRec = ''
				
			END
			LOCATE StartDTM IN RTRec<REACT_TUBE_INST_DTM$> BY 'DR' USING @VM SETTING IPos THEN
				Null
				
			END ELSE
				RTRec = INSERT(RTRec,REACT_TUBE_INST_DTM$,IPos,0,StartDTM)
				RTRec = INSERT(RTRec,REACT_TUBE_TUBE_ID$,IPos,0,TubeID)
				RTRec = INSERT(RTRec,REACT_TUBE_INST_RL_ID$,IPos,0,RLId)
				RTRec = INSERT(RTRec,REACT_TUBE_RDS_WAFER_CNT$,IPos,0,'')
				RTRec = INSERT(RTRec,REACT_TUBE_INST_REACT_HRS$,IPos,0,ReactHrsStart)
				RTRec = INSERT(RTRec,REACT_TUBE_INST_REACT_CYCLES$,IPos,0,0)
				
				RTRec = INSERT(RTRec,REACT_TUBE_REM_DTM$,IPos,0,'')
				RTRec = INSERT(RTRec,REACT_TUBE_REM_RL_ID$,IPos,0,'')
				RTRec = INSERT(RTRec,REACT_TUBE_REM_REACT_HRS$,IPos,0,'')
				RTRec = INSERT(RTRec,REACT_TUBE_REM_REACT_CYCLES$,IPos,0,'')
			END
			WRITE RTRec ON ReactTubeTable,ReactNo THEN
				Send_Info(RecCnt)
			END
				
		END
		
	END	;* End of RLRec read

REPEAT


ReactCnt = COUNT(ReactList,@VM) + (ReactList NE '')


FOR I = 1 TO ReactCnt
	ReactNo = ReactList<1,I>
	
	READ RTRec FROM ReactTubeTable,ReactNo THEN
	
		DTMCnt = COUNT(RTRec<REACT_TUBE_INST_DTM$>,@VM) + (RTRec<REACT_TUBE_INST_DTM$> NE '')
		
		FOR N = DTMCnt TO 2 STEP -1
			RTRec<REACT_TUBE_REM_DTM$,N>			= RTRec<REACT_TUBE_INST_DTM$,N-1>
			RTRec<REACT_TUBE_REM_RL_ID$,N>			= RTRec<REACT_TUBE_INST_RL_ID$,N-1>
			RTRec<REACT_TUBE_REM_REACT_HRS$,N>		= RTRec<REACT_TUBE_INST_REACT_HRS$,N-1>
			RTRec<REACT_TUBE_REM_REACT_CYCLES$,N>	= RTRec<REACT_TUBE_INST_REACT_CYCLES$,N-1>
		NEXT N
		
		WRITE RTRec ON ReactTubeTable,ReactNo THEN
				Send_Info(ReactNo)
			END
		
	END
NEXT I


SELECT ReactTubeTable
debug
Done = 0
LOOP
	READNEXT ReactNo ELSE DONE = 1
UNTIL Done
	READ TubeRec FROM ReactTubeTable,ReactNo THEN
		InstallDTMs = TubeRec<REACT_TUBE_INST_DTM$>
				
		LineCnt = COUNT(InstallDTMs,@VM) + (InstallDTMs NE '')
		
		FOR I = 1 TO LineCnt

			TubeRec<REACT_TUBE_RDS_WAFER_CNT$,I> = 0
			
		NEXT I
		WRITE TubeRec ON ReactTubeTable,ReactNo THEN
			Send_Info(ReactorNo)
		END

	END
REPEAT


SELECT RDSTable

Done = 0
RecCnt = 0
LOOP
	READNEXT RDSNo ELSE Done = 1
UNTIL Done 
	READ RDSRec FROM RDSTable,RDSNo THEN
		RecCnt += 1
		DateOut = RDSRec<RDS_DATE_OUT$>
		TimeOut = RDSRec<RDS_TIME_OUT$>
		RDSDtm = ICONV(OCONV(DateOut,'D4/'):' ':OCONV(TimeOut,'MTS'),'DT')
		
		
		
			ReactorNo = RDSRec<RDS_REACTOR$>
			
			READ TubeRec FROM ReactTubeTable,ReactorNo THEN
			
				InstallDTMs = TubeRec<REACT_TUBE_INST_DTM$>
				
				LineCnt = COUNT(InstallDTMs,@VM) + (InstallDTMs NE '')
				
				LOCATE RDSDtm IN InstallDTMs BY 'DR' USING @VM  SETTING Pos THEN
					Null
				END ELSE
					Null
				END
				
				
				WafersIn = RDSRec<RDS_WAFERS_IN$>
				TubeRec<REACT_TUBE_RDS_WAFER_CNT$,Pos> = TubeRec<REACT_TUBE_RDS_WAFER_CNT$,Pos> + WafersIn
				
				WRITE TubeRec ON ReactTubeTable,ReactorNo THEN
					Send_Info(RecCnt)
				END
			END	;* End of TubeRec Read
		
	
	END	;* End of RDSRec read

REPEAT



IF Get_Status(errCode) THEN DEBUG


* * * * * * *
Bail:
* * * * * * *

END
