COMPILE FUNCTION obj_Prod_Spec(Method,Parms)
/*
	Methods for Prod_Spec original product specification table
	Used to wrap messy original file in something cleaner while working on a transistion
    
	08/08/2004 JCH - Initial Coding
	
	06/13/24	djm		Add support for EPP signature profile.
     
    Properties:
     
    Methods:
    
    GetLayerProp(PSNo,LayerSet)
    SpecType(PSNo)
	
*/
#pragma precomp SRP_PreCompiler

DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box, OBJ_POPUP
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Make.List, Btree.Extract, ErrMsg, obj_Epi_Part, obj_Cust_Epi_Part, obj_PRS_Stage
DECLARE SUBROUTINE Send_Dyn, Update_Index

$INSERT MSG_EQUATES
$INSERT POPUP_EQUATES
$INSERT PROD_SPEC_EQUATES
$INSERT QUOTE_SPEC_EQU
$INSERT PRS_LAYER_EQU
$INSERT PROD_VER_EQUATES
$INSERT PRS_LAYER_EQUATES
$INSERT PRS_PROP_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT RECIPE_EQUATES
$INSERT RECIPE_LAYER_INFO_EQU	;* Used with LAYER_INFO field rathole data in the RECIPE table
$INSERT QA_MET_EQUATES			;* Used in GetQAMet return data structure
$INSERT LOGICAL

EQU LS_ID$		TO 1		;* Use these equates for the PRS_LAYER records until converstion is done and PRS_LAYER_EQU can go away.
EQU LAYER_TYPE$	TO 2
EQU RECIPE$		TO 3

EQU UNIT$THICK			TO CHAR(230):'m'			;* Microns
EQU UNIT$THICKA			TO CHAR(143)				;* Angstroms
EQU UNIT$RES			TO CHAR(234):'-cm'			;* Ohms.Cm
EQU UNIT$SRES			TO CHAR(234):'/':CHAR(220)	;* Ohms/Square
EQU UNIT$CRES			TO CHAR(234):'-cm'			;* Ohms.Cm
EQU UNIT$CONC			TO 'CM-3'					;* Carriers.Cubic Centimeter
EQU UNIT$STRESS			TO 'dyne/cm-2'				;* Dyne/Square Centimeter
EQU UNIT$BOW			TO CHAR(230):'m'			;* Microns
EQU UNIT$TRANS			TO CHAR(230):'m'			;* Microns

EQU MET_PROP$CODE			TO 1		;* Used with MET_PROPERTY popup contents
EQU MET_PROP$PROPERTY		TO 2
EQU MET_PROP$IN_CONV		TO 3
EQU MET_PROP$OUT_CONV		TO 4
EQU MET_PROP$SYMBOL			TO 5
EQU MET_PROP$UNITS			TO 6

ErrTitle = 'Error in Stored Procedure "obj_Prod_Spec"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'GetSpec'				; GOSUB GetSpec
	CASE Method = 'GetProp'				; GOSUB GetProp
	CASE Method = 'GetLayerProp'		; GOSUB GetLayerProp
	CASE Method = 'SpecType'			; GOSUB SpecType
	CASE Method = 'Quotes'				; GOSUB Quotes
	CASE Method = 'GetSubSupplier'		; GOSUB GetSubSupplier
	CASE Method = 'CheckLastActivity'	; GOSUB CheckLastActivity
	CASE Method = 'GetSigProfile'		; GOSUB GetSigProfile
	CASE Method = 'GetRunSigProfile'	; GOSUB GetRunSigProfile
	CASE Method = 'GetWfrSigProfile'	; GOSUB GetWfrSigProfile
	CASE Method = 'GetCIProfile'		; GOSUB GetCIProfile
	CASE Method = 'AvailMUWafers'		; GOSUB AvailMUWafers
	CASE Method = 'PartNos'				; GOSUB PartNos
	CASE Method = 'PSNId'				; GOSUB PSNId
	CASE Method = 'GetStage'			; GOSUB GetStage
	CASE Method = 'PushSplit'			; GOSUB PushSplit
	CASE Method = 'ProdVerSortKeys'		; GOSUB ProdVerSortKeys
	CASE Method = 'PushTech'			; GOSUB PushTech
	CASE Method = 'StageSortKeys'		; GOSUB StageSortKeys
	CASE Method = 'CEPSortKeys'			; GOSUB CEPSortKeys
	CASE Method = 'Duplicate'			; GOSUB Duplicate
	CASE Method = 'GetQAMet'			; GOSUB GetQAMet
		
	CASE 1
		
END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

RETURN Result


* * * * * * *
GetSpec:
* * * * * * *
	
	PSNo		= Parms[1,@RM]
	PSRec		= Parms[COL2()+1,@RM]	;* 
	LayerNo		= Parms[COL2()+1,@RM]	;* Pass Null for all Layers
	PropCode	= Parms[COL2()+1,@RM]	;* Pass Property Code or pass as null for Fields in the PRS_LAYER table
	FieldNo		= Parms[COL2()+1,@RM]	;* Pass FieldNo as an equate
	
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN RETURN
	
	LayerKeys = PSRec<PROD_SPEC_PRS_LAYER_KEY$>
	
	LayerCnt = COUNT(LayerKeys,@VM) + (LayerKeys NE '')
	
	FOR I = 1 TO LayerCnt
		LayerKey	= LayerKeys<1,I>
		
		IF PropCode NE '' THEN
			PropVal = ICONV(XLATE('PRS_PROP',LayerKey:'*':PropCode,FieldNo,'X'),'[MET_PROP_CONV,':PropCode:']')
			Result<1,I> = OCONV( PropVal,'[MET_PROP_CONV,':PropCode:']')
		END ELSE
			LayerRec = XLATE('PRS_LAYER',LayerKey,'','X')
			Result = LayerRec<FieldNo>
		END
		
	NEXT I
	
RETURN


* * * * * * *
GetProp:
* * * * * * *
	
	PSNo			= Parms[1,@RM]
	PSRec			= Parms[COL2()+1,@RM]
	DictFieldName	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN RETURN
	
	PropCds = obj_Popup('AllCodes','MET_PROPERTY')
	
	PropCd = DictFieldName[1,'_']
	IF PropCd = 'CON' THEN PropCd = 'CONC'
	
	LOCATE PropCd IN PropCds USING @VM SETTING Pos THEN
		DictFieldName[1,COL2()] = ''
		LayerNo = DictFieldName[-1,'B_']
		DictFieldName[COL1(),COL2()] = ''
		
		IF DictFieldName = 'MIN' OR DictFieldName = 'MAX' THEN
			DictfieldName = 'RAW_':DictFieldName
		END
		
		IF LayerNo[1,1] _eqc 'A' THEN
			
			* All Layers
			
			LSKeys = PSRec<PROD_SPEC_PRS_LAYER_KEY$>
			lsCnt = COUNT(LSKeys,@VM) + (LSKeys NE '')
			
			FOR I = 1 TO lsCnt
				LSKey = LSKeys<1,I>
				Val = XLATE('PRS_PROP',LSKey:'*':PropCd,DictFieldName,'X')
				Result<1,I> = OCONV(Val,'[MET_PROP_CONV,':PropCd:']')
			NEXT I
			
		END ELSE
			
			* Single Layer
			
			CONVERT 'L' TO '' IN LayerNo
			Val = XLATE('PRS_PROP',PSNo:'*':LayerNo:'*':PropCd,DictFieldName,'X')
			Result = OCONV(Val,'[MET_PROP_CONV,':PropCd:']')
		END
		
		
	END	;* End of check for Met Property code in the first postion
	
	
RETURN


