COMPILE ROUTINE FIX_WO_MAT(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE obj_Schedule,Send_Dyn,Send_Info, obj_WO_Log, Set_Status, obj_WO_Step, RList, obj_WO_Mat, Send_Info
DECLARE SUBROUTINE ErrMsg, RDS_React_Run, obj_Post_Log, obj_WO_Mat, obj_RDS2, Btree.Extract, obj_WM_IN, obj_WM_Out, Send_Dyn
DECLARE FUNCTION Get_Status, Set_Printer, obj_WO_Mat, WO_Mat_Purge, obj_Clean_Insp

$INSERT WO_MAT_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQUATES
$INSERT NCR_EQU
$INSERT RDS_EQUATES
$INSERT REACT_RUN_EQUATES
$INSERT RDS_TEST_EQUATES
$INSERT RDS_LAYER_EQUATES
$INSERT PROD_SPEC_EQUATES
$INSERT QUOTE_SPEC_EQU
$INSERT WM_OUT_EQUATES
$INSERT SURFACE_SCAN_EQUATES
$INSERT CLEAN_INSP_EQUATES
$INSERT ORDER_DET_EQU
$INSERT ORDER_EQU
$INSERT TOOL_EQUATES
$INSERT RLIST_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT PROD_VER_EQUATES

EQU CRLF$ TO \0D0A\


OPEN 'WO_MAT' TO WOMatTable ELSE
	DEBUG 
	GOTO Bail
END

OPEN 'WM_OUT' TO WMOutTable ELSE
	DEBUG 
	GOTO Bail
END


OPEN 'WO_LOG' TO WOLogTable ELSE
	DEBUG
	GOTO Bail
END


OPEN 'RDS' TO RDSTable ELSE
	DEBUG
	GOTO Bail
END

OPEN 'DICT.RDS' TO DictVar ELSE
	DEBUG
	GOTO Bail
END

OPEN 'NCR' TO NCRTable ELSE
	DEBUG
	GOTO Bail
END

OPEN 'CLEAN_INSP' TO CITable ELSE
	DEBUG
	GOTO Bail
End





RList('SELECT WO_MAT WITH PS_REACTOR_TYPE = "GAN" ',TARGET_ACTIVELIST$)	

DEBUG

Done = 0
RecNo = 0
LOOP
	READNEXT WOMKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMKey THEN
		RecNo += 1
		
		*IF WOMatRec<WO_MAT_SIG_PROFILE$> = '' THEN
			SigProfile = obj_WO_Mat('CassSigProfile',WOMKey)
			
			WOMatRec<WO_MAT_SIG_PROFILE$> 		= SigProfile
			WOMatRec<WO_MAT_WFR_SIG_PROFILE$>	= ''
			
			*Write WOMatRec On WOMatTable,WOMKey Then
				Send_Dyn (RecNo:' ':WOMKey:' ':WOMatRec<WO_MAT_SIG_PROFILE$>:' / ':WOMatRec<WO_MAT_WFR_SIG_PROFILE$>)
			*End
		*END	
		
		
	End	;* End of record read
	
Repeat

Goto Bail


* * * * * * * * * * * * * * * * * * * * * * * * * * * 

/*
RList('SELECT WO_MAT WITH WO_NO > 141548 AND WITH REACTOR_TYPE = "EPP" ',TARGET_ACTIVELIST$)		;* Change to desired WO_NO


Done = 0
RecNo = 0
RecCnt = @RECCOUNT
Pointer = 1
WMArray = ''
RDSArray = ''

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		RecNo += 1
		WONo	= WOMatKey[1,'*']
		CassNo	= WOMatKey[COL2()+1,'*']
		
		/*
		SlotNos = WOMatRec<WO_MAT_SLOT_NO$>
		
		IF SlotNos = '' THEN
		
			WaferQty = WOMatRec<WO_MAT_WAFER_QTY$>
			FOR I = 1 TO WaferQty
				SlotNos<1,I> = I
			NEXT
			
			WOMatRec<WO_MAT_SLOT_NO$> = SlotNos
				
			*WRITE WOMatRec ON WOMatTable,WOMatKey THEN
				Send_Info(RecNo:' - ':WOMatKey)
			*END
		END	;* End of check for null slotNo
		
		
		EPOSlotNos = WOMatRec<WO_MAT_EPO_SLOT$>
		
		IF EPOSlotNos = '' THEN
		
			EPOWfrQty = XLATE('WO_LOG',WONo,WO_LOG_OUT_CASS_LOAD_QTY$,'X')
			
			IF EPOWfrQty > 0 THEN
			
				FOR I = 1 TO EPOWfrQty
					EPOSlotNos<1,I> = I
				NEXT
				
				WOMatRec<WO_MAT_EPO_SLOT$> = EPOSlotNos
					
				WRITE WOMatRec ON WOMatTable,WOMatKey THEN
					Send_Info(RecNo:' - ':WOMatKey)
				END
			
		END
	END
		

	
REPEAT

*/
GOTO Bail




* * * * * * * Fix INV... fields with SR*VER location and 'PLACE' as Action   * * * * * * * * * * *


RList('SELECT WO_MAT WITH WO_NO > 161000',TARGET_ACTIVELIST$)		;* Change to desired WO_NO


DEBUG


Done = 0
RecNo = 0
RecCnt = @RECCOUNT
Pointer = 1
WMArray = ''
RDSArray = ''

EpiProPSNo = '4168'
EpiProPSRec = XLATE('PROD_SPEC',EpiProPSNo,'','X')

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		WONo	= WOMatKey[1,'*']
		CassNo	= WOMatKey[COL2()+1,'*']
		
		InvCnt = COUNT(WOMatRec<WO_MAT_INV_DTM$>,@VM) + (WOMatRec<WO_MAT_INV_DTM$> NE '')
		
		WriteFlag = 0
		
		FOR I = 1 TO InvCnt
			WH 		= WOMatRec<WO_MAT_INV_WH$,I>
			Loc		= WOMatRec<WO_MAT_INV_LOCATION$,I>
			Action	= WOMatRec<WO_MAT_INV_ACTION$,I>
			
			IF WH = 'SR' AND Loc = 'VER' AND Action = 'PLACE' THEN
				WriteFlag = 1
		
				WOMatRec<WO_MAT_INV_ACTION$,I> = 'PSVER'
			END
		NEXT I
		
		IF WriteFlag THEN
			RecNo += 1
			
			*WRITE WOMatRec ON WOMatTable,WOMatKey THEN
				Send_Dyn(WOMatKey:' ':RecNo:' of ':RecCnt)
			*END
		
		END	;* End of check for Write Flag
		
		
		
		
		
		
		
	END	;*End of read
REPEAT


GOTO Bail

*****************************************************************
* Fix missing Post Clean specifications on WO 158124 and 158125 *
*****************************************************************


RList('SELECT WO_MAT WITH WO_NO 160043 160044 BY WO_NO',TARGET_ACTIVELIST$)		;* Change to desired WO_NO


DEBUG

PostCINo = ''

Done = 0
Pointer = 1
WMArray = ''
RDSArray = ''

EpiProPSNo = '4168'
EpiProPSRec = XLATE('PROD_SPEC',EpiProPSNo,'','X')

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		WONo	= WOMatKey[1,'*']
		CassNo	= WOMatKey[COL2()+1,'*']
		
		IF WOMatRec<WO_MAT_EPO_CI_NO$> = '' THEN
		
			IF RowExists('PRS_STAGE',EpiProPSNo:'*POST') THEN
			
			
				ociParms  = WONo:@RM			;* WONo	
				ociParms := 1:@RM				;* WOStep
				ociParms := CassNo:@RM			;* CassNo
				ociParms := 'POST':@RM			;* Stage
				ociParms := '':@RM				;* RDSNo
				ociParms := EpiProPSNo:@RM		;* PSNo
				ociParms := EpiProPSRec			;* PSRec
				
				PostCINo = 'Test'
				*PostCINo = obj_Clean_Insp('Create',ociParms)
				
			
				WOMatRec<WO_MAT_EPO_CI_NO$> = PostCINo
				
				*WRITE WOMatRec ON WOMatTable,WOMatKey THEN
				
					Send_Dyn(WOMatKey:' ':PostCINo)
				*END
				
			END	;* End of Check for Post C&I spec
		END
		
	END ;* End of WOMatRecord read
	
REPEAT

GOTO Bail

***********************************************************************************

****************************************
* Fixes missing Cass No & Missing EPO_CI_NO problems
***************************************

DEBUG

RList('SELECT CLEAN_INSP WITH WO_NO 159958 BY CI_NO',TARGET_ACTIVELIST$)		;* Change to desired WO_NO

Done = 0
RecCnt = 1

LOOP
	READNEXT CINo ELSE Done = 1
UNTIL Done
	READ CIRec FROM CITable,CINo THEN
		IF CIRec<CLEAN_INSP_RDS_NO$> NE '' THEN
			
			CIRec<CLEAN_INSP_RDS_NO$> = ''
			
			*WRITE CIRec ON CITable,CINo THEN
				Send_Dyn('POST -> ':CINo)
			*END
		END ;* End of WOMatRec read
	
		
	END	;* End of CIRec read
REPEAT


GOTO Bail












**********************************************************************************************************************
* Trash records fixit

BadKeys  = '155039*45':@VM


bkCnt = COUNT( BadKeys , @VM ) + ( BadKeys NE '' )

Total = 0

FOR I = 1 TO bkCnt
	BadKey = BadKeys<1,I>
	READ BadRecord FROM WOMatTable,BadKey THEN


		
		Len1 = LEN(BadRecord)

		invCnt = COUNT(BadRecord<WO_MAT_INV_WH$>,@VM) + (BadRecord<WO_MAT_INV_WH$> NE '')
	
		
		BadRecord<WO_MAT_INV_DTM$> = FIELD(BadRecord<WO_MAT_INV_DTM$>,@VM,1,invCnt)
		BadRecord<WO_MAT_INV_USER$> = FIELD(BadRecord<WO_MAT_INV_USER$>,@VM,1,invCnt)
		
		Len2 = LEN(BadRecord)
		
		Delta = Len1 - Len2
		
		Total += Delta
		
		
		WRITE BadRecord ON WOMatTable,BadKey THEN

			Send_Dyn(BadKey:' ':Len1:' ':Len2:' ':OCONV(Total,'MD0,'))
		END


	END

NEXT I

GOTO Bail








******************************************************************************************************************



*************************
* Fix Cassette Ship Qty *
*************************

RList('SELECT WO_MAT WITH WO_NO  "157869"',TARGET_ACTIVELIST$)		;* Change to desired WO_NO

Done = 0
Pointer = 1
WMArray = ''
RDSArray = ''

DEBUG
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		WONo = WOMatKey[1,'*']
		CassNo = WOMatKey[COL2()+1,'*']

		*IF WONo < 128680 THEN RETURN			;* This is the first WO No on 7/29/2005 - The day we cut over to the new system.
		
		OrgShipQty = WOMatRec<WO_MAT_CASS_SHIP_QTY$>		;* Change dict item as desired - no multi-value fields.
		
		IF OrgShipQty NE 25 THEN
		
			WOMatRec<WO_MAT_CASS_SHIP_QTY$> = 25			;* New desired value
	
			*WRITE WOMatRec ON WOMatTable,WOMatKEy THEN			;* Remove the * to run 'hot' - add again and compile before closing procedure - adds protection.
				Send_Dyn(WOMatKey:' - ':OrgShipQty:' -> ':WOMatRec<WO_MAT_CASS_SHIP_QTY$>)
			*END												;* Remove the * to run 'hot' - add again and compile before closing procedure - adds protection.
		END
	END

REPEAT


GOTO Bail









RList('SELECT WO_MAT WITH CURR_LOCATION "1K*PTI" BY WO_NO BY CASS_NO',5)

Done = 0
RecCnt = 0

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done 
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		WMIKey = WOMatRec<WO_MAT_WMI_KEY$>
		WMOKey = WOMatRec<WO_MAT_WMO_KEY$>
		
		WMIStat = ''
		WMOStat = ''
		
		IF WMIKey NE '' THEN
			WMIStat = XLATE('WM_IN',WMIKey,'CURR_STATUS','X')
			Send_Dyn(WMIKey:'  In ':WMIStat)
		END
		
		IF WMOKey NE '' THEN
			WMOStat = XLATE('WM_OUT',WMOKey,'CURR_STATUS','X')
			Send_Dyn(WMOKey:' Out':WMOStat)
		END
		
		IF WMIStat = 'MT' THEN
			IF WMOStat = '' OR WMOStat = 'MT' OR WMOStat = 'VOID' OR WMOStat = 'RTB' THEN
				Send_Dyn('WOMat ':WOMatKey:' Set Location to CR*EPR')
				Send_Dyn(' ')
			END
		
		END
		
		
	END	;* End of WO_MAT record read
		

REPEAT

GOTO Bail

RList('SELECT WO_MAT WITH WO_NO > 153800 ',5)

Done = 0
RecCnt = 0

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done 
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
	
		SpecSigProfile = obj_WO_Mat('CassSigProfile',WOMatKey)
		SpecSignatures = ''
		SpecDTMs = ''
		SpecVers = ''
		
		SigProfile 	= WOMatRec<WO_MAT_SIG_PROFILE$>
		Signatures	= WOMatRec<WO_MAT_SIGNATURE$>
		SigDTMS		= WOMatRec<WO_MAT_SIG_DTM$>
		SigVers		= WOMatRec<WO_MAT_SIG_VER$>      
		
		SpecCnt = COUNT(SpecSigProfile,@VM) + (SpecSigProfile NE '')
		
		FOR I = 1 TO SpecCnt
			SpecProfItem = SpecSigProfile<1,I>
			
			* Look for new PItem in Existing Profile
			
			LOCATE SpecProfItem IN SigProfile USING @VM SETTING Pos THEN
				SpecSignatures<1,I> = Signatures<1,Pos>
				SpecDTMs<1,I>		= SigDTMs<1,Pos>
				SpecVers<1,I>		= SigVers<1,Pos>
				
				SigProfile	= DELETE(SigProfile,1,Pos,0)
				Signatures	= DELETE(Signatures,1,Pos,0)
				SigDTMs		= DELETE(SigDTMs,1,Pos,0)
				SigVers		= DELETE(SigVers,1,Pos,0)
				
			END ELSE
				* Check for FWI or LWI newer profile being stored as old 'WFR'
				IF SpecProfItem[2,3] = 'FWI' OR SpecProfItem[2,3] = 'LWI' THEN
				
					WfrString = SpecProfItem[2,3] 									;* LWI or FWI
					SWAP WfrString WITH 'WFR' IN SpecProfItem						;* Update WfrString
					
					
					LOCATE SpecProfItem IN SigProfile USING @VM SETTING Pos THEN
						SpecSignatures<1,I> = Signatures<1,Pos>
						SpecDTMs<1,I>		= SigDTMs<1,Pos>
						SpecVers<1,I>		= SigVers<1,Pos>
					END
				END ELSE
					* New item in Spec Sig -> won't be signed
				END
				
			END
		
		
		NEXT I
		
		WOMatRec<WO_MAT_SIG_PROFILE$>	= SpecSigProfile
		WOMatRec<WO_MAT_SIGNATURE$>		= SpecSignatures
		WOMatRec<WO_MAT_SIG_DTM$>		= SpecDTMs
		WOMatRec<WO_MAT_SIG_VER$>		= SpecVers
		
		*WRITE WOMatRec ON WOMatTable,WOMatKEy THEN
			Send_Dyn(RecCnt:' ':WOMatKey:' ':WOMatRec<WO_MAT_SIG_PROFILE$>:' ':SpecSignatures)
			Send_Dyn(SigProfile:' ':Signatures:' ':SigDTMs:' ':SigVers)
			Send_Dyn(' ')
		*END
		
	END
	
REPEAT

*Send_Dyn(RecCnt:' - ':WOMatKey)

GOTO Bail



* * * * * * *
DeleteRec:
* * * * * * *

Send_Info('Deleting ':TableName:' ':RecKey)

DELETE TableVar,RecKey THEN
	Log<-1> = TableName:' ':RecKey:' purged.'
	Gone = 1
END ELSE
	Log<-1> = '*** Unable to purge ':TableName:' ':RecKey:'   ***'
	Gone = 0
END

RETURN





GOTO Bail

* * * * * * *
FixPartNos:
* * * * * * *

WONos = 153204


DEBUG



LineCnt = COUNT(WONos,@VM) + (WONos NE '')

FOR I = 1 TO LineCnt
	WONo = WONos<1,I>

	READ WOLogRec FROM WOLogTable,WONO THEN
	
		CustPartNo = WOLogRec<WO_LOG_CUST_PART_NO$>
		
		
		WOMatKeys = WOLogRec<WO_LOG_WO_MAT_KEY$>
		
		CassCnt = COUNT(WOMatKeys,@VM) + (WOMatKeys NE '')
		
		FOR Box = 1 TO CassCnt
			WOMatKey = WOMatKeys<1,Box>
			
			READ WOMatRec FROM WOMatTable,WOMatKey THEN
				IF WOMatRec<WO_MAT_CUST_PART_NO$> NE CustPartNo THEN
					WOMatRec<WO_MAT_CUST_PART_NO$> = CustPartNo
		
					WRITE WOMatRec ON WOMatTable,WOMatKey THEN
						Send_Dyn(WOMatKey)
					END
				END
			END
			
		NEXT Box
		
		
		SearchString = 'WO':@VM:WONo:@FM
		Option = ''
		Flag = ''

		Btree.Extract(SearchString,'RDS',DictVar, RDSNos, Option, Flag)
		
		IF Get_Status(errCode) THEN
			DEBUG
			GOTO Bail
		END
		
		
		IF RDSNos NE '' THEN
		Send_Dyn(RdsNos)
			obj_RDS2('SetPartNo',RDSNos:@RM:CustPartNo)
		END
		
	END
NEXT I





GOTO Bail











RList('SELECT WO_MAT WITH WO_NO  "153138"',5)

Done = 0
Pointer = 1
WMArray = ''
RDSArray = ''



LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		
		LOCATE '1PSTS' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
			WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_PROFILE$,Pos,0)
			WOMatRec = DELETE(WOMatRec,WO_MAT_SIGNATURE$,Pos,0)
			WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_DTM$,Pos,0)
		END
			
		WRITE WOMatRec ON WOMatTable,WOMatKEy THEN
			Send_Dyn(WMOKey)
		END
		
	END

