COMPILE ROUTINE FIX_TOOL_WFR(Dummy)
ROWDEF (CHARSTR)

DECLARE SUBROUTINE SEND_INFO, SEND_DYN, RList,Btree.Extract, Set_Status, Get_Status


$INSERT TOOL_EQUATES
$INSERT TOOL_LOG_EQUATES
$INSERT TOOL_CLASS_EQUATES
$INSERT TOOL_WFR_EQUATES

debug

OPEN 'TOOL' TO ToolTable ELSE
	Send_Info('Puked on tool table open.')
	GOTO Bail
END

OPEN 'TOOL_LOG' TO LogTable ELSE
	Send_Info('Puked on TOOL_LOG table open.')
	GOTO Bail
END

OPEN 'TOOL_CLASS' TO ToolClassTable ELSE
	Send_Info('Puked on TOOL_LOG table open.')
	GOTO Bail
END


OPEN 'TOOL_WFR' TO ToolWfrTable ELSE
	Send_Info('Puked on TOOL_WFR table open.')
	GOTO Bail
END

SelectSent = 'SELECT TOOL_WFR '

RList(SelectSent,5)

DEBUG

Done = 0
LOOP
	READNEXT ToolID ELSE Done = 1
UNTIL Done

	ToolClass = XLATE('TOOL',ToolID,'CLASS','X')
	
	IF ToolClass[1,1] = 'G' THEN
	
		READ ToolWfrRec FROM ToolWfrTable,ToolID THEN
		
			WfrIDs = ToolWfrRec<1>
			
			wCnt = COUNT(WfrIDs,@VM) + (WfrIDs NE '')
			
			FOR I = 1 TO wCnt
				WfrID = WfrIDs<1,I>
				WfrRec = XLATE('WO_WFR',WfrID,'','X')
				
				IF WfrRec = '' THEN
					LOCATE WfrID IN ToolWfrRec<1> USING @VM SETTING Pos THEN
						ToolWfrRec = DELETE(ToolWfrRec,1,Pos,'')
					END
				END
			
			
			NEXT I
			

			*WRITE ToolWfrRec ON ToolWfrTable,ToolID THEN
				Send_Dyn(ToolID:' ':ToolWfrRec<1>)
			*END
		END
	END	;* 	
		
REPEAT



GOTO Bail


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

END