* * * * * * *
GetLayerProp:
* * * * * * *
	
	PSNo			= Parms[1,@RM]
	LayerSets		= Parms[COL2()+1,@RM]	;* @VM Delimited list of LayerSets - Returns all layers if passed null
	NoConversion	= Parms[COL2()+1,@RM]	;* Don't do output conversion
	
	IF PSNo = '' THEN RETURN
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	
	IF PSRec = '' THEN Return
	
	EpiLayers = PSRec<15>
	
	CONVERT CHAR(248) TO @RM IN EpiLayers
	CONVERT @VM TO @FM IN EpiLayers
	CONVERT @SVM TO @VM IN EpiLayers
	CONVERT '~' TO @VM IN EpiLayers
	
	SpecAddtls = PSRec<25>
	
	CONVERT CHAR(248) TO @RM IN SpecAddtls
	CONVERT @VM TO @FM IN SpecAddtls
	CONVERT @SVM TO @VM IN SpecAddtls
	CONVERT '~' TO @VM IN SpecAddtls
	
	CompResult = ''
	
	LayerCount = COUNT(EpiLayers,@RM) + (EpiLayers NE '')
	
	FOR I = 1 TO LayerCount
		
		EpiLayer = FIELD(EpiLayers,@RM,I,1)
		SpecAddtl = FIELD(SpecAddtls,@RM,I,1)
		
		BEGIN CASE
			CASE I = 1
				Layer = 'L1'
				
			CASE I = 2 
				IF LayerCount = 3 THEN
					Layer = 'L2'
				END ELSE
					Layer = '2'
				END
				
			CASE I = 3 ; Layer = '2'
			CASE 1 ; Layer = I-1
		END CASE
		
		ResultLine = ''
		
		Dopant			= EpiLayer<10>
		Recipe			= EpiLayer<11>
		RecipeName		= EpiLayer<12>
		ConcMin			= EpiLayer<1,1>						;* This could have @SVM's in it - (old stuff-not used anymore)
		ConcMax			= EpiLayer<2,1>						;* This could have @SVM's in it - (old stuff-not used anymore)
		ConcUnits		= EpiLayer<3>
		ConcMeasure		= EpiLayer<15>						;* This is a measurment data structure
		ResMin			= EpiLayer<4>
		ResMax			= EpiLayer<5>
		ResUnits		= EpiLayer<6>
		ResMeasure		= EpiLayer<14>						;* This is a measurment data structure
		ThickMin		= EpiLayer<7>
		ThickMax		= EpiLayer<8>
		ThickUnits		= EpiLayer<9>
		ThickMeasure	= Epilayer<13>						;* This is a measurment data structure
		CResMin			= Epilayer<16>						;* CRes Added 4/9/2009 JCH
		CResMax			= Epilayer<17>
		CresUnits		= Epilayer<18>
		CResMeasure		= Epilayer<19>						;* This is a measurment data structure
		CResPhaseMin    = Epilayer<20>
		StressMin		= SpecAddtl<QSAddStressMin$>
		StressMax		= SpecAddtl<QSAddStressMax$>
		StressMeasure	= SpecAddtl<QSAddStressMeasure$>	;* This is a measurment data structure 
		TransSpec		= SpecAddtl<QSAddTransSpec$>
		TransMeasure	= SpecAddtl<QSAddTransMeasure$>		;* This is a measurment data structure
		
		ResultLine<PRS_LAYER_DOPANT$>				= Dopant
		ResultLine<PRS_LAYER_RECIPE$>				= Recipe
		ResultLine<PRS_LAYER_RECIPE_NAME$>			= RecipeName
		
		IF NoConversion THEN
			ResultLine<PRS_LAYER_CONC_MIN$>			= ConcMin
			ResultLine<PRS_LAYER_CONC_MAX$>			= ConcMax
		END ELSE
			ResultLine<PRS_LAYER_CONC_MIN$>			= OCONV(ConcMin,'MS21')
			ResultLine<PRS_LAYER_CONC_MAX$>			= OCONV(ConcMax,'MS21')
		END
		
		ResultLine<PRS_LAYER_CONC_UNITS$>			= ConcUnits
		ResultLine<PRS_LAYER_CONC_MEASUREMENT$>		= ConcMeasure
		
		* CRes Added 4/9/2009 JCH
		IF NoConversion THEN
			ResultLine<PRS_LAYER_CRES_MIN$>			= CResMin
			ResultLine<PRS_LAYER_CRES_MAX$>			= CResMax
		END ELSE
			ResultLine<PRS_LAYER_CRES_MIN$>			= OCONV(CResMin,'MD3')
			ResultLine<PRS_LAYER_CRES_MAX$>			= OCONV(CResMax,'MD3')
		END
		
		ResultLine<PRS_LAYER_CRES_UNITS$>			= CResUnits
		ResultLine<PRS_LAYER_CRES_MEASUREMENT$>		= CResMeasure
		ResultLine<PRS_LAYER_CRES_PHASE_MIN$>       = CResPhaseMin
		
		IF NoConversion THEN
			ResultLine<PRS_LAYER_RES_MIN$>			= ResMin
			ResultLine<PRS_LAYER_RES_MAX$>			= ResMax
		END ELSE
			ResultLine<PRS_LAYER_RES_MIN$>			= OCONV(ResMin,'MD3')
			ResultLine<PRS_LAYER_RES_MAX$>			= OCONV(ResMax,'MD3')
		END
		
		ResultLine<PRS_LAYER_RES_UNITS$>			= ResUnits
		ResultLine<PRS_LAYER_RES_MEASUREMENT$>		= ResMeasure
		
		IF NoConversion THEN
			ResultLine<PRS_LAYER_THICK_MIN$>		= ThickMin
			ResultLine<PRS_LAYER_THICK_MAX$>		= ThickMax
		END ELSE
			ResultLine<PRS_LAYER_THICK_MIN$>		= OCONV(ThickMin,'MD3')
			ResultLine<PRS_LAYER_THICK_MAX$>		= OCONV(ThickMax,'MD3')
		END
		
		ResultLine<PRS_LAYER_THICK_UNITS$>			= ThickUnits
		ResultLine<PRS_LAYER_THICK_MEASUREMENT$>	= ThickMeasure
		ResultLine<PRS_LAYER_STRESS_MIN$>			= StressMin
		ResultLine<PRS_LAYER_STRESS_MAX$>			= StressMax
		ResultLine<PRS_LAYER_STRESS_MEASUREMENT$>	= StressMeasure
		ResultLine<PRS_LAYER_TRANS_SPEC$>			= TransSpec
		ResultLine<PRS_LAYER_TRANS_MEASUREMENT$>	= TransMeasure
		
		ConcMin = ICONV(ConcMin,'MS')
		ConcMax = ICONV(ConcMax,'MS')
		IF ConcMin NE '' AND ConcMax NE '' THEN
			IF NUM(ConcMin) AND NUM(ConcMax) THEN
				IF ConcMin = ConcMax THEN
					ConcTarget = ConcMin
				END ELSE
					ConcDelta = INT((ConcMax - ConcMin)/2)
					ConcTarget = (ConcMin + ConcDelta)
				END
				
				IF NoConversion THEN
					ResultLine<PRS_LAYER_CONC_TARGET$> = ConcTarget
				END ELSE	
					ResultLine<PRS_LAYER_CONC_TARGET$> = OCONV(ConcTarget,'MS21')
				END
				
			END
		END
		
		* CRes Added 4/9/2009 JCH
		IF CResMin NE '' AND CResMax NE '' THEN
			IF NUM(CResMin) AND NUM(CResMax) THEN
				IF CResMin = CResMax THEN
					CResTarget = CResMin
				END ELSE
					CResDelta = INT((CResMax - CResMin)/2)
					CResTarget = (CResMin + CResDelta)
				END
				
				IF NoConversion THEN
					ResultLine<PRS_LAYER_CRES_TARGET$> = CResTarget
				END ELSE	
					ResultLine<PRS_LAYER_CRES_TARGET$> = OCONV(CResTarget,'MD3')
				END
				
			END
		END
		
		IF ResMin NE '' AND ResMax NE '' THEN
			IF NUM(ResMin) AND NUM(ResMax) THEN
				IF ResMin = ResMax THEN
					ResTarget = ResMin
				END ELSE
					ResDelta = INT((ResMax - ResMin)/2)
					ResTarget = (ResMin + ResDelta)
				END
				
				IF NoConversion THEN
					ResultLine<PRS_LAYER_RES_TARGET$> = ResTarget
				END ELSE	
					ResultLine<PRS_LAYER_RES_TARGET$> = OCONV(ResTarget,'MD3')
				END
				
			END
		END
		
		IF ThickMin NE '' AND ThickMax NE '' THEN
			IF NUM(ThickMin) AND NUM(ThickMax) THEN
				IF ThickMin = ThickMax THEN
					ThickTarget = ThickMin
				END ELSE
					ThickDelta = INT((ThickMax - ThickMin)/2)	;* Same as above
					ThickTarget = (ThickMin + ThickDelta)
				END
				
				IF NoConversion THEN
					ResultLine<PRS_LAYER_THICK_TARGET$> = ThickTarget
				END ELSE
					ResultLine<PRS_LAYER_THICK_TARGET$> = OCONV(ThickTarget,'MD2')
				END
				
			END
		END
		
		
		IF LayerSets = '' THEN
			CompResult := Layer:@FM:ResultLine:@RM
		END ELSE
			LOCATE Layer IN LayerSets USING @VM Setting Pos THEN
				CompResult := Layer:@FM:ResultLine:@RM
			END
		END
		
	NEXT I
	
	IF CompResult[-1,1] = @RM THEN CompResult[-1,1] = ''
	Result = CompResult
	
RETURN


* * * * * * *
SpecType:
* * * * * * *
	
	PSNo		= Parms[1,@RM]
	
	IF NOT(ASSIGNED(PSNo))		THEN RETURN
	
	IF PSNo = '' THEN RETURN
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	PSStatus = PSRec<PROD_SPEC_STATUS$>
	
	IF PSStatus = 'I' THEN
		RETURN	;* Return null - Specification is inactive
	END
	
	IF PSRec = '' THEN
		ErrorMsg = 'No PROD_SPEC record found for PSNo ':QUOTE(PSNo):'. (':Method:')'
		RETURN
	END
	
	SpecAddtls = PSRec<25>
	
	NumSigs = DCount(PSRec<PROD_SPEC_MODE_SIG$>, @VM)
	CurrMode = PSRec<PROD_SPEC_MODE_CODE$, NumSigs>
	
	* ProdSig 	= PSRec<PROD_SPEC_MODE_SIG$,4>
	* QualSig		= PSRec<PROD_SPEC_MODE_SIG$,2>
	* PreProdSig	= PSRec<PROD_SPEC_MODE_SIG$,3>
	* PreQualSig 	= PSRec<PROD_SPEC_MODE_SIG$,1>
	
	
	BEGIN CASE
		
		Case CurrMode EQ 'U'
			StatText = 'PreQualification'
			
		Case CurrMode EQ 'Q'
			StatText = 'Qualification'
			
		Case CurrMode EQ 'E'
			StatText = 'PreProduction'
			
		Case CurrMode EQ 'P'
			StatText = 'Production'
			
		Case Otherwise$
			StatText = 'Setup'
			
	End Case
	
	Result = StatText
	
Return

* 	CASE ProdSig NE ''
*		StatText = 'Production'
*		
* 	CASE PreProdSig NE ''
*		StatText = 'PreProduction'
*		
* 	CASE QualSig NE ''
*		StatText = 'Qualification'
*		
* 	CASE PreQualSig	NE ''
*		StatText = 'PreQualification'


* * * * * * *
Quotes:
* * * * * * *
	
	PSNo		= Parms[1,@RM]
	
	IF NOT(ASSIGNED(PSNo))		THEN RETURN
	
	IF PSNo = '' THEN RETURN
	
	OPEN 'DICT.QUOTE' TO DictVar ELSE
		ErrorMsg = 'Unable to open "DICT.QUOTE" in routine.'
		RETURN
	END
	
	SearchString = 'PROC_STEP_PSN':@VM:PSNo:@FM
	
	QuoteNos = ''
	Btree.Extract(SearchString,'QUOTE',DictVar,QuoteNos,'',Flag)
	
	errCode = ''
	IF Get_Status(errCode) THEN DEBUG
	
	FOR I = 1 TO COUNT(QuoteNos,@VM) + (QuoteNos NE '')
		QuoteNo = QuoteNos<0, I>
		LOCATE QuoteNo IN Result BY 'AR' USING @VM SETTING Pos ELSE
			Result = INSERT(Result,1,Pos,0,QuoteNo)
		END
	NEXT I
	
RETURN


* * * * * * *
GetSubSupplier:
* * * * * * *
	
	PSNo		= Parms[1,@RM]
	SubPartNo	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	IF SubPartNo = '' THEN RETURN
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	
	SubPartNos = PSRec<PROD_SPEC_SUB_PART_NUMS$>
	SubSuppliers = PSRec<PROD_SPEC_SUB_WAFER_MFG$>
	
	LOCATE SubPartNo IN SubPartNos USING @VM SETTING Pos THEN
		Result = SubSuppliers<1,Pos>
	END
	
RETURN


* * * * * * *
CheckLastActivity:
* * * * * * *
	
	Days	= Parms[1,@RM]
	PSNo	= Parms[COL2()+1,@RM]
	
	* Checks for activity in the last N days
	
	IF PSNo = '' THEN RETURN
	IF Days = '' THEN RETURN
	
	
	OPEN 'DICT.WO_LOG' TO DictVar ELSE RETURN
	
	SearchString  = 'PS_NO':@VM:'[':PSNo:']':@FM
	SearchString := 'ENTRY_DATE':@VM:'>=':OConv(DATE()-Days, 'D4/'):@FM
	
	Option = ''
	Flag = ''
	
	Keys = ''
	Btree.Extract(SearchString, 'WO_LOG', Dictvar, Keys, Option, Flag)
	
	IF Keys NE '' THEN Result = 1
	
Return


* * * * * * *
GetWfrSigProfile:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN Return
	
	GOSUB GetStage
	
	StageKeys	= Result<2>
	Result		= ''
	
	SWAP PSNo:'*'  WITH '' IN StageKeys
	
	Result = StageKeys	
	
	
RETURN 


* * * * * * *
GetRunSigProfile:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN Return
	
	GOSUB GetStage
	
	StageKeys	= Result<1>
	Result		= ''
	
	SWAP PSNo:'*'  WITH '' IN StageKeys
	
	Result = StageKeys	
	