REPEAT


GOTO Bail









*GOTO FixPartNos

RList('SELECT WO_MAT WITH WO_NO "152912" ',5)

Done = 0
Pointer = 1
WMArray = ''
RDSArray = ''

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		WONo = WOMatKey[1,'*']
		CassNo = WOMatKey[COL2()+1,'*']

		IF WONo < 128680 THEN RETURN			;* This is the first WO No on 7/29/2005 - The day we cut over to the new system.

		WOStepKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')

		StepCnt = COUNT(WOStepKeys,@VM) + (WOStepKeys NE '')

		MetLine = 1

		FOR I = 1 TO StepCnt
			PSNo = XLATE('WO_STEP',WOStepKeys<1,I>,WO_STEP_PROD_SPEC_ID$,'X')
			PSRec = XLATE('PROD_SPEC',PSNo,'','X')
			
			MetCnt = COUNT(PSRec<PROD_SPEC_MET_TEST$>,@VM) + (PSRec<PROD_SPEC_MET_TEST$> NE '')
			
			FOR N = 1 TO MetCnt
			
				Interval	= PSRec<PROD_SPEC_MET_INTERVAL$,N>
				Start		= PSRec<PROD_SPEC_MET_START$,N>
				
				TestFlag = 0
				
				IF Interval NE '' AND Start NE '' THEN
					IF Interval = Start THEN
						IF REM(CassNo,Interval) = 0 THEN TestFlag = 1
					END ELSE
						IF ABS((Start + INT(CassNo/Interval)*Interval) - CassNo) = 0 THEN TestFlag = 1
					END
					IF TestFlag THEN
						WOMatRec<WO_MAT_MET_PROFILE$,MetLine>		= I:PSRec<PROD_SPEC_MET_TEST$,N>
						WOMatRec<WO_MAT_MET_RUN_STEP$,MetLine>		= PSRec<PROD_SPEC_MET_RUN_STEP$,N>
						WOMatRec<WO_MAT_MET_MIN$,MetLine>			= PSRec<PROD_SPEC_MET_MIN$,N>
						WOMatRec<WO_MAT_MET_MAX$,MetLine>			= PSRec<PROD_SPEC_MET_MAX$,N>
						WOMatRec<WO_MAT_MET_SLOT$,MetLine>			= PSRec<PROD_SPEC_MET_SLOT$,N>
						WOMatRec<WO_MAT_MET_SIG$,MetLine>			= ''
						WOMatRec<WO_MAT_MET_SIG_DTM$,MetLine>		= ''
						MetLine += 1
					END
				END
				
			NEXT N

		NEXT I
		
		IF MetLine > 1 THEN
			WRITE WOMatRec ON WOMatTable,WOMatKEy THEN

				Send_Dyn(WOMatKey)
			END
		END
	END

