COMPILE ROUTINE FIX_RDS_TEST(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE Send_Dyn,Send_Info, Send_Dyn,  Set_Status,  RList, ErrMsg, obj_RDS_Test
DECLARE FUNCTION Get_Status,  ErrMsg, obj_Prod_Spec


$INSERT RDS_TEST_EQUATES
$INSERT RDS_EQU
$INSERT PROD_SPEC_EQU
$INSERT PRS_LAYER_EQU


OPEN 'RDS_TEST' TO RDSTestFile ELSE
	debug
	GOTO Bail
END


OPEN 'TW_USE' TO TWUseFile ELSE
	ErrorMsg = 'Unable to open "TW_USE" table.(':Method:').'
	RETURN
END

SELECT RDSTestFile


DEBUG

Done = 0
RecCnt = 0
FixCnt = 0

LOOP
	READNEXT MetKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	
	READ MetRec FROM RDSTestFile,MetKey THEN
	
		IF MetRec<RDS_TEST_RDS_NO$> = '' OR MetRec<RDS_TEST_LS_ID$> = '' THEN
		
			TWUseKeys = MetRec<RDS_TEST_TW_USE_ID$>
			
			IF TWUseKeys NE '' THEN
				
				UseRecordsCleared = 1
				
				UseCnt = COUNT(TWUseKeys,@VM) + (TWUseKeys NE '')
				
				FOR N = 1 TO UseCnt
					TWUseKey = TWUseKeys<1,N>
					DELETE TWUseFile,TWUseKey THEN
						Send_Dyn(TWUseKey:' Cleared')
					END ELSE
						UseRecordsCleared = 0
					END
				NEXT N
				
				IF UseRecordsCleared = 1 THEN
					DELETE RDSTestFile,MetKey THEN
						Send_Dyn(MetKey:' Cleared')
					END
				END
			END
			
			DELETE RDSTestFile,MetKey THEN
				Send_Dyn(MetKey:' Cleared')
			END
		END	
	END
	Send_Info(RecCnt)

REPEAT

GOTO Bail



WONos  = 144654:@VM
WONos := 144653

debug

FOR I = 1 TO 2

	WONo = WONos<1,I>
	
	
	Set_Status(0)
	
	SelectSent = 'SELECT RDS_TEST WITH WO_NO ':QUOTE(WONo)
	
	

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

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
		DEBUG
		GOTO Bail
	END

	TotRecCnt = @RECCOUNT
	RecCnt = 0
	FixCnt = 0
	Done = 0
	DEBUG
	LOOP
		READNEXT MetNo ELSE Done = 1
	UNTIL Done
		Set_Status(0)
		obj_RDS_Test('RefreshSpecs',MetNo)
		IF Get_Status(errCode) THEN
			DEBUG
		END
	REPEAT

	
NEXT I
GOTO Bail





Send_Dyn(RecCnt:' - ':FixCnt)

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

END