RETURN

* * * * * * *
GetSigProfile:
* * * * * * *
	
	PSNo     = Parms[1,@RM]
	PSRec    = Parms[COL2()+1,@RM]
	WOMatKey = Parms[COL2()+1,@RM]
	RDSNo    = Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN Return
	
	ReactorType = PSRec<PROD_SPEC_REACTOR_TYPE$>
	
	Sigs = ''
	
	Begin CASE
		Case ReactorType = 'P' OR ReactorType = 'EPP' 
			/*
					* * * * * * * * * * * * * * * * * * * *  No signatures on the inbound material  * * * * * * * * 
					
					Sigs<1,-1> = 'MI_VER'
			
					* * WM_IN Cleaning and Inspection * *
			
					SCSubOxide		= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubOxide$>
					SCAngstroms		= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubOxideAngstroms$>
					SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreClean$>
					SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreAkrionRecipe$>
			
					IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
					IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
					 
					SBrightLight	= PSRec<PROD_SPEC_PRE_BRIGHTLIGHT$>
					SMicroscope		= PSRec<PROD_SPEC_PRE_MICROSCOPE$>
			
					SSurfscan		= PSRec<PROD_SPEC_PRE_SURFSCAN$>
					SSurfscanRecipe	= PSRec<PROD_SPEC_PRE_SURFSCAN_RECIPE$>
			
			
					IF SCSubOxide = 1 OR SCAngstroms NE '' OR SCTool NE '' OR SCToolRecipe NE ''	THEN Sigs<1,-1> = 'MI_PREC'
					IF SBrightLight = 1 OR SMicroscope = 1											THEN Sigs<1,-1> = 'MI_PREI'
					IF SSurfscan = 1 OR SSurfscanRecipe NE ''										THEN Sigs<1,-1> = 'MI_PRES'
					
					* * Reactor Run 
			
					Sigs<1,-1> = 'RN_LOAD'
					Sigs<1,-1> = 'RN_UNLOAD'
			
					* * First/Last Wafer Cleaning and Inspection * *
			
					Spec_FWI_LWI	= PSRec<PROD_SPEC_POST_FWI_LWI$>		;* FWI OR LWI
			
					SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostClean$>
					SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostAkrionRecipe$>
			
					IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
					IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
			
					SBrightLight	= PSRec<PROD_SPEC_FIRST_BRIGHTLIGHT$>
					SMicroscope		= PSRec<PROD_SPEC_FIRST_MICROSCOPE$>
			
					SSurfscan		= PSRec<PROD_SPEC_FIRST_SURFSCAN$>
					SSurfscanRecipe	= PSRec<PROD_SPEC_FIRST_SURFSCAN_RECIPE$>
			
					IF SCTool NE '' OR SCToolRecipe NE ''		THEN Sigs<1,-1> = 'RN_WFRC'
					IF SBrightLight = 1 OR SMicroscope = 1		THEN Sigs<1,-1> = 'RN_WFRI'	
					IF SSurfscan = 1 OR SSurfscanRecipe NE ''	THEN Sigs<1,-1> = 'RN_WFRS'
			
					*Sigs<1,-1> = 'PVER'						;************  This is conditional from somewhere
			
					*/
			* * WM_OUT - Cleaning and Inspection * *
			If RDSNo NE '' then
				
				Sigs<1,-1> = 'VER'
				
				* * Pre Epi Cleaning and Inspection * *
				
				StageRec = XLATE('PRS_STAGE',PSNo:'*PRE','','X')		;* 1/15/2013 JCH **********
				
				IF StageRec<PRS_STAGE_CLEAN_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'PREC'
				IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'PREI'
				IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1 	THEN Sigs<1,-1> = 'PRES'
				
				Sigs<1,-1> = 'LOAD'
				
				* * First Wafer Inspection and Surfscan * *
				
				StageRec = XLATE('PRS_STAGE',PSNo:'*FWI','','X')		;* 1/15/2013 JCH **********
				IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1 	    THEN Sigs<1,-1> = 'FWII'	
				IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1    THEN Sigs<1,-1> = 'FWIS'
				
				Sigs<1,-1> = 'UNLOAD'
				
				* * Last Wafer Inspection and Surfscan  ******************	;* 1/15/2013 JCH **********
				
				StageRec = XLATE('PRS_STAGE',PSNo:'*LWI','','X')			;* 1/15/2013 JCH **********
				
				InspReq = True$
				InspSig = ''
			
				// Old records may have more than one RDS
				If RowExists('RDS', RDSNo) then
					LWICINo = Xlate('RDS', RDSNo, 'LWI_CI_NO', 'X')<0, 1>
					InspInterval = Xlate('CLEAN_INSP', LWICINo, 'INSP_INTERVAL', 'X')<0, 1>
					If InspInterval NE '' then
						// Use the stored interval
						StageKey     = PSNo:'*LWI'
						WONo         = Field(WOMatKey, '*', 1)<0, 1>
						WOQty        = Xlate('WO_LOG', WONo, 'QTY', 'X')<0, 1>
						RunNo        = Xlate('RDS', RDSNo, 'RUN_ORDER_NUM', 'X')<0, 1>
						LastRun      = ( (RunNo * 25) EQ WOQty )
						InspReq      = ( (Mod((RunNo - 1), InspInterval) EQ 0) or LastRun )
					end else
						// Use the current PRS_STAGE interval
						InspReq = Xlate('CLEAN_INSP', LWICINo, 'INSP_REQ', 'X')
					end
					InspReq = Xlate('CLEAN_INSP', LWICINo, 'SPEC_INSP_REQ', 'X')
					If InspReq EQ '' then InspReq = Xlate('CLEAN_INSP', LWICINo, 'INSP_REQ', 'X')
					InspReq = Xlate('CLEAN_INSP', LWICINo, 'INSP_REQ', 'X')
					InspSig = Xlate('CLEAN_INSP', LWICINo, 'INSP_SIG', 'X')
				end
			
				If ( (StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1) and ( (InspReq EQ True$) or (InspSig NE '') ) ) then
					Sigs<1,-1> = 'LWII'	
				end
				IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1	THEN Sigs<1,-1> = 'LWIS'
				
				* * Post Epi Clean and Inspection  ******************	;* 1/15/2013 JCH **********
			
				StageRec = XLATE('PRS_STAGE',PSNo:'*POST','','X')		;* 1/15/2013 JCH **********
				
				IF StageRec<PRS_STAGE_CLEAN_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'PSTC'
				IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1 		THEN Sigs<1,-1> = 'PSTI'
				IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1	THEN Sigs<1,-1> = 'PSTS'	
				
			end
			
			If WOMatKey NE '' then 
			
				StageRec = XLATE('PRS_STAGE',PSNo:'*POST','','X')		;* 1/15/2013 JCH **********
				
				IF StageRec<PRS_STAGE_CLEAN_SIG_REQ$> = 1 		THEN Sigs<1,-1> = 'MO_PSTC'
				IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'MO_PSTI'
				IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1	THEN Sigs<1,-1> = 'MO_PSTS'
				
				Sigs<1,-1> = 'MO_QA'
				
			end
			
		Case ReactorType = 'GAN'
			
			
			Sigs<1,-1> = 'G_FQA'		;* This is the Final QA on the shipping cassette
			
			
		Case 1
			
			Sigs<1,-1> = 'VER'
			
			* * Pre Epi Cleaning and Inspection * *
			
			StageRec = XLATE('PRS_STAGE',PSNo:'*PRE','','X')		;* 1/15/2013 JCH **********
			
			IF StageRec<PRS_STAGE_CLEAN_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'PREC'
			IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'PREI'
			IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1 	THEN Sigs<1,-1> = 'PRES'
			
			Sigs<1,-1> = 'LOAD'
			
			* * First Wafer Inspection and Surfscan * *
			
			StageRec = XLATE('PRS_STAGE',PSNo:'*FWI','','X')		;* 1/15/2013 JCH **********
			IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1 	    THEN Sigs<1,-1> = 'FWII'	
			IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1    THEN Sigs<1,-1> = 'FWIS'
			
			Sigs<1,-1> = 'UNLOAD'
			
			* * Last Wafer Inspection and Surfscan  ******************	;* 1/15/2013 JCH **********
			
			StageRec = XLATE('PRS_STAGE',PSNo:'*LWI','','X')			;* 1/15/2013 JCH **********
			
			InspReq = True$
			InspSig = ''
			If WOMatKey NE '' then
				// Old records may have more than one RDS
				RDSNo   = Xlate('WO_MAT', WOMatKey, 'RDS_NO', 'X')<0, 1>
				If RowExists('RDS', RDSNo) then
					LWICINo = Xlate('RDS', RDSNo, 'LWI_CI_NO', 'X')<0, 1>
					InspInterval = Xlate('CLEAN_INSP', LWICINo, 'INSP_INTERVAL', 'X')<0, 1>
					If InspInterval NE '' then
						// Use the stored interval
						StageKey     = PSNo:'*LWI'
						WONo         = Field(WOMatKey, '*', 1)<0, 1>
						WOQty        = Xlate('WO_LOG', WONo, 'QTY', 'X')<0, 1>
						RunNo        = Xlate('RDS', RDSNo, 'RUN_ORDER_NUM', 'X')<0, 1>
						LastRun      = ( (RunNo * 25) EQ WOQty )
						InspReq      = ( (Mod((RunNo - 1), InspInterval) EQ 0) or LastRun )
					end else
						// Use the current PRS_STAGE interval
						InspReq = Xlate('CLEAN_INSP', LWICINo, 'INSP_REQ', 'X')
					end
					InspReq = Xlate('CLEAN_INSP', LWICINo, 'SPEC_INSP_REQ', 'X')
					If InspReq EQ '' then InspReq = Xlate('CLEAN_INSP', LWICINo, 'INSP_REQ', 'X')
					InspReq = Xlate('CLEAN_INSP', LWICINo, 'INSP_REQ', 'X')
					InspSig = Xlate('CLEAN_INSP', LWICINo, 'INSP_SIG', 'X')
				end
			end
			If ( (StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1) and ( (InspReq EQ True$) or (InspSig NE '') ) ) then
				Sigs<1,-1> = 'LWII'	
			end
			IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1	THEN Sigs<1,-1> = 'LWIS'
			
			* * Post Epi Clean and Inspection  ******************	;* 1/15/2013 JCH **********
			
			StageRec = XLATE('PRS_STAGE',PSNo:'*POST','','X')		;* 1/15/2013 JCH **********
			
			IF StageRec<PRS_STAGE_CLEAN_SIG_REQ$> = 1		THEN Sigs<1,-1> = 'PSTC'
			IF StageRec<PRS_STAGE_INSP_SIG_REQ$> = 1 		THEN Sigs<1,-1> = 'PSTI'
			IF StageRec<PRS_STAGE_SURFSCAN_SIG_REQ$> = 1	THEN Sigs<1,-1> = 'PSTS'
			
			Sigs<1,-1> = 'QA'
	End CASE
	
	
	Result = Sigs
	