REPEAT
debug


GOTO Bail


OSREAD KeyList FROM 'C:\VOIDNOS.TXT' ELSE
	DEBUG
	RETURN
END

CONVERT CHAR(9) TO @FM IN KeyList
CONVERT ' ' TO '' IN KeyList
SWAP CRLF$ WITH '' IN Keylist

IF KeyList<-1> = @FM THEN KeyList<-1> = ''

KeyList 	= '132470*26'
KeyList<-1> = '132844*24'
KeyList<-1> = '133191*17'
KeyList<-1> = '133353*38'
KeyList<-1> = '133577*56'
KeyList<-1> = '133607*71'
KeyList<-1> = '141447*2'
KeyList<-1> = '141448*2'
KeyList<-1> = '142138*6'
KeyList<-1> = '145299*1'
KeyList<-1> = '147696*13'
KeyList<-1> = '147805*5'





KeyCnt = COUNT(KeyList,@FM) + (KeyList NE '')

DEBUG

FOR I = 1 TO KeyCnt
	Key = KeyList<I>
	IF NUM(Key) THEN
		RDSNo = Key
		RDSRec = XLATE('RDS',RDSNo,'','X')
		WONo = RDSRec<RDS_WO$>
		CassNo = RDSRec<RDS_CASS_NO$> 
	
		Key = WONo:'*':CassNo
	END ELSE
		RDSNo = ''
	END
	
	READ WOMatRec FROM WOMatTable,Key THEN
		WOMatRec<WO_MAT_VOID$> = '1'
		
		WRITE WOMatRec ON WOMatTable,Key THEN
			Send_Dyn(Key:'(':RDSNo:') Voided')
		END
	END
	
