COMPILE ROUTINE FIX_RUN_STAGE(Dummy)
ROWDEF(CHARSTR)


DECLARE SUBROUTINE Send_Dyn

$INSERT RUN_STAGE_EQUATES
$INSERT RUN_STAGE_WFR_EQUATES


OPEN 'RUN_STAGE' TO StageTable ELSE
	DEBUG
END


OPEN 'RUN_STAGE_WFR' TO StageWfrTable ELSE
	DEBUG
END

GOTO Bail ;**********************  R E M O V E   B E F O R E   F L I G H T   *************************


debug

SELECT StageWfrTable


DEBUG


Done = 0

LOOP
	READNEXT StageWfrKey ELSE Done = 1
UNTIL Done
	Stage = FIELD(StageWfrKey,'*',2)
	
	IF Stage = 'FRINGE' THEN
	
		READ StageWfrRec FROM StageWfrTable,StageWfrKey THEN
		
			WriteFlag = 0
			
			IF StageWfrRec<RUN_STAGE_WFR_SPEC_TOOL_CLASS$> NE 'G_FRINGE' THEN
				StageWfrRec<RUN_STAGE_WFR_SPEC_TOOL_CLASS$> = 'G_FRINGE'
				WriteFlag = 1
			END
			
			IF StageWfrRec<RUN_STAGE_WFR_SPEC_INV_ACTION$> = '' THEN
				StageWfrRec<RUN_STAGE_WFR_SPEC_INV_ACTION$> = 'START':@VM:'STOP'
				WriteFlag = 1
			END
			
			IF StageWfrRec<RUN_STAGE_WFR_TOOL_ID$> NE 'FRINGE01' THEN
				StageWfrRec<RUN_STAGE_WFR_TOOL_ID$> = 'FRINGE01'
				WriteFlag = 1
			END
				
			
			IF WriteFlag THEN
				WRITE StageWfrRec ON StageWfrTable,StageWfrKey THEN
					Send_Dyn(StageWfrKey:' / ':StageWfrRec)
				END
			END ELSE
				UNLOCK StageWfrRec,StageWfrKey ELSE NULL
			END
			
		END ;* End of record read
		
	END ;* End of check for FRINGE stages

REPEAT







GOTO Bail


 * * * * * * * * * * *

SELECT StageTable

Done = 0

DEBUG
LOOP
	READNEXT StageKey ELSE Done = 1
UNTIL Done
	READ StageRec FROM StageTable,StageKey THEN
	
		CompDTM = StageRec<RUN_STAGE_COMP_DTM$>
		
		IF INDEX(CompDTM,'/',1) THEN
			StageRec<RUN_STAGE_COMP_DTM$> = ICONV(CompDTM,'DT')
			
			WRITE StageRec ON StageTable,StageKey THEN
				Send_Dyn(StageKEy)
			END
		END
		
		
	END

REPEAT



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


END