RETURN


* * * * * * *
GetCIProfile:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN Return
	
	ReactorType = PSRec<PROD_SPEC_REACTOR_TYPE$>
	
	Stages = ''
	TypeCodes = ''
	
	*IF ReactorType = 'P' OR ReactorType = 'EPP' THEN
	
	* * WM_IN Cleaning and Inspection * *
	
	SCSubOxide		= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubOxide$>
	SCAngstroms		= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubOxideAngstroms$>
	SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreClean$>
	SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreAkrionRecipe$>
	
	IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
	IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
	
	SBrightLight	= PSRec<PROD_SPEC_PRE_BRIGHTLIGHT$>
	SMicroscope		= PSRec<PROD_SPEC_PRE_MICROSCOPE$>
	
	SSurfscan		= PSRec<PROD_SPEC_PRE_SURFSCAN$>
	SSurfscanRecipe	= PSRec<PROD_SPEC_PRE_SURFSCAN_RECIPE$>
	
	TypeCode = ''
	
	IF SCSubOxide = 1 OR SCAngstroms NE '' OR SCTool NE '' OR SCToolRecipe NE ''	THEN TypeCode := 'C'
	IF SBrightLight = 1 OR SMicroscope = 1											THEN TypeCode := 'I'
	IF SSurfscan = 1 OR SSurfscanRecipe NE ''										THEN TypeCode := 'S'
	
	IF TypeCode NE '' THEN
		Stages<1,-1> = 'PRE'
		TypeCodes<1,-1> = TypeCode
	END
	
	* * First/Last Wafer Cleaning and Inspection * *
	
	Spec_FWI_LWI	= PSRec<PROD_SPEC_POST_FWI_LWI$>		;* FWI OR LWI
	
	SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostClean$>
	SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostAkrionRecipe$>
	
	IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
	IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
	
	SBrightLight	= PSRec<PROD_SPEC_FIRST_BRIGHTLIGHT$>
	SMicroscope		= PSRec<PROD_SPEC_FIRST_MICROSCOPE$>
	
	SSurfscan		= PSRec<PROD_SPEC_FIRST_SURFSCAN$>
	SSurfscanRecipe	= PSRec<PROD_SPEC_FIRST_SURFSCAN_RECIPE$>
	
	TypeCode = ''
	
	IF SCTool NE '' OR SCToolRecipe NE ''		THEN TypeCode := 'C'
	IF SBrightLight = 1 OR SMicroscope = 1		THEN TypeCode := 'I'
	IF SSurfscan = 1 OR SSurfscanRecipe NE ''	THEN TypeCode := 'S'
	
	IF TypeCode NE '' THEN
		Stages<1,-1> = Spec_FWI_LWI
		TypeCodes<1,-1> = TypeCode
	END
	
	* * WM_OUT - Cleaning and Inspection * *
	
	SBrightLight	= PSRec<PROD_SPEC_POST_CLEAN_BRIGHTLIGHT$>
	
	SSurfscan		= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN$>
	SSurfscanRecipe	= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN_RECIPE$>
	
	SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostClean$>
	SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostAkrionRecipe$>
	
	IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
	IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
	
	TypeCode = ''
	
	IF SCTool NE '' OR SCToolRecipe NE ''		THEN TypeCode := 'C'
	IF SSurfscan = 1 OR SSurfscanRecipe NE ''	THEN TypeCode := 'I'
	IF SBrightLight	= 1							THEN TypeCode := 'S'
	
	IF TypeCode NE '' THEN
		Stages<1,-1> = 'POST'
		TypeCodes<1,-1> = TypeCode
	END
	
	
	*END ELSE
	/*
	
		* * Pre Epi Cleaning and Inspection * *
	
		SCSubOxide		= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubOxide$>
		SCAngstroms		= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubOxideAngstroms$>
		SCAngstroms 	= ''
		
		SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreClean$>
		SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPreAkrionRecipe$>
	
		IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
		IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
		 
		SBrightLight	= PSRec<PROD_SPEC_PRE_BRIGHTLIGHT$>
		SMicroscope		= PSRec<PROD_SPEC_PRE_MICROSCOPE$>
	
		SSurfscan		= PSRec<PROD_SPEC_PRE_SURFSCAN$>
		SSurfscanRecipe	= PSRec<PROD_SPEC_PRE_SURFSCAN_RECIPE$>
	
	
		IF SCSubOxide = 1 OR SCAngstroms NE '' OR SCTool NE '' OR SCToolRecipe NE '' THEN
			Sigs<1,-1> = 'PREC'
		END
	
		IF SBrightLight = 1 OR SMicroscope = 1 THEN
			Sigs<1,-1> = 'PREI'
		END
	
		IF SSurfscan = 1 OR SSurfscanRecipe NE '' THEN
			Sigs<1,-1> = 'PRES'
		END
	
		Sigs<1,-1> = 'LOAD'
	
		* * First/Last Wafer Cleaning and Inspection * *
	
		Spec_FWI_LWI	= PSRec<PROD_SPEC_POST_FWI_LWI$>		;* FWI OR LWI
	
		
		SBrightLight	= PSRec<PROD_SPEC_FIRST_BRIGHTLIGHT$>
		SMicroscope		= PSRec<PROD_SPEC_FIRST_MICROSCOPE$>
	
		SSurfscan		= PSRec<PROD_SPEC_FIRST_SURFSCAN$>
		SSurfscanRecipe	= PSRec<PROD_SPEC_FIRST_SURFSCAN_RECIPE$>
	
		
	
		IF SBrightLight = 1 OR SMicroscope = 1 THEN
			Sigs<1,-1> = 'WFRI'	
		END
	
		IF SSurfscan = 1 OR SSurfscanRecipe NE '' THEN
			Sigs<1,-1> = 'WFRS'
		END
	
		*Sigs<1,-1> = 'PVER'						;************  This is conditional from somewhere
		Sigs<1,-1> = 'UNLOAD'
	
	
		* * Post Epi Cleaning and Inspection * *
		
		
		SCTool			= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostClean$>
		SCToolRecipe	= PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubPostAkrionRecipe$>
	
		IF SCTool[1,2] 			_EQC 'NO' THEN SCTool = ''
		IF SCToolRecipe[1,2] 	_EQC 'NO' THEN SCToolRecipe = ''
	
		SBrightLight	= PSRec<PROD_SPEC_POST_CLEAN_BRIGHTLIGHT$>
	
		SSurfscan		= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN$>
		SSurfscanRecipe	= PSRec<PROD_SPEC_POST_CLEAN_SURFSCAN_RECIPE$>
	
		IF SCTool NE '' OR SCToolRecipe NE '' THEN
			Sigs<1,-1> = 'PSTC'
		END
	
		IF SBrightLight	= 1 THEN
			Sigs<1,-1> = 'PSTI'
		END
	
		IF SSurfscan = 1 OR SSurfscanRecipe NE '' THEN
			Sigs<1,-1> = 'PSTS'
		END
	
		Sigs<1,-1> = 'QA'
	*/	
	*END
	
	Result = Stages:@FM:TypeCodes
	
RETURN