NEXT I






GOTO Bail

LotNos 		= '6A0AAA0631'
LotNos<2>	= '6A0AAA0631'
LotNos<3>	= '6A0AAA1298'
LotNos<4>	= '6A0AAA1298'
LotNos<5>	= '6A0AAA0631'
LotNos<6>	= '6A0AAA0631'
LotNos<7>	= '6A0AAA1298'
LotNos<8>	= '6A0AAA1298'
LotNos<9>	= '6A0A9A1277'
LotNos<10>	= '6A0A9A1277'
LotNos<11>	= '6A0A9A0902'
LotNos<12>	= '6A0AAA8F48'
LotNos<13>	= '6A0AAA0631'
LotNos<14>	= '6A0AAA1298'
LotNos<15>	= '6A0AAA0631'
LotNos<16>	= '6A0AAA1298'
LotNos<17>	= '6A0AAA0631'
LotNos<18>	= '6A0AAA0631'
LotNos<19>	= '6A0AAA1298'
LotNos<20>	= '6A0A9A0902'

DEBUG

FOR I = 1 TO 20
	LotNo = LotNos<I>
	WOMatKey = '150900*':I
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		RDSNo = WOMatRec<WO_MAT_RDS_NO$>
		READ RDSRec FROM RDSTable,RDSNo THEN
			RDSRec<RDS_LOT_NUM$> = LotNo
			WRITE RDSRec ON RDSTable,RDSNo THEN
				Send_Dyn('RDS ':RDSNo:' -> ':LotNo)
			END
		END
		WOMatRec<WO_MAT_LOT_NO$> = LotNo
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			Send_Dyn('WO_MAT ':WOMatKey:' -> ':LotNo)
		END
	END

NEXT I


GOTO Bail




RList('SELECT WO_MAT WITH WO_NO "150876" AND WITH CASS_NO > 84',5)

Done = 0
Pointer = 1
WMArray = ''
RDSArray = ''

DEBUG

LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		Set_Status(0)
		CONVERT '*' TO @RM IN WOMatKey
		obj_WO_Mat('Delete',WOMatKey)
		IF Get_Status(errCode) THEN
			DEBUG
		END
		Send_Dyn(WOMatKey)
	END

REPEAT

DEBUG

GOTO Bail


RList('SELECT WO_MAT WITH WO_NO "149993" BY WO_NO BY CASS_NO',5)


DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		RecDTM = WOMatRec<WO_MAT_RX_DTM$>
		NewRXDt = ICONV('3/30/2010','D')
		
		CONVERT '.' TO @VM IN RecDTM
		
		OrgRXDt = RecDTM<1,1>
		RecDTM<1,1> = NewRXDt
		
		CONVERT @VM TO '.' IN RecDTM
		
		WOMatRec<WO_MAT_RX_DTM$> = RecDTM
		
		*WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			Send_Dyn(WOMatKey:' ':OCONV(WOMatRec<WO_MAT_RX_DTM$>,'DT/^HS'):' -> ':OCONV(RecDTM,'DT/^HS'))
		*END
		
	END	;* End of record read
REPEAT


GOTO Bail





OrgLotNo = '6A0ABA1818'
NewLotNo = '6A0ACA0522'
WOMatKeys = '149690*19':@VM:'149690*20'

FOR I = 1 TO 2

	WOMatKey = WOMatKeys<1,I>
	
	WOMatRec = XLATE('WO_MAT',WOMatKey,'','X')

	IF WOMatRec<WO_MAT_LOT_NO$> = OrgLotNo THEN
		RDSNos = WOMatRec<WO_MAT_RDS_NO$>
		RDSCnt = COUNT(RDSNos,@VM) + (RDSNos NE '')
		FOR N = 1 TO RDSCnt
			oPLParms  = 'RDS':@RM
			oPLParms := RDSNos<1,N>:@RM
			oPLParms := RDS_LOT_NUM$:@RM
			oPLParms := NewLotNo
			
			obj_Post_Log('Create',oPLParms)
			
		
			
		NEXT N
		
		oPLParms  = 'WO_MAT':@RM
		oPLParms := WOMatKey:@RM
		oPLParms := WO_MAT_LOT_NO$:@RM
		oPLParms := NewLotNo
		
		obj_Post_Log('Create',oPLParms)
		
		
	END
NEXT I



GOTO Bail

WONo = 149655

FOR I = 13 TO 25
	WOMatKey = WONo:'*':I
	RDSNo = XLATE('WO_MAT',WOMatKey,WO_MAT_RDS_NO$,'X')
	
	RDSRec = ''
	RDSRec<RDS_WO$> = WONo
	RDSRec<RDS_CASS_NO$> = I
	
	WRITE RDSRec ON RDSTable,RDSNo THEN
		DELETE RDSTable,RDSNo THEN NULL
	END

NEXT I

FOR I = 13 to 25
	WOMatKey = WONo:'*':I
	DELETE WOMatTable,WOMatKey ELSE NULL
NEXT I


GOTO Bail

DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		LOCATE WOMatKey IN WOMatKeys USING @VM SETTING Pos ELSE
			DELETE WOMatTable,WOMatKey THEN
				Send_Dyn(WOMatKey:' Deleted')
				WRITE WOMatRec ON WOMatTable,WOMatKey THEN
					Send_Dyn(WOMatKey:' Written')
				END
			END
		END
		
	END	;* End of record read
REPEAT




GOTO Bail




RList('SELECT WO_MAT WITH WO_NO > 129000 BY-DSND WO_NO',5)

SelCnt = @RECCOUNT
DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		WONo = WOMatKey[1,'*']
		OrdNo = XLATE('WO_LOG',WONo,WO_LOG_ORDER_NO$,'X')
		OrdItem = WOMatRec<WO_MAT_ORDER_ITEM$>
		
		CustPN = XLATE('ORDER_DET',OrdNo:'*':OrdItem,ORDER_DET_CUST_PN$,'X')
			
		IF WOMatRec<WO_MAT_CUST_PART_NO$> NE CustPN THEN
			obj_WO_Mat('SetPartNo',WOMatKey:@RM:CustPN)
			Send_Dyn(WOMatKey:' Written')
			
		END
		
		
	END	;* End of record read
	Send_Info(RecCnt:'/':SelCnt)
REPEAT











GOTO Bail



RList('SELECT WO_MAT WITH WO_NO "148736" BY WO_NO BY CASS_NO',5)


DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		SigProfs 	= WOMatRec<WO_MAT_SIG_PROFILE$>
		Signatures	= WOMatRec<WO_MAT_SIGNATURE$>
		SigDTMs		= WOMatRec<WO_MAT_SIG_DTM$>
		
		aSigProf = SigProfs
		aSignature = Signatures
		aSigDTM = SigDTMs
		
		
		LOCATE '1PREI' IN SigProfs USING @VM SETTING Pos THEN
			IF Signatures<1,Pos> = '' THEN
				SigProfs	= DELETE(SigProfs,1,Pos,0)
				Signatures	= DELETE(Signatures,1,Pos,0)
				SigDTMs		= DELETE(SigDTMs,1,Pos,0)
			END
			
			Send_Dyn(WOMatKey:'  -  ':aSigProf:'  -  ':aSignature:'  -  ':aSigDTM)
			Send_Dyn(WOMatKey:'  -  ':SigProfs:'  -  ':Signatures:'  -  ':SigDTMS)
			Send_Dyn(' ')
				
		END
		
		WOMatRec<WO_MAT_SIG_PROFILE$>	= SigProfs
		WOMatRec<WO_MAT_SIGNATURE$>		= Signatures
		WOMatRec<WO_MAT_SIG_DTM$>		= SigDTMs
		
		
		
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			*Send_Dyn(WOMatKey:' ':aSigProf:' ':aSignature:' ':aSigDTM)
			*Send_Dyn(WOMatKey:' ':SigProfs:' ':Signatures:' ':SigDTMS)
			
		END
		
	END	;* End of record read
REPEAT




GOTO Bail	;***************************************************








WOMatKey = '148634*16' 
READ WOMatRec FROM WOMatTable,WOMatKey THEN
	DELETE WOMatTable,WOMatKey THEN
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
		END
	END
END





GOTO Bail



RList('SELECT WO_MAT WITH WO_NO "148362" ',5)


DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
	
		RecCnt += 1
		
		WONo = WOMatKey[1,'*']
		
		WOLogRec = XLATE('WO_LOG',WONo,'','X')
		
		OrderNo = WOLogRec<WO_LOG_ORDER_NO$>
		
		OrdItemNo = WOMatRec<WO_MAT_ORDER_ITEM$>
		
		SubPartNo = TRIM(XLATE('ORDER_DET',OrderNo:'*':OrdItemNo,ORDER_DET_SUB_PART_NO$,'X'))
		CurrSubPartNo = WOMatRec<WO_MAT_SUB_PART_NO$>
		
		IF SubPartNo NE CurrSubPartNo THEN
		
			WOMatRec<WO_MAT_SUB_PART_NO$> = SubPartNo
			
			Send_Dyn(RecCnt:' ':FixCnt:' ':WOMatKey:' ':QUOTE(CurrSubPartNo):' -> ':QUOTE(SubPartNo))
			
			RDSNos = WOMatRec<WO_MAT_RDS_NO$>
			
			RDSCnt = COUNT(RDSNos,@VM) + (RDSNos NE '')
			
			FOR I = 1 TO RDSCnt
			
				TableName = 'RDS'
				TableKey = RDSNos<1,I>
				FieldNo	= RDS_SUB_PART_NO$
				FieldData = SubPartNo
					
				*obj_Post_Log('Create',TableName:@RM:TableKey:@RM:FieldNo:@RM:FieldData)
				Send_Dyn(TableName:' ':TableKey:' ':FieldNo:' ':FieldData)
			
			NEXT I
			
			FixCnt += 1
			
			*WRITE WOMatRec ON WOMatTable,WOMatKey THEN
				Null
			*END
			
		END
		
		
		
	END	;* End of record read
REPEAT




GOTO Bail	;***************************************************



RList('SELECT WO_MAT WITH WO_NO "144637"',5)

DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		LOCATE '1PREI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
			IF WOMatRec<WO_MAT_SIGNATURE$,Pos> = '' THEN
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIGNATURE$,Pos,0)
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_PROFILE$,Pos,0)
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_DTM$,Pos,0)
				
				WRITE WOMatRec ON WOMatTable,WOMatKey THEN
					Send_Info(WOMatKey)
				END
			END	;* End of check for no PREI signature
		END	;* End of check FOR PREI
	END	;* End of record read
REPEAT


GOTO Bail


*********************************************


RList('SELECT WO_MAT WITH WO_NO  "144656"',5)


DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		WOMatRec<WO_MAT_CASS_SHIP_QTY$> = 24
		
				
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			Send_Dyn(WOMatKey)
		END
		
	END	;* End of record read
REPEAT




GOTO Bail	;***************************************************





WONo = '144556'

RList('SELECT WO_MAT WITH WO_NO  ':QUOTE(WONo),'1',5)

PSNo = XLATE('WO_STEP',WONo:'*1',1,'X')

RawSigProfile = XLATE('PROD_SPEC',PSNo,'SIG_PROFILE','X')