* * * * * * *
AvailMUWafers:
* * * * * * *
	
	PSNo = Parms[1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	
	IF PSRec = '' THEN Return
	
	ReactorType = PSRec<PROD_SPEC_REACTOR_TYPE$>
	
	IF ReactorType = 'P' OR ReactorType = 'EPP' THEN
		
		OPEN 'DICT.WM_OUT' TO DictVar ELSE
			ErrMsg('Unable to open DICT.WM_OUT in COMM_WM_OUT.')
		END
		
		SearchString  = 'MU_PS_NO':@VM:PSNo:@FM
		
		Set_Status(0)
		
		MUWMOutIDs = ""
		Option = ""
		Flag = ""
		Btree.Extract(SearchString, 'WM_OUT', DictVar, MUWMOutIDs, option, flag)
		
		IF Get_Status(errCode) THEN RETURN	;* Called from dictionary
		
		Result = SUM(XLATE('WM_OUT',MUWMOutIDs,'WFRS_OUT','X'))
		
	END ELSE
		
		TableName = 'WO_MAT'
		
		OPEN 'DICT.':TableName TO DictVar ELSE
			ErrMsg('Unable to open DICT.':TableName:' in obj_MUWafers.')
			
			RETURN
		END
		
		SearchString  = 'MU_PS_NO':@VM:PSNo:@FM
		SearchString := 'CURR_STATUS':@VM:'RTU':@FM
		
		Set_Status(0)
		
		OpenRecordIDs = ""
		Option = ""
		Flag = ""
		Btree.Extract(SearchString, TableName, DictVar, OpenRecordIDs, option, flag)
		
		IF Get_Status(errCode) THEN RETURN	;* Called from dictionary
		
		Result = SUM(XLATE('WO_MAT',OpenRecordIDs,'CURR_WFR_CNT','X'))
		
	END
	
RETURN


* * * * * * *
PartNos:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	
	IF PSRec = '' THEN Return
	
	ReactType	= OCONV(PSRec<PROD_SPEC_REACTOR_TYPE$>,'[REACT_TYPE_CONV,CODE]')
	SubPartNos	= PSRec<97>
	PSNIDs		= XLATE('PROD_SPEC',PSNo,'PSN_ID','X')
	
	SPNCnt = COUNT(SubPartNos,@VM) + (SubPartNos NE '')
	PSNIdCnt = COUNT(PSNIDs,@VM) + (PSNIDs NE '')
	
	Ans = ''
	FOR I = 1 TO SPNCnt
		SubPartNo = TRIM(SubPartNos<1,I>)
		
		CONVERT @LOWER_CASE TO @UPPER_CASE IN SubPartNo
		
		PartWorkKeys = ''
		FOR N = 1 TO PSNIdCnt
			PartWorkKeys = SubPartNo:'*':ReactType:'*':PSNIDs<1,N>
		NEXT N
		
		PartNos = XLATE('PART_WORK',PartWorkKeys,1,'X')
		
		CONVERT @VM TO ',' IN PartNos
		
		Ans<1,I> = PartNos
		
	NEXT I
	
	Result = Ans
	
RETURN


* * * * * * *
PSNId:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	
	IF PSRec = '' THEN Return
	
	QuoteStatii = XLATE('PROD_SPEC',PSNo,'QUOTE_STATUS','X')
	QuotePSNIDs = XLATE('PROD_SPEC',PSNo,'QUOTE_PSN_ID','X')
	
	QSCnt = COUNT(QuoteStatii,@VM) + (QuoteStatii NE '')
	
	PSNIDs = ''
	
	FOR N = 1 TO QSCnt
		IF QuoteStatii<1,N> = 'O' THEN
			QuotePSNID = QuotePSNIDs<1,N>
			LOCATE QuotePSNID IN PSNIDs USING @VM SETTING Pos ELSE
				PSNIDs = INSERT(PSNIDs,1,Pos,0,QuotePSNID)
			END
		END
	NEXT N
	
	Result = PSNIDs
	
RETURN

* * * * * * *
GetStage:
* * * * * * *
	
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN Return
	
	StageKeys		= PSRec<PROD_SPEC_PRS_STAGE_KEY$>
	AllStages		= obj_Popup('AllCodes','STAGE')
	SortedKeys		= ''
	SortedWfrKeys	= ''
	
	skCnt = COUNT(StageKeys,@VM) + (StageKeys NE '')
	
	
	FOR I = 1 TO skCnt
		StageKey = StageKeys<1,I>
		Stage = FIELD(StageKey,'*',2)
		WfrFlag = obj_Popup('CodeDesc','STAGE':@RM:Stage:@RM:4)
		
		IF WfrFlag = 1 THEN
			LOCATE Stage IN AllStages USING @VM SETTING Pos THEN
				SortedWfrKeys<1,Pos> = StageKey
			END
		END ELSE		
			LOCATE Stage IN AllStages USING @VM SETTING Pos THEN
				SortedKeys<1,Pos> = StageKey
			END
		END
	NEXT I
	
	
	CONVERT @VM TO ' ' IN SortedKeys
	SortedKeys = TRIM(SortedKeys)
	CONVERT ' ' TO @VM IN SortedKeys
	
	CONVERT @VM TO ' ' IN SortedWfrKeys
	SortedWfrKeys = TRIM(SortedWfrKeys)
	CONVERT ' ' TO @VM IN SortedWfrKeys
	
	
	Result = SortedKeys:@FM:SortedWfrKeys
	
RETURN



* * * * * * *
PushSplit:
* * * * * * *
	
	* Push data to EPI_PART, CUST_EPI_PART AND PROD_VER Tables until we cut over  JCH 5/26/2011
	* Called as a POST WRITE event from event handler in window
	
	
RETURN

PSNo = Parms[1,@RM]

IF PSNo = '' THEN RETURN

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

EpiPN = ''
*EpiPN = PSRec<PROD_SPEC_EPI_PART_NO$>

IF EpiPN NE '' THEN
	obj_Epi_Part('SetSubstrate',EpiPN:@RM:PSNo:@RM:PSRec)
	obj_Cust_Epi_Part('Convert',PSNo:@RM:PSRec)
END

RETURN


* * * * * * *
PushTech:
* * * * * * *
******************************************************************************
******************************************************************************
	PSNo	= Parms[1,@RM]
	
	* Added 4/2/2015 JCH
	* Properties and layers deleted from the rathole data are not being removed from the PRS_LAYER and PRS_PROP tables
	* Check keys from last push, remove newly built keys during process, anything left over -> delete from new tables
	
	OrgPRSLayerKeys = XLATE('PROD_SPEC',PSNo,PROD_SPEC_PRS_LAYER_KEY$,'X')
	OrgPRSPropKeys = XLATE('PRS_LAYER',OrgPRSLayerKeys,PRS_LAYER_PRS_PROP_KEY$,'X')
	
	GOSUB GetLayerProp
	
	LayerSpecs = Result
	Result = ''
	
	LayerCnt = COUNT(LayerSpecs,@RM) + (LayerSpecs NE '')
	
	FOR N = 1 TO LayerCnt
		LayerNo		= N
		LayerSpec	= FIELD(LayerSpecs,@RM,N)
		LSID		= LayerSpec<1>
		LayerSpec 	= FIELD(LayerSpec,@FM,2,99)
		
		Dopant		= LayerSpec<PRS_LAYER_DOPANT$>
		
		IF LSID = 'L1' THEN
			Recipe	= LayerSpec<PRS_LAYER_RECIPE$>
		END
		
		
		IF NUM(LSID) THEN
			LSType = 'CMB'
			Recipe = ''
		END ELSE
			LSType = 'DEP'
		END
		
		PRSLayerKey = PSNo:'*':LayerNo
		PRSLayerRec = LSID:@FM:LSType:@FM:Recipe
		
		LOCATE PRSLayerKey IN OrgPRSLayerKeys USING @VM SETTING Pos THEN
			OrgPRSLayerKeys = DELETE(OrgPRSLayerKeys,1,Pos,0)
		END
		
		OtParms = 'PRS_LAYER':@RM:PRSLayerKey:@RM:@RM:PRSLayerRec
		obj_Tables('WriteRec',OtParms)
		
		IF LayerSpec<PRS_LAYER_THICK_MIN$> NE '' OR LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MTOOL$> NE ''THEN
		
		IF LayerSpec<PRS_LAYER_THICK_UNITS$> = UNIT$THICK THEN
			Prop = 'THICK'
		END ELSE
			Prop = 'THICKA'
		END
		
		PRSPropKey = PSNo:'*':LayerNo:'*':Prop
		
		LOCATE PRSPropKey IN OrgPRSPropKeys USING @VM SETTING Pos THEN
			OrgPRSPropKeys = DELETE(OrgPRSPropKeys,1,Pos,0)
		END
		
		PRSRec = ''
		*PRSRec<PRS_PROP_LS_ID$>			= LSID
		PRSRec<PRS_PROP_RAW_MIN$>			= ICONV(LayerSpec<PRS_LAYER_THICK_MIN$>,'MD5')
		PRSRec<PRS_PROP_RAW_MAX$>			= ICONV(LayerSpec<PRS_LAYER_THICK_MAX$>,'MD5')
		PRSRec<PRS_PROP_UNITS_ORG$>			= LayerSpec<PRS_LAYER_THICK_UNITS$>
		PRSRec<PRS_PROP_TOOL$>				= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MTOOL$>
		PRSRec<PRS_PROP_MET_WFR_TYPE$>		= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MTYPE$>
		PRSRec<PRS_PROP_RECIPE$>			= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MRECIPE$>
		PRSRec<PRS_PROP_FREQ$>				= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MFREQ$>
		PRSRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MPROVEIN$>
		PRSRec<PRS_PROP_FIRST$>				= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MFIRST$>
		PRSRec<PRS_PROP_LAST$>				= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MLAST$>
		PRSRec<PRS_PROP_SPC$>				= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MSPC$>
		PRSRec<PRS_PROP_OVERGROW$>			= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MOVERGROW$>
		PRSRec<PRS_PROP_EXP_TW_QTY$>		= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MEXP_TW_QTY$>
		PRSRec<PRS_PROP_PATTERN$>			= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MPATTERN$>
		PRSRec<PRS_PROP_MET_SLOT$>			= 1
		
		Freq	= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MFREQ$>
		First	= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MFIRST$>
		Last	= LayerSpec<PRS_LAYER_THICK_MEASUREMENT$,PRS_PROP_MLAST$>
		
		BEGIN CASE
			CASE NUM(Freq)  AND Freq NE '' 
				
				PRSRec<PRS_PROP_MET_INTERVAL$>	= Freq
				PRSRec<PRS_PROP_MET_START$>	= 1
				
			CASE First = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'F'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
			CASE Last = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'L'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
		END CASE	
		
		
		OtParms = 'PRS_PROP':@RM:PRSPropKey:@RM:@RM:PRSRec
		obj_Tables('WriteRec',OtParms)
		
	END	;* End of Thickness Property
	
	IF LayerSpec<PRS_LAYER_RES_MIN$> NE '' OR LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MTOOL$> NE '' THEN
		
		Prop = ''
		
		IF LayerSpec<PRS_LAYER_RES_UNITS$> = UNIT$RES THEN
			Prop = 'RES'
		END
		
		IF LayerSpec<PRS_LAYER_RES_UNITS$> = UNIT$SRES THEN
			Prop = 'SRES'
		END
		
		
		IF Prop NE '' THEN
			
			PRSPropKey = PSNo:'*':LayerNo:'*':Prop
			
			LOCATE PRSPropKey IN OrgPRSPropKeys USING @VM SETTING Pos THEN
				OrgPRSPropKeys = DELETE(OrgPRSPropKeys,1,Pos,0)
			END
			
			PRSRec = ''
			
			*PRSRec<PRS_PROP_LS_ID$>				= LSID
			PRSRec<PRS_PROP_RAW_MIN$>			= ICONV(LayerSpec<PRS_LAYER_RES_MIN$>,'MD5')
			PRSRec<PRS_PROP_RAW_MAX$>			= ICONV(LayerSpec<PRS_LAYER_RES_MAX$>,'MD5')
			PRSRec<PRS_PROP_UNITS_ORG$>			= LayerSpec<PRS_LAYER_RES_UNITS$>
			PRSRec<PRS_PROP_TOOL$>				= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MTOOL$>
			PRSRec<PRS_PROP_MET_WFR_TYPE$>		= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MTYPE$>
			PRSRec<PRS_PROP_RECIPE$>			= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MRECIPE$>
			PRSRec<PRS_PROP_FREQ$>				= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MFREQ$>
			PRSRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MPROVEIN$>
			PRSRec<PRS_PROP_FIRST$>				= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MFIRST$>
			PRSRec<PRS_PROP_LAST$>				= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MLAST$>
			PRSRec<PRS_PROP_SPC$>				= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MSPC$>
			PRSRec<PRS_PROP_OVERGROW$>			= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MOVERGROW$>
			PRSRec<PRS_PROP_EXP_TW_QTY$>		= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MEXP_TW_QTY$>
			PRSRec<PRS_PROP_PATTERN$>			= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MPATTERN$>
			PRSRec<PRS_PROP_MET_SLOT$>			= 1
			
			Freq	= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MFREQ$>
			First	= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MFIRST$>
			Last	= LayerSpec<PRS_LAYER_RES_MEASUREMENT$,PRS_PROP_MLAST$>
			
			BEGIN CASE
				CASE NUM(Freq)  AND Freq NE '' 
					
					PRSRec<PRS_PROP_MET_INTERVAL$>	= Freq
					PRSRec<PRS_PROP_MET_START$>	= 1
					
				CASE First = 1
					PRSRec<PRS_PROP_MET_INTERVAL$>		= 'F'
					PRSRec<PRS_PROP_MET_START$>	= ''
					
				CASE Last = 1
					PRSRec<PRS_PROP_MET_INTERVAL$>		= 'L'
					PRSRec<PRS_PROP_MET_START$>	= ''
					
			END CASE
			
			OtParms = 'PRS_PROP':@RM:PRSPropKey:@RM:@RM:PRSRec
			obj_Tables('WriteRec',OtParms)
		END ELSE
			
			Send_Dyn("PSN: ":PSNo:" Prop: ":Prop:" Units: ":LayerSpec<PRS_LAYER_RES_UNITS$>)
			
		END
		
	END	;* End of Resistivity Property
	
	IF LayerSpec<PRS_LAYER_CRES_MIN$> NE '' OR LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MTOOL$> NE '' THEN
		
		PRSPropKey = PSNo:'*':LayerNo:'*CRES'
		
		LOCATE PRSPropKey IN OrgPRSPropKeys USING @VM SETTING Pos THEN
			OrgPRSPropKeys = DELETE(OrgPRSPropKeys,1,Pos,0)
		END
		
		PRSRec = ''
		
		*PRSRec<PRS_PROP_LS_ID$>				= LSID
		PRSRec<PRS_PROP_RAW_MIN$>			= ICONV(LayerSpec<PRS_LAYER_CRES_MIN$>,'MD5')
		PRSRec<PRS_PROP_RAW_MAX$>			= ICONV(LayerSpec<PRS_LAYER_CRES_MAX$>,'MD5')
		PRSRec<PRS_PROP_UNITS_ORG$>			= LayerSpec<PRS_LAYER_CRES_UNITS$>
		PRSRec<PRS_PROP_PHASE_MIN$>         = LayerSpec<PRS_LAYER_CRES_PHASE_MIN$>
		PRSRec<PRS_PROP_TOOL$>				= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MTOOL$>
		PRSRec<PRS_PROP_MET_WFR_TYPE$>		= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MTYPE$>
		PRSRec<PRS_PROP_RECIPE$>			= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MRECIPE$>
		PRSRec<PRS_PROP_FREQ$>				= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MFREQ$>
		PRSRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MPROVEIN$>
		PRSRec<PRS_PROP_FIRST$>				= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MFIRST$>
		PRSRec<PRS_PROP_LAST$>				= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MLAST$>
		PRSRec<PRS_PROP_SPC$>				= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MSPC$>
		PRSRec<PRS_PROP_OVERGROW$>			= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MOVERGROW$>
		PRSRec<PRS_PROP_EXP_TW_QTY$>		= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MEXP_TW_QTY$>
		PRSRec<PRS_PROP_PATTERN$>			= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MPATTERN$>
		PRSRec<PRS_PROP_MET_SLOT$>			= 1
		
		Freq	= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MFREQ$>
		First	= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MFIRST$>
		Last	= LayerSpec<PRS_LAYER_CRES_MEASUREMENT$,PRS_PROP_MLAST$>
		
		BEGIN CASE
			CASE NUM(Freq)  AND Freq NE '' 
				
				PRSRec<PRS_PROP_MET_INTERVAL$>	= Freq
				PRSRec<PRS_PROP_MET_START$>	= 1
				
			CASE First = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'F'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
			CASE Last = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'L'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
		END CASE
		
		OtParms = 'PRS_PROP':@RM:PRSPropKey:@RM:@RM:PRSRec
		obj_Tables('WriteRec',OtParms)
		
	END	;* End of HgCvResistivity Property
	
	IF LayerSpec<PRS_LAYER_CONC_MIN$> NE '' OR LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MTOOL$> NE '' THEN
		
		PRSPropKey = PSNo:'*':LayerNo:'*CONC'
		
		LOCATE PRSPropKey IN OrgPRSPropKeys USING @VM SETTING Pos THEN
			OrgPRSPropKeys = DELETE(OrgPRSPropKeys,1,Pos,0)
		END
		
		PRSRec = ''
		
		*PRSRec<PRS_PROP_LS_ID$>			= LSID
		PRSRec<PRS_PROP_RAW_MIN$>			= ICONV(LayerSpec<PRS_LAYER_CONC_MIN$>,'MS21')
		PRSRec<PRS_PROP_RAW_MAX$>			= ICONV(LayerSpec<PRS_LAYER_CONC_MAX$>,'MS21')
		PRSRec<PRS_PROP_UNITS_ORG$>			= LayerSpec<PRS_LAYER_CONC_UNITS$>
		PRSRec<PRS_PROP_TOOL$>				= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MTOOL$>
		PRSRec<PRS_PROP_MET_WFR_TYPE$>		= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MTYPE$>
		PRSRec<PRS_PROP_RECIPE$>			= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MRECIPE$>
		PRSRec<PRS_PROP_FREQ$>				= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MFREQ$>
		PRSRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MPROVEIN$>
		PRSRec<PRS_PROP_FIRST$>				= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MFIRST$>
		PRSRec<PRS_PROP_LAST$>				= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MLAST$>
		PRSRec<PRS_PROP_SPC$>				= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MSPC$>
		PRSRec<PRS_PROP_OVERGROW$>			= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MOVERGROW$>
		PRSRec<PRS_PROP_EXP_TW_QTY$>		= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MEXP_TW_QTY$>
		PRSRec<PRS_PROP_PATTERN$>			= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MPATTERN$>
		PRSRec<PRS_PROP_MET_SLOT$>			= 1
		
		Freq	= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MFREQ$>
		First	= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MFIRST$>
		Last	= LayerSpec<PRS_LAYER_CONC_MEASUREMENT$,PRS_PROP_MLAST$>
		
		BEGIN CASE
			CASE NUM(Freq)  AND Freq NE '' 
				
				PRSRec<PRS_PROP_MET_INTERVAL$>	= Freq
				PRSRec<PRS_PROP_MET_START$>	= 1
				
			CASE First = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'F'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
			CASE Last = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'L'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
		END CASE
		
		
		
		
		OtParms = 'PRS_PROP':@RM:PRSPropKey:@RM:@RM:PRSRec
		obj_Tables('WriteRec',OtParms)
		
	END	;* End of Concentration Property
	
	IF LayerSpec<PRS_LAYER_STRESS_MIN$> NE '' OR LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MTOOL$> NE '' THEN
		
		PRSPropKey = PSNo:'*':LayerNo:'*STRESS'
		
		LOCATE PRSPropKey IN OrgPRSPropKeys USING @VM SETTING Pos THEN
			OrgPRSPropKeys = DELETE(OrgPRSPropKeys,1,Pos,0)
		END
		
		SpecAddtl = XLATE('PROD_SPEC',PSNo,PROD_SPEC_SPEC_ADDTL$,'X')
		StressMeasure = SpecAddtl<1,QSAddStressMeasure$>
		
		PRSRec = ''
		
		*PRSRec<PRS_PROP_LS_ID$>			= LSID
		PRSRec<PRS_PROP_RAW_MIN$>			= ICONV(LayerSpec<PRS_LAYER_STRESS_MIN$>,'MS21')
		PRSRec<PRS_PROP_RAW_MAX$>			= ICONV(LayerSpec<PRS_LAYER_STRESS_MAX$>,'MS21')
		PRSRec<PRS_PROP_UNITS_ORG$>			= UNIT$STRESS
		PRSRec<PRS_PROP_TOOL$>				= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MTOOL$>
		PRSRec<PRS_PROP_MET_WFR_TYPE$>		= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MTYPE$>
		PRSRec<PRS_PROP_RECIPE$>			= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MRECIPE$>
		PRSRec<PRS_PROP_FREQ$>				= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MFREQ$>
		PRSRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MPROVEIN$>
		PRSRec<PRS_PROP_FIRST$>				= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MFIRST$>
		PRSRec<PRS_PROP_LAST$>				= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MLAST$>
		PRSRec<PRS_PROP_SPC$>				= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MSPC$>
		PRSRec<PRS_PROP_OVERGROW$>			= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MOVERGROW$>
		PRSRec<PRS_PROP_EXP_TW_QTY$>		= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MEXP_TW_QTY$>
		PRSRec<PRS_PROP_PATTERN$>			= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MPATTERN$>
		PRSRec<PRS_PROP_MET_SLOT$>			= 1
		
		Freq	= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MFREQ$>
		First	= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MFIRST$>
		Last	= LayerSpec<PRS_LAYER_STRESS_MEASUREMENT$,PRS_PROP_MLAST$>
		
		BEGIN CASE
			CASE NUM(Freq)  AND Freq NE '' 
				
				PRSRec<PRS_PROP_MET_INTERVAL$>	= Freq
				PRSRec<PRS_PROP_MET_START$>	= 1
				
			CASE First = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>	= 'F'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
			CASE Last = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'L'
				PRSRec<PRS_PROP_MET_START$>	= ''
				
		END CASE
		
		OtParms = 'PRS_PROP':@RM:PRSPropKey:@RM:@RM:PRSRec
		obj_Tables('WriteRec',OtParms)
		
	END	;* End of Stress Property
	
	IF LayerSpec<PRS_LAYER_TRANS_SPEC$> NE '' OR LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MTOOL$> NE '' THEN
		
		PRSPropKey = PSNo:'*':LayerNo:'*TRANS'
		
		LOCATE PRSPropKey IN OrgPRSPropKeys USING @VM SETTING Pos THEN
			OrgPRSPropKeys = DELETE(OrgPRSPropKeys,1,Pos,0)
		END
		
		PRSRec = ''
		
		*PRSRec<PRS_PROP_LS_ID$>			= LSID
		PRSRec<PRS_PROP_RAW_MIN$>			= ICONV(LayerSpec<PRS_LAYER_TRANS_SPEC$>,'MD0')
		*PRSRec<PRS_PROP_RAW_MAX$>			= ICONV(LayerSpec<PRS_LAYER_TRANS_MAX$>,'MD0')
		PRSRec<PRS_PROP_UNITS_ORG$>			= UNIT$TRANS
		PRSRec<PRS_PROP_TOOL$>				= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MTOOL$>
		PRSRec<PRS_PROP_MET_WFR_TYPE$>		= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MTYPE$>
		PRSRec<PRS_PROP_RECIPE$>			= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MRECIPE$>
		PRSRec<PRS_PROP_FREQ$>				= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MFREQ$>
		PRSRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MPROVEIN$>
		PRSRec<PRS_PROP_FIRST$>				= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MFIRST$>
		PRSRec<PRS_PROP_LAST$>				= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MLAST$>
		PRSRec<PRS_PROP_SPC$>				= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MSPC$>
		PRSRec<PRS_PROP_OVERGROW$>			= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MOVERGROW$>
		PRSRec<PRS_PROP_EXP_TW_QTY$>		= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MEXP_TW_QTY$>
		PRSRec<PRS_PROP_PATTERN$>			= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MPATTERN$>
		PRSRec<PRS_PROP_MET_SLOT$>			= 1
		
		Freq	= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MFREQ$>
		First	= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MFIRST$>
		Last	= LayerSpec<PRS_LAYER_TRANS_MEASUREMENT$,PRS_PROP_MLAST$>
		
		BEGIN CASE
			CASE NUM(Freq)  AND Freq NE '' 
				
				PRSRec<PRS_PROP_MET_INTERVAL$>		= Freq
				PRSRec<PRS_PROP_MET_START$>			= 1
				
			CASE First = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'F'
				PRSRec<PRS_PROP_MET_START$>			= ''
				
			CASE Last = 1
				PRSRec<PRS_PROP_MET_INTERVAL$>		= 'L'
				PRSRec<PRS_PROP_MET_START$>			= ''
				
		END CASE
		
		OtParms = 'PRS_PROP':@RM:PRSPropKey:@RM:@RM:PRSRec
		obj_Tables('WriteRec',OtParms)
		
	END	;* End of Resistivity Property
	
	* Where is the BOW property coming from????????
	
NEXT N


IF OrgPRSPropKeys NE '' THEN
	
	pCnt = COUNT(OrgPRSPropKeys,@VM) + (OrgPRSPropKeys NE '')
	
	FOR I = 1 TO pCnt
		OrgPRSPropKey = OrgPRSPropKeys<1,I>
		
		IF OrgPRSPropKey NE '' THEN
			otParms = 'PRS_PROP':@RM:OrgPRSPropKey
			obj_Tables('DeleteRec',otParms)
			
			IF Get_Status(errCode) THEN
				DEBUG
			END
		END
		
	NEXT I
END

IF OrgPRSLayerKeys NE '' THEN
	
	lCnt = COUNT(OrgPRSLayerKeys,@VM) + (OrgPRSLayerKeys NE '')
	
	FOR I = 1 TO lCnt
		OrgPRSLayerKey = OrgPRSLayerKeys<1,I>
		
		IF OrgPRSLayerKey NE '' THEN
			otParms = 'PRS_LAYER':@RM:OrgPRSLayerKey
			obj_Tables('DeleteRec',otParms)
			
			IF Get_Status(errCode) THEN
				DEBUG
			END
		END
	NEXT I
	
END

* obj_PRS_Stage('Convert',PSNo)	;* Dead JCH 3/11/2013
// Flush pending index transactions
Update_Index("PRS_LAYER", "PRS_PROP_KEY", False$, True$)

RETURN


* * * * * * *
ProdVerSortKeys:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN RETURN
	
	IF PSRec<PROD_SPEC_STATUS$> NE 'A' THEN RETURN
	
	
	SubSuppBy	 = PSRec<PROD_SPEC_SPEC_SUBSTRATE$,QSSubWafersSupBy$>
	ReactType 	= OCONV(PSRec<PROD_SPEC_REACTOR_TYPE$>,'[REACT_TYPE_CONV,CODE]')
	ProdVerNo	= XLATE('PRS_PROD_VER',PSNo,1,'X')<1,1>
	
	PSNId = XLATE('PROD_VER',ProdVerNo,PROD_VER_PROC_STEP_PSN$,'X')
	
	CONVERT @VM TO '.' IN PSNId
	
	Result = ''
	
	IF SubSuppBy = 'L' THEN
		* Supplied by IR
		SubPartNos = PSRec<PROD_SPEC_SUB_PART_NUMS$>
		
		PNCnt = COUNT(SubPartNos,@VM) + (SubPartNos NE '')
		FOR I = 1 TO PNCnt
			Result<1,-1> = TRIM(SubPartNos<1,I>):'*':ReactType:'*':PSNId:'*'
		NEXT I
		
	END ELSE
		* Customer Supplied
		CustPartNos = PSRec<PROD_SPEC_CUST_PART_NO$>
		
		PNCnt = COUNT(CustPartNos,@VM) + (CustPartNos NE '')
		
		FOR I = 1 TO PNCnt
			Result<1,-1> = '*':ReactType:'*':PSNId:'*':TRIM(CustPartNos<1,I>)
		NEXT I
		
	END
	
RETURN


* * * * * * *
StageSortKeys:
* * * * * * *
	
	IF NOT(Assigned(PSNo)) THEN
		PSNo	= Parms[1,@RM]
		PSRec	= Parms[COL2()+1,@RM]
	END
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN RETURN
	
	StageKeys = PSRec<PROD_SPEC_PRS_STAGE_KEY$>
	
	AllStages = obj_Popup('AllCodes','STAGE')
	
	SortedKeys = ''
	
	skCnt = COUNT(StageKeys,@VM) + (StageKeys NE '')
	
	FOR I = 1 TO skCnt
		StageKey = StageKeys<1,I>
		Stage = FIELD(StageKey,'*',2)
		LOCATE Stage IN AllStages USING @VM SETTING Pos THEN
			SortedKeys<1,Pos> = StageKey
		END
	NEXT I
	
	CONVERT @VM TO ' ' IN SortedKeys
	
	SortedKeys = TRIM(SortedKeys)
	
	CONVERT ' ' TO @VM IN SortedKeys
	
	Result = SortedKeys
	
RETURN


* * * * * * *
CEPSortKeys:
* * * * * * *
	
	PSNo	= Parms[1,@RM]
	PSRec	= Parms[COL2()+1,@RM]
	
	IF PSNo = '' THEN RETURN
	
	IF PSRec = '' THEN
		PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	END
	
	IF PSRec = '' THEN RETURN
	
	ProdVerKeys = XLATE('PRS_PROD_VER',PSNo,1,'X')
	
	CustNos		= XLATE('PROD_VER',ProdVerKeys,PROD_VER_CUST_NO$,'X')
	EpiParts	= XLATE('PROD_VER',ProdVerKeys,PROD_VER_EPI_PART_NO$,'X')
	
	CEPKeys = ''
	
	CustCnt = COUNT(CustNos,@VM) + (CustNos NE '')
	
	FOR I = 1 TO CustCnt
		CEPKey = CustNos<1,I>:'*':EpiParts<1,I>
		
		LOCATE CEPKey IN CEPKeys USING @VM SETTING Pos ELSE
			CEPKeys = INSERT(CEPKeys,1,Pos,0,CEPKey)
		END
	NEXT I
	
	Result = CEPKeys
	
RETURN


* * * * * * *
Duplicate:
* * * * * * * 
	
	PSNo = Parms[1,@RM]
	
	PSRec = XLATE('PROD_SPEC',PSNo,'','X')
	
	* * *  Build New PROD_SPEC record from original   * * *
	
	NewRec = ''
	NewRec<PROD_SPEC_ENTRY_ID$>				= @USER4
	NewRec<PROD_SPEC_ENTRY_DATE$>			= Date()
	NewRec<PROD_SPEC_SPEC_INST$>			= PSRec<PROD_SPEC_SPEC_INST$>
	NewRec<PROD_SPEC_PROVEIN_MIN$>			= PSRec<PROD_SPEC_PROVEIN_MIN$>
	NewRec<PROD_SPEC_QUAL_REACTS$>			= PSRec<PROD_SPEC_QUAL_REACTS$>
	NewRec<PROD_SPEC_PROVE_IN_INST$>		= PSRec<PROD_SPEC_PROVE_IN_INST$>
	NewRec<PROD_SPEC_RECIPE_TYPE$>			= PSRec<PROD_SPEC_RECIPE_TYPE$>
	NewRec<PROD_SPEC_REACTOR_TYPE$>			= PSRec<PROD_SPEC_REACTOR_TYPE$>
	NewRec<PROD_SPEC_WAND_RESTRICTER$>		= PSRec<PROD_SPEC_WAND_RESTRICTER$>
	NewRec<PROD_SPEC_RATIOS$>				= PSRec<PROD_SPEC_RATIOS$ >
	NewRec<PROD_SPEC_TUBE_PRESSURE_TYPE$>	= PSRec<PROD_SPEC_TUBE_PRESSURE_TYPE$>
	NewRec<PROD_SPEC_MINUTES_PER_WAFER$>	= PSRec<PROD_SPEC_MINUTES_PER_WAFER$>
	NewRec<PROD_SPEC_LW_RHO_MIN$>			= PSRec<PROD_SPEC_LW_RHO_MIN$>
	NewRec<PROD_SPEC_LW_RHO_MAX$>			= PSRec<PROD_SPEC_LW_RHO_MAX$>
	NewRec<PROD_SPEC_SUSCEPTOR_TYPE$>		= PSRec<PROD_SPEC_SUSCEPTOR_TYPE$>
	NewRec<PROD_SPEC_BLOCKED_REACTS$>		= PSRec<PROD_SPEC_BLOCKED_REACTS$>
	NewRec<PROD_SPEC_VERIFY_INSP_REQ$>		= PSRec<PROD_SPEC_VERIFY_INSP_REQ$>
	NewRec<PROD_SPEC_PI_PARTICLE_QUAL$>		= PSRec<PROD_SPEC_PI_PARTICLE_QUAL$>
	NewRec<PROD_SPEC_THICKFILM_MET$>		= PSRec<PROD_SPEC_THICKFILM_MET$>
	NewRec<PROD_SPEC_TEST_POINT_MAP$>		= PSRec<PROD_SPEC_TEST_POINT_MAP$>
	NewRec<PROD_SPEC_SMALL_REACTOR_DELTA$>	= PSRec<PROD_SPEC_SMALL_REACTOR_DELTA$>
	NewRec<PROD_SPEC_DEP_TIME_RATIO$>		= PSRec<PROD_SPEC_DEP_TIME_RATIO$>
	NewRec<PROD_SPEC_MET_TEST$>				= PSRec<PROD_SPEC_MET_TEST$>
	NewRec<PROD_SPEC_MET_INTERVAL$>			= PSRec<PROD_SPEC_MET_INTERVAL$>
	NewRec<PROD_SPEC_MET_START$>			= PSRec<PROD_SPEC_MET_START$>	
	NewRec<PROD_SPEC_MET_SLOT$>				= PSRec<PROD_SPEC_MET_SLOT$>
	NewRec<PROD_SPEC_MET_RUN_STEP$>			= PSRec<PROD_SPEC_MET_RUN_STEP$>
	NewRec<PROD_SPEC_MET_MIN$>				= PSRec<PROD_SPEC_MET_MIN$>
	NewRec<PROD_SPEC_MET_MAX$>				= PSRec<PROD_SPEC_MET_MAX$>
	NewRec<PROD_SPEC_MODE_CODE$>			= PSRec<PROD_SPEC_MODE_CODE$>
	
	NewPSNo = '9999'
	
	*NewPSNo = NextKey('PROD_SPEC')
	
	otParms = 'PROD_SPEC':@RM:NewPSNo:@RM:@RM:NewRec
	obj_Tables('WriteRec',otParms)
	
	IF Get_Status(errCode) THEN RETURN   ;***** Check for error in the commuter that called this
	
	PRSLayerKeys	= PSRec<PROD_SPEC_PRS_LAYER_KEY$>
	PRSStageKeys	= PSRec<PROD_SPEC_PRS_STAGE_KEY$>
	
	NewPRSLayerKeys = PRSLayerKeys
	
	SWAP PSNo WITH NewPSNo IN NewPRSLayerKeys
	
	lCnt = COUNT(NewPRSLayerKeys,@VM) + (NewPRSLayerKeys NE '')
	
	FOR I = 1 TO lCnt
		
		PRSLayerKey		= PRSLayerKeys<1,I>
		NewPRSLayerKey	= NewPRSLayerKeys<1,I>
		
		PRSLayerRec = XLATE('PRS_LAYER',PRSLayerKey,'','X')
		
		NewLayerRec = ''
		NewLayerRec<PRS_LAYER_LS_ID$>		= PRSLayerRec<PRS_LAYER_LS_ID$>
		NewLayerRec<PRS_LAYER_LAYER_TYPE$>	= PRSLayerRec<PRS_LAYER_LAYER_TYPE$>
		NewLayerRec<PRS_LAYER_RECIPE_ID$>	= PRSLayerRec<PRS_LAYER_RECIPE_ID$>
		
		otParms = 'PRS_LAYER':@RM:NewPRSLayerKey:@RM:@RM:NewLayerRec
		
		obj_Tables('WriteRec',otParms)
		IF Get_Status(errCode) THEN RETURN
		
		PRSPropKeys = PRSLayerRec<PRS_LAYER_PRS_PROP_KEY$>
		
		NewPRSPropKeys = PRSPropKeys
		
		SWAP PSNo WITH NewPSNo IN NewPRSPropKeys
		
		pCnt = COUNT(NewPRSPropKeys,@VM) + (NewPRSPropKeys NE '')
		
		FOR N = 1 TO PCnt
			
			PRSPropKey		= PRSPropKeys<1,N>
			NewPRSPropKEy	= NewPRSPropKeys<1,N>
			
			PRSPropRec = XLATE('PRS_PROP',PRSPropKey, '','X')
			
			NewPropRec = ''
			NewPropRec<PRS_PROP_TOOL$>				= PRSPropRec<PRS_PROP_TOOL$>
			NewPropRec<PRS_PROP_MET_WFR_TYPE$>		= PRSPropRec<PRS_PROP_MET_WFR_TYPE$>
			NewPropRec<PRS_PROP_RECIPE$>			= PRSPropRec<PRS_PROP_RECIPE$>
			NewPropRec<PRS_PROP_FREQ$>				= PRSPropRec<PRS_PROP_FREQ$>
			NewPropRec<PRS_PROP_PROVEIN_WFR_TYPE$>	= PRSPropRec<PRS_PROP_PROVEIN_WFR_TYPE$>
			NewPropRec<PRS_PROP_FIRST$>				= PRSPropRec<PRS_PROP_FIRST$>
			NewPropRec<PRS_PROP_LAST$>				= PRSPropRec<PRS_PROP_LAST$>
			NewPropRec<PRS_PROP_SPC$>				= PRSPropRec<PRS_PROP_SPC$>
			NewPropRec<PRS_PROP_OVERGROW$>			= PRSPropRec<PRS_PROP_OVERGROW$>
			NewPropRec<PRS_PROP_EXP_TW_QTY$>		= PRSPropRec<PRS_PROP_EXP_TW_QTY$>
			NewPropRec<PRS_PROP_PATTERN$>			= PRSPropRec<PRS_PROP_PATTERN$>
			
			otParms = 'PRS_PROP':@RM:NewPRSPropKey:@RM:@RM:NewPropRec
			
			obj_Tables('WriteRec',otParms)
			IF Get_Status(errCode) THEN RETURN
			
		NEXT N
		
	NEXT I
	
	
	NewPRSStageKeys = PRSStageKeys
	
	SWAP PSNo WITH NewPSNo IN NewPRSStageKeys
	
	sCnt = COUNT(NewPRSStageKeys,@VM) + (NewPRSStageKeys NE '')
	
	
	FOR I = 1 TO sCnt
		PRSStageKey		= PRSStageKeys<1,I>
		NewPRSStageKey	= NewPRSStageKeys<1,I>
		
		PRSStageRec = XLATE('PRS_STAGE',PRSStageKey,'','X')
		
		NewStageRec = ''
		
		NewStageRec<PRS_STAGE_INST$>				= PRSStageRec<PRS_STAGE_INST$>
		NewStageRec<PRS_STAGE_BRIGHTLIGHT$>			= PRSStageRec<PRS_STAGE_BRIGHTLIGHT$>
		NewStageRec<PRS_STAGE_MICROSCOPE$>			= PRSStageRec<PRS_STAGE_MICROSCOPE$>
		NewStageRec<PRS_STAGE_SURFSCAN_SIG_REQ$>	= PRSStageRec<PRS_STAGE_SURFSCAN_SIG_REQ$>
		NewStageRec<PRS_STAGE_SURFSCAN_RECIPE$>		= PRSStageRec<PRS_STAGE_SURFSCAN_RECIPE$>
		NewStageRec<PRS_STAGE_CLEAN_TOOL$ >			= PRSStageRec<PRS_STAGE_CLEAN_TOOL$ >
		NewStageRec<PRS_STAGE_CLEAN_RECIPE$>		= PRSStageRec<PRS_STAGE_CLEAN_RECIPE$>
		NewStageRec<PRS_STAGE_SURF_HAZE$>			= PRSStageRec<PRS_STAGE_SURF_HAZE$>
		NewStageRec<PRS_STAGE_SURF_DEFECTS$>		= PRSStageRec<PRS_STAGE_SURF_DEFECTS$>
		NewStageRec<PRS_STAGE_PITS$>				= PRSStageRec<PRS_STAGE_PITS$>
		NewStageRec<PRS_STAGE_MOUNDS$>				= PRSStageRec<PRS_STAGE_MOUNDS$>
		NewStageRec<PRS_STAGE_BL_DEFECTS$>			= PRSStageRec<PRS_STAGE_BL_DEFECTS$>
		NewStageRec<PRS_STAGE_SPOTS$>				= PRSStageRec<PRS_STAGE_SPOTS$>
		NewStageRec<PRS_STAGE_FOV$>					= PRSStageRec<PRS_STAGE_FOV$>
		NewStageRec<PRS_STAGE_SCRATCHES$>			= PRSStageRec<PRS_STAGE_SCRATCHES$>
		NewStageRec<PRS_STAGE_SCRATCH_LEN$>			= PRSStageRec<PRS_STAGE_SCRATCH_LEN$>
		NewStageRec<PRS_STAGE_LPD$>					= PRSStageRec<PRS_STAGE_LPD$>
		NewStageRec<PRS_STAGE_STACK_FAULTS$>		= PRSStageRec<PRS_STAGE_STACK_FAULTS$>
		NewStageRec<PRS_STAGE_SPIKES$>				= PRSStageRec<PRS_STAGE_SPIKES$>
		NewStageRec<PRS_STAGE_FWI_LWI$>				= PRSStageRec<PRS_STAGE_FWI_LWI$>
		NewStageRec<PRS_STAGE_SS_SAMP_QTY$>			= PRSStageRec<PRS_STAGE_SS_SAMP_QTY$>
		NewStageRec<PRS_STAGE_CLEAN_SIG_REQ$>		= PRSStageRec<PRS_STAGE_CLEAN_SIG_REQ$>
		NewStageRec<PRS_STAGE_INSP_SIG_REQ$>		= PRSStageRec<PRS_STAGE_INSP_SIG_REQ$>
		
		otParms = 'PRS_STAGE':@RM:NewPRSStageKey:@RM:@RM:NewStageRec
		obj_Tables('WriteRec',otParms)
		IF Get_Status(errCode) THEN RETURN
		
	NEXT I
	
RETURN


* * * * * * *
GetQAMet:
* * * * * * *
	
	PSNo			= Parms[1,@RM]
	PSRec			= Parms[COL2()+1,@RM]
	ReactSchedFlag	= Parms[COL2()+1,@RM]
	
	GOSUB StageSortKeys
	
	PSStageKeys = Result
	Result = ''
	
	pssCnt 		= COUNT(PSStageKeys,@VM) + (PSStageKeys NE '')
	ResLineCnt	= 0
	
	FOR N = 1 TO pssCnt
		PSStageKey = PSStageKeys<1,N>
		PSStageRec = XLATE('PRS_STAGE',PSStageKey,'','X')
		
		MetCnt = COUNT(PSStageRec<PRS_STAGE_MET_TEST$>,@VM) + (PSStageRec<PRS_STAGE_MET_TEST$> NE '')
		
		FOR TestNo = 1 TO MetCnt
			
			IF PSStageRec<PRS_STAGE_MET_TEST$,TestNo> NE '' THEN
				
				IF ReactSchedFlag = 1 THEN
					
					IF PSStageRec<PRS_STAGE_MET_REACT_SCHED$,TestNo> = 1 THEN
						
						ResLineCnt += 1
						Result<COL$QA_MET_STAGE,ResLineCnt>				= FIELD(PSStageKey,'*',2)
						Result<COL$QA_MET_TEST,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_TEST$,TestNo>
						Result<COL$QA_MET_PROP,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_PROP$,TestNo>
						Result<COL$QA_MET_TOOL_CLASS,ResLineCnt>		= PSStageRec<PRS_STAGE_MET_TOOL_CLASS$,TestNo>
						Result<COL$QA_MET_RECIPE,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_RECIPE$,TestNo>
						Result<COL$QA_MET_RECIPE_PATTERN,ResLineCnt>	= PSStageRec<PRS_STAGE_MET_RECIPE_PATTERN$,TestNo>
						Result<COL$QA_MET_MIN,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_MIN$,TestNo>
						Result<COL$QA_MET_MAX,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_MAX$,TestNo>
						Result<COL$QA_MET_SLOT,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_SLOT$,TestNo>
						Result<COL$QA_MET_REACT_SCHED,ResLineCnt>		= PSStageRec<PRS_STAGE_MET_REACT_SCHED$,TestNo>
						Result<COL$QA_MET_INTERVAL,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_INTERVAL$,TestNo>
						Result<COL$QA_MET_START,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_START$,TestNo>
						Result<COL$QA_MET_WFR_QTY,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_WFR_QTY$,TestNo>
						Result<COL$QA_MET_WFR_TYPE,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_WFR_TYPE$,TestNo>	;* Possible Future
						Result<COL$QA_MET_SHIP_DOC,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_SHIP_DOC$,TestNo>	;* 12/3/2016 JCH for Mark
						Result<COL$QA_MET_PHASE_MIN,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_PHASE_MIN$,TestNo>
						
					END
					
				END ELSE
					
					ResLineCnt += 1
					Result<COL$QA_MET_STAGE,ResLineCnt>				= FIELD(PSStageKey,'*',2)
					Result<COL$QA_MET_TEST,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_TEST$,TestNo>
					Result<COL$QA_MET_PROP,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_PROP$,TestNo>
					Result<COL$QA_MET_TOOL_CLASS,ResLineCnt>		= PSStageRec<PRS_STAGE_MET_TOOL_CLASS$,TestNo>
					Result<COL$QA_MET_RECIPE,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_RECIPE$,TestNo>
					Result<COL$QA_MET_RECIPE_PATTERN,ResLineCnt>	= PSStageRec<PRS_STAGE_MET_RECIPE_PATTERN$,TestNo>
					Result<COL$QA_MET_MIN,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_MIN$,TestNo>
					Result<COL$QA_MET_MAX,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_MAX$,TestNo>
					Result<COL$QA_MET_SLOT,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_SLOT$,TestNo>
					Result<COL$QA_MET_REACT_SCHED,ResLineCnt>		= PSStageRec<PRS_STAGE_MET_REACT_SCHED$,TestNo>
					Result<COL$QA_MET_INTERVAL,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_INTERVAL$,TestNo>
					Result<COL$QA_MET_START,ResLineCnt>				= PSStageRec<PRS_STAGE_MET_START$,TestNo>
					Result<COL$QA_MET_WFR_QTY,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_WFR_QTY$,TestNo>
					Result<COL$QA_MET_WFR_TYPE,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_WFR_TYPE$,TestNo>		;* Possible future
					Result<COL$QA_MET_SHIP_DOC,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_SHIP_DOC$,TestNo>		;* 12/3/2016 JCH for Mark
					Result<COL$QA_MET_PHASE_MIN,ResLineCnt>			= PSStageRec<PRS_STAGE_MET_PHASE_MIN$,TestNo>
					
				END	;* End of check for ReactSchedFlag
			END
		NEXT TestNo
	NEXT N
	
RETURN