RSCnt = COUNT(RawSigProfile,@VM) + (RawSigProfile NE '')

SigProfile = ''
FOR I = 1 TO RSCnt
	SigProfile<1,I> = '1':RawSigProfile<1,I>
NEXT I

DEBUG



Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		RDSNo = WOMatRec<WO_MAT_RDS_NO$>
		
		RDSRec = XLATE('RDS',RDSNo,'','X')
		
		
		VerSig		= RDSRec<RDS_PRE_EPI_SIG$>
		LoadSig		= RDSRec<RDS_OPERATOR_IN$>
		FWSig		= RDSRec<RDS_FIRST_WAF_SIG$>
		UnLoadSig	= RDSRec<RDS_OPERATOR_OUT$>
		PstCleanSig	= RDSRec<RDS_POST_EPI_SIG$>
		QASig		= RDSRec<RDS_SUP_VER_SIG$>
		
		VerSigDTM		= ICONV(OCONV(RDSRec<RDS_PRE_EPI_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_PRE_EPI_SIG_TIME$>,'MTS'),'DT')
		LoadSigDTM		= ICONV(OCONV(RDSRec<RDS_DATE_IN$>,'D4/'):' ':OCONV(RDSRec<RDS_TIME_IN$>,'MTS'),'DT')
		FWSigDTM		= ICONV(OCONV(RDSRec<RDS_FIRST_WAF_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_FIRST_WAF_SIG_TIME$>,'MTS'),'DT')
		UnLoadSigDTM	= ICONV(OCONV(RDSRec<RDS_DATE_OUT$>,'D4/'):' ':OCONV(RDSRec<RDS_TIME_OUT$>,'MTS'),'DT')
		PstCleanSigDTM	= ICONV(OCONV(RDSRec<RDS_POST_EPI_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_POST_EPI_SIG_TIME$>,'MTS'),'DT')
		QASigDTM		= ICONV(OCONV(RDSRec<RDS_SUP_VER_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_SUP_VER_SIG_TIME$>,'MTS'),'DT')
		
		WOMatRec<WO_MAT_SIG_PROFILE$> = SigProfile
		WOMatRec<WO_MAT_SIGNATURE$> = ''
		WOMatRec<WO_MAT_SIG_DTM$> = ''
		
	
		
		IF VerSig NE '' THEN
			LOCATE '1VER' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = VerSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= VerSigDTM
			END
			
			LOCATE '1PREC' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = VerSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= VerSigDTM
			END
			
			LOCATE '1PREI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = VerSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= VerSigDTM
			END
			
			LOCATE '1PRES' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = VerSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= VerSigDTM
			END
			
		END
		
		IF LoadSig NE '' THEN
			LOCATE '1LOAD' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = LoadSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= LoadSigDTM
			END
		END
		
		IF FWSig NE '' THEN
			LOCATE '1WFRI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = FWSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= FWSigDTM
			END
		END
		
		IF UnLoadSig NE '' THEN
			LOCATE '1UNLOAD' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = UnLoadSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= UnLoadSigDTM
			END
		END
		
		IF PstCleanSigDTM NE '' THEN
			LOCATE '1PSTC' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = PstCleanSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PstCleanSigDTM
			END
			
			LOCATE '1PSTI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = PstCleanSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PstCleanSigDTM
			END
			
			LOCATE '1PSTS' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = PstCleanSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PstCleanSigDTM
			END
		
		END
		
		IF QASig NE '' THEN
			LOCATE '1QA' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = QASig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= QASigDTM
			END
		END
		
				
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			Send_Dyn(WOMatKey)
		END
		
	END	;* End of record read
REPEAT





GOTO Bail	;**********************************************







*/

DEBUG

READ WOMatRec FROM WOMatTable,'144556*11' THEN
	RDSNo = WOMatRec<WO_MAT_RDS_NO$>
	RDSRec = XLATE('REACT_RUN',RDSNo,'','X')
	
	PostCIKey = RDSRec<REACT_RUN_POST_CI_NO$>
	PostCIRec = XLATE('POST_CLEAN',PostCIKey,'','X')
	
	PostCleanSig = PostCIRec<CLEAN_INSP_CLEAN_SIG$>
	PostCleanSigDTM = PostCIRec<CLEAN_INSP_CLEAN_SIG_DTM$>
	
	LOCATE '1PSTC' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
		WOMatRec<WO_MAT_SIGNATURE$,Pos> = 'ROXANNE_S'
		WOMatRec<WO_MAT_SIG_DTM$,Pos> = ICONV('12/15/09 10:49AM','DT')
	END
	
	LOCATE '1PSTI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
		WOMatRec<WO_MAT_SIGNATURE$,Pos> = 'ROXANNE_S'
		WOMatRec<WO_MAT_SIG_DTM$,Pos> = ICONV('12/15/09 11:25AM','DT')
	END
	
	LOCATE '1PSTS' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
		WOMatRec<WO_MAT_SIGNATURE$,Pos> = 'ROXANNE_S'
		WOMatRec<WO_MAT_SIG_DTM$,Pos> = ICONV('12/15/09 11:25AM','DT')
	END
	
	LOCATE '1QA' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
		WOMatRec<WO_MAT_SIGNATURE$,Pos> = 'DICHAN_S'
		WOMatRec<WO_MAT_SIG_DTM$,Pos> = ICONV('12/15/09 11:27AM','DT')
	END
	
	WRITE WOMatRec ON WOMatTable,'144556*16' THEN NULL
	
END
GOTO Bail
*************************















DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		LOCATE '1PREI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
			IF WOMatRec<WO_MAT_SIGNATURE$,Pos> = '' THEN
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIGNATURE$,Pos,0)
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_PROFILE$,Pos,0)
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_DTM$,Pos,0)
				
				WRITE WOMatRec ON WOMatTable,WOMatKey THEN
					Send_Info(WOMatKey)
				END
			END	;* End of check for no PREI signature
		END	;* End of check FOR PREI
	END	;* End of record read
REPEAT


GOTO Bail





RList('SELECT WO_MAT WITH WO_NO  "143484" ',5)


RDSKeys = ''
DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		GoodRec = XLATE('ORG_WO_MAT',WOMatKey,'','X')
		
		WOMatRec<WO_MAT_REL_DTM$>			= GoodRec<WO_MAT_REL_DTM$>
		WOMatRec<WO_MAT_REL_BY$>			= GoodRec<WO_MAT_REL_BY$>
		WOMatRec<WO_MAT_ORG_COMMIT_DT$>		= GoodRec<WO_MAT_ORG_COMMIT_DT$>
		
		RDSKeys<1,-1> = GoodRec<WO_MAT_RDS_NO$>
		
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			Send_Dyn(WOMatKey:' - ':GoodRec<WO_MAT_RDS_NO$>)
		END
	

	END	;* End of record read
REPEAT


RDSCnt = COUNT(RDSKeys,@VM) + (RDSKeys NE '')
DEBUG
FOR I = 1 TO RDSCnt
	RDSKey = RDSKeys<1,I>
	GoodRDS = XLATE('ORG_RDS',RDSKey,'','X')
	
	LSKeys = GoodRDS<RDS_RDS_LAYER_KEYS$>
	
	LSCnt = COUNT(LSKeys,@VM) + (LSKeys NE '')
	
	FOR J = 1 TO LSCnt
		LSKey = LSKeys<1,J>
		GoodLayer = XLATE('ORG_RDS_LAYER',LSKey,'','X')
		
		MetKeys = GoodLayer<RDS_LAYER_RDS_TEST_KEYS$>
		
		MetCnt = COUNT(MetKeys,@VM) + (MetKeys NE '')
		
		FOR K = 1 TO MetCnt
			MetKey = MetKeys<1,K>
			GoodMet = XLATE('ORG_RDS_TEST',MetKey,'','X')
			
			WRITE GoodMet ON RDSTestTable,MetKey THEN
				Send_Dyn(MetKey)
			END
		NEXT K
		
		WRITE GoodLayer ON RDSLayerTable,LSKey THEN
			Send_Dyn(LSKey)
		END

	NEXT J
	
	WRITE GoodRDS ON RDSTable,RDSKey THEN
		Send_Dyn('RDS ':RDSKey)
	End

NEXT I

	
	

GOTO Bail	;	****************


RList('SELECT WO_MAT WITH WO_NO  "143566" ',5)

DEBUG
Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
		
		LOCATE '1PREI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
			IF WOMatRec<WO_MAT_SIGNATURE$,Pos> = '' THEN
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIGNATURE$,Pos,0)
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_PROFILE$,Pos,0)
				WOMatRec = DELETE(WOMatRec,WO_MAT_SIG_DTM$,Pos,0)
				
				WRITE WOMatRec ON WOMatTable,WOMatKey THEN
					Send_Info(WOMatKey)
				END
			END	;* End of check for no PREI signature
		END	;* End of check FOR PREI
	END	;* End of record read
REPEAT


GOTO Bail
/*

*RList('SELECT WO_MAT WITH WO_NO > 128680 ',5)


Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done OR Fix_Cnt > 100
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN

		WMOutKey = WOMatRec<WO_MAT_WMO_KEY$>
		
		IF WMOutKey NE '' THEN
		
			WMOutRec = XLATE('WM_OUT',WMOutKey,'','X')
		
			WONo		= WMOutKey[1,'*']
			WOStepNo	= WMOutKey[COL2()+1,'*']
			CassNo		= WMOutKey[COL2()+1,'*']

			WOStepKey = FIELD(WMOutKey,'*',1,2)
			PSNo = XLATE('WO_STEP',WOStepKey,1,'X')

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

			SpecSubPostClean 				= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostClean$>
			SpecPostCleanSurfscan			= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN$>
			SpecPostCleanBrightlight		= PSRec<PROD_SPEC_POST_CLEAN_BRIGHTLIGHT$>
			SpecPostCleanSurfscanRecipe		= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN_RECIPE$>

			IF SpecSubPostClean NE '' THEN
				IF WMOutRec<WM_OUT_POST_CODE$> NE '' OR WMOutRec<WM_OUT_POST_BOAT_ID$> OR WMOutRec<WM_OUT_POST_SRD_NO$> NE '' THEN
				
					LOCATE WOStepNo:'MO_PSTC' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
						WOMatRec<WO_MAT_SIGNATURE$,Pos> = WMOutRec<WM_OUT_POST_EPI_SIG$>
						WOMatRec<WO_MAT_SIG_DTM$,Pos>	= WMOutRec<WM_OUT_POST_EPI_SIG_DTM$>	
					END
				END
			END

			IF SpecPostCleanSurfscan = 1 THEN
			
				SurfScanKey = WMOutKey:'*PC'
				SurfScanRec = XLATE('SURFACE_SCAN',SurfScanKey,'','X')
				
				ScanSig		= SurfScanRec<SURFACE_SCAN_SCAN_USER$>
				ScanSigDTM	= SurfScanRec<SURFACE_SCAN_SCAN_DTM$>
				
				IF ScanSig NE '' THEN
					LOCATE WOStepNo:'MO_PSTS' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
						WOMatRec<WO_MAT_SIGNATURE$,Pos> = ScanSig
						WOMatRec<WO_MAT_SIG_DTM$,Pos>	= ScanSigDTM
					END
				END
			END
							
			IF SpecPostCleanBrightlight = 1 THEN
				IF WMOutRec<WM_OUT_LPD_POSTCLEAN$> NE '' AND WMOutRec<WM_OUT_LPD_POSTCLEAN$> NE '' THEN
					LOCATE WOStepNo:'MO_PSTI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
						WOMatRec<WO_MAT_SIGNATURE$,Pos> = WMOutRec<WM_OUT_SUP_VER_SIG$>
						WOMatRec<WO_MAT_SIG_DTM$,Pos>	= WMOutRec<WM_OUT_SUP_VER_SIG_DTM$>	
					END
				END
			END
			
			IF WMOutRec<WM_OUT_SUP_VER_SIG$> NE '' THEN
				LOCATE WOStepNo:'MO_QA' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = WMOutRec<WM_OUT_SUP_VER_SIG$>
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= WMOutRec<WM_OUT_SUP_VER_SIG_DTM$>	
				END
			END
			
			
			WRITE WOMatRec ON WOMatTable,WOMatKey THEN
				FixCnt += 1
				Send_Dyn(WOMatKey)
			END
		
		END	;* End of check for WMOKey
	END	;* End of WOMatRec read
	
	Send_Info(RecCnt:' ':FixCnt)
	
REPEAT



GOTO Bail

*/


* 128680   
DEBUG

RList('SELECT WO_MAT WITH WO_NO "143386" ',5)

Done = 0
RecCnt = 0
FixCnt = 0
LOOP
	READNEXT WOMatKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	
	READ WOMatRec FROM WOMatTable,WOMatKey THEN
	
		SigProfile = WOMatRec<WO_MAT_SIG_PROFILE$>
		Signatures = WOMatRec<WO_MAT_SIGNATURE$>
		
		TestString = Signatures
		CONVERT @VM TO '' IN TestString
		IF TestString = '' THEN GOTO SkipRecord
				
		Update = 0
		
		ProfCnt = COUNT(SigProfile,@VM) + (SigProfile NE '')
		FOR N = 1 TO ProfCnt
			IF Signatures<1,N> = '' THEN Update = 1
		UNTIL Update
		NEXT N
		
		*IF NOT(Update) THEN GOTO SkipRecord
		
		
		WOMatRec<WO_MAT_SIGNATURE$> = ''
		WOMatRec<WO_MAT_SIG_DTM$> = ''
		
		RDSNos = WOMatRec<WO_MAT_RDS_NO$>
		
		RdsCnt = COUNT(RDSNos,@VM) + (RDSNos NE '')
		FOR I = 1 TO RdsCnt
			RDSNo = RDSNos<1,I>
			RDSRec = XLATE('RDS',RDSNo,'','X')
			
			WOStepKey = RDSRec<RDS_WO_STEP_KEY$>
			WOStepNo = WOStepKey[-1,'B*']
			
			IF WOStepNo NE I THEN 
				Send_Dyn('WOStep NE "I" in ':QUOTE(WOStepKey))
				GOTO SkipRecord
			END
				
			PSNo = XLATE('WO_STEP',WOStepKey,WO_STEP_PROD_SPEC_ID$,'X')
			
			PSRec = XLATE('PROD_SPEC',PSNo,'','X')
			
			ReactorType = PSRec<PROD_SPEC_REACTOR_TYPE$>
			
			* * Verify
			
			PreEpiSig		= RDSRec<RDS_PRE_EPI_SIG$,1>
			PreEpiSigDTM	= ICONV(OCONV(RDSRec<RDS_PRE_EPI_SIG_DATE$,1>,'D4/'):' ':OCONV(RDSRec<RDS_PRE_EPI_SIG_TIME$,1>,'MTS'),'DT')
			
			
			IF PreEpiSig NE '' THEN
				LOCATE WOStepNo:'VER' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PreEpiSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PreEpiSigDTM
						
				END
			END
			
			* * Pre C & I
			
		
			PreClean = PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreClean$>
			IF PreClean[1,5] = 'If Ne' THEN PreCleanFlag = 1 ELSE PreCleanFlag = ''
			
			PreCodes = RDSRec<RDS_PRE_CODE$>
			PreBoats = RDSRec<RDS_PRE_BOAT_ID$>
			PreSRDs	 = RDSRec<RDS_PRE_SRD_NUM$>
			
			CONVERT @VM TO '' IN PreCodes
			CONVERT @VM TO '' IN PreBoats
			CONVERT @VM TO '' IN PreSRDs
			
			IF PreCodes NE '' OR PreBoats NE '' OR PreSRDs NE '' OR PreClean[1,5] = 'If Ne' THEN
				PreCleanFlag = 1
				LOCATE WOStepNo:'PREC' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PreEpiSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PreEpiSigDTM
				END
				
			END
			
			
			
			IF PSRec<PROD_SPEC_PRE_BRIGHTLIGHT$> = 1 OR PSRec<PROD_SPEC_PRE_MICROSCOPE$> = 1 THEN
				
				LOCATE WOStepNo:'PREI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PreEpiSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PreEpiSigDTM
				END
			END
				
			IF PSRec<PROD_SPEC_PRE_SURFSCAN$> = 1 OR PSRec<PROD_SPEC_PRE_SURFSCAN_RECIPE$> NE '' THEN
				
				LOCATE WOStepNo:'PRES' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PreEpiSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PreEpiSigDTM
				END
			END
			
			
			* * Load
			
			LoadSig			= RDSRec<RDS_OPERATOR_IN$>
			LoadSigDTM		= ICONV(OCONV(RDSRec<RDS_DATE_IN$>,'D4/'):' ':OCONV(RDSRec<RDS_TIME_IN$>,'MTS'),'DT')
			
			LOCATE WOStepNo:'LOAD' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = LoadSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= LoadSigDTM
			END
			
			* * Wafer Insp & Scan
			
			WfrSig			= RDSRec<RDS_FIRST_WAF_SIG$>
			WfrSigDTM		= ICONV(OCONV(RDSRec<RDS_FIRST_WAF_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_FIRST_WAF_SIG_TIME$>,'MTS'),'DT')
			
			IF PSRec<PROD_SPEC_FIRST_BRIGHTLIGHT$> = 1 OR PSRec<PROD_SPEC_FIRST_MICROSCOPE$> = 1 THEN
				
				LOCATE WOStepNo:'WFRI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = WfrSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= WfrSigDTM
				END
				
			END
				
			IF PSRec<PROD_SPEC_FIRST_SURFSCAN$> = 1 OR PSRec<PROD_SPEC_FIRST_SURFSCAN_RECIPE$> NE '' THEN	
				
				LOCATE WOStepNo:'WFRS' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = WfrSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= WfrSigDTM
				END
			END	
			
			
			* * Unload
			
			
			UnloadSig		= RDSRec<RDS_OPERATOR_OUT$>
			UnloadSigDTM	= ICONV(OCONV(RDSRec<RDS_DATE_OUT$>,'D4/'):' ':OCONV(RDSRec<RDS_TIME_OUT$>,'MTS'),'DT')
			
			LOCATE WOStepNo:'UNLOAD' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = UnloadSig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= UnloadSigDTM
			END
			
			* * Post Epi Insp 
			
			PostSig			= RDSRec<RDS_POST_EPI_SIG$>
			PostSigDTM		= ICONV(OCONV(RDSRec<RDS_POST_EPI_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_POST_EPI_SIG_TIME$>,'MTS'),'DT')
			
			IF RDSRec<RDS_POST_CODE$> NE '' OR RDSRec<RDS_POST_BOAT_ID$> NE '' OR RDSRec<RDS_POST_SRD_NUM$> NE '' THEN
				
				LOCATE WOStepNo:'PSTC' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PostSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PostSigDTM
				END
				
			END
			
			IF PSRec<PROD_SPEC_POST_CLEAN_BRIGHTLIGHT$> = 1 THEN
				
				
				LOCATE WOStepNo:'PSTI' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PostSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PostSigDTM
				END
				
			END
			
			IF PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN$> = 1 OR PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN_RECIPE$> NE '' THEN
				
				LOCATE WOStepNo:'PSTS' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
					WOMatRec<WO_MAT_SIGNATURE$,Pos> = PostSig
					WOMatRec<WO_MAT_SIG_DTM$,Pos>	= PostSigDTM
				END
				
			END
			
			
			QASig			= RDSRec<RDS_SUP_VER_SIG$>
			QASigDTM		= ICONV(OCONV(RDSRec<RDS_SUP_VER_SIG_DATE$>,'D4/'):' ':OCONV(RDSRec<RDS_SUP_VER_SIG_TIME$>,'MTS'),'DT')
			
			LOCATE WOStepNo:'QA' IN WOMatRec<WO_MAT_SIG_PROFILE$> USING @VM SETTING Pos THEN
				WOMatRec<WO_MAT_SIGNATURE$,Pos> = QASig
				WOMatRec<WO_MAT_SIG_DTM$,Pos>	= QASigDTM
			END
		
		NEXT I
		
		
		
		WRITE WOMatRec ON WOMatTable,WOMatKey THEN
			FixCnt += 1
			Send_Dyn(WOMatKey)
		END
		
		
* * * * * * *		
SkipRecord:
* * * * * * *
		
	END	;* End of WOMat record read
	Send_Info(RecCnt:' ':FixCnt)
	
REPEAT


GOTO Bail


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

END
