COMPILE SUBROUTINE Print_Coc_Back( PrintRDSNos, WMOutKeys, Prelim, EmailAddresses, PrintOnly, ShipDt, HideUI, ShipNo)
#pragma precomp SRP_PreCompiler

DECLARE FUNCTION FieldCount, Msg, Key_Sort, Set_Printer, obj_RDS
DECLARE FUNCTION Calc_WO_Stats, Get_Printer, obj_NCR, obj_WO_Mat_QA, Database_Services

DECLARE SUBROUTINE Btree.Extract

$INSERT COMPANY_EQU
$INSERT COC_EQU
$INSERT EMAIL_PENDING_EQU
$INSERT LOGICAL
$INSERT LSL_USERS_EQU
$INSERT MSG_EQUATES
$INSERT POPUP_EQUATES
$INSERT RDS_EQUATES
$INSERT RDS_LAYER_INFO_EQU
$INSERT RDS_LAYER_EQUATES
$INSERT RDS_TEST_EQUATES
$INSERT NCR_EQU
$INSERT QUOTE_EQU
$INSERT QUOTE_SPEC_EQU
$INSERT OIPRINT_EQUATES
$INSERT SCHEDULE_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT PROD_SPEC_EQUATES
$INSERT CUST_EPI_PART_EQUATES

$INSERT SRP_COC_RESULTS_EQU
$INSERT WO_LOG_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT WO_STEP_EQU
$INSERT WM_OUT_EQUATES
$INSERT APPCOLORS


EQU FONT_NAME$		TO 1
EQU FONT_SIZE$		TO 2
EQU FONT_JUST$		TO 3
EQU FONT_BOLD$		TO 4
EQU FONT_ITALIC$	TO 5
EQU FONT_UNDERLINE$	TO 6

* 	This is the ID code number FOR first wafer inspection out of the tw_codes table

EQU FirstWaferInspection$ TO 5

IF NOT(ASSIGNED(ShipDt)) THEN ShipDt = ''

Margins			= Get_Printer('MARGIN')
TopMargin		= Margins<2>
BottomMargin	= Margins<4>

PrintableHeight = Get_Printer('PAGESIZE')<2> - TopMargin - BottomMargin

If Assigned(HideUI) else HideUI = False$
If HideUI NE True$ then HideUI = False$

RDSNos = PrintRDSNos

WOStepKey = FIELD(WMOutKeys<1,1>,'*',1,2)
WONo = WOStepKey[1,'*']
WORec = XLATE('WO_LOG',WONo,'','X')

ProdOrdNo = XLATE('WO_LOG',WONo,WO_LOG_PROD_ORD_NO$,'X')

PSNo		= XLATE('WO_STEP',WOStepKey,WO_STEP_PROD_SPEC_ID$,'X')
Dopant		= XLATE('PROD_SPEC',PSNo,'DOPANT_L1','X' )
SuppliedBy	= XLATE('PROD_SPEC',PSNo,'SUB_SUPPLIED_BY','X' )

* * *  11/19/2015 JCH - Changed to get Spec data from Cust_Epi_Part table * * * * *

CustNo    = Xlate('COC', Shipno, 'WO_CUST_NO_EX', 'X')
EpiPartNo = Xlate('COC', ShipNo, 'EPI_PART_NO_EX', 'X')

CustEpiPartRec	= Xlate('CUST_EPI_PART',CustNo:'*':EpiPartNo,'','X')

CustSpecIDs		= CustEpiPartRec<CUST_EPI_PART_SPEC_NO$>
CustSpecRevs	= CustEpiPartRec<CUST_EPI_PART_SPEC_REV$>
CustSpecRevDts	= CustEpiPartRec<CUST_EPI_PART_SPEC_REV_DT$>

CustSpecRevDts = Oconv(CustSpecRevDts,'D4/')


SWAP @VM WITH CRLF$ IN CustSpecIDs
SWAP @VM WITH CRLF$ IN CustSpecRevs
SWAP @VM WITH CRLF$ IN CustSpecRevDts

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

IF RDSNos<1,1> = '' THEN
	RDSNos = ''
	RDSLotNos = ''
	RDSLotCnts = ''
	
	AllRDSNos = XLATE('WM_OUT',WMOutKeys,WM_OUT_RDS$,'X')
	AllCassNos = XLATE('WM_OUT',WMOutKeys,WM_OUT_IN_CASS_NO$,'X')
	
	FOR I = 1 TO COUNT(AllRDSNos,@VM) + (AllRDSNos NE '')
	
		AllRDSNo = AllRDSNos<1,I>
		
		IF AllRDSNo NE '' THEN
			LOCATE AllRDSNo IN RDSNos USING @VM SETTING Pos ELSE
				RDSNos = INSERT(RDSNos,1,-1,0,AllRDSNo)
				RDSLotNos = INSERT(RDSLotNos,1,-1,0,'')
				RDSLotCnts = INSERT(RDSLotCnts,1,-1,0,'')
			END
			
			AllCassNo = AllCassNos<1,I>
			
			LotNo = XLATE('WO_MAT',WONo:'*':AllCassNo,WO_MAT_LOT_NO$,'X')
			
			LOCATE LotNo IN RDSLotNos<1,Pos> USING @SVM SETTING LPos THEN
				RDSLotCnts<1,Pos,LPos> = RDSLotCnts<1,Pos,LPos> + 1
			END ELSE
				RDSLotNos = INSERT(RDSLotNos,1,Pos,LPos,LotNo)
				RDSLotCnts = INSERT(RDSLotCnts,1,Pos,LPos,1)
			END
		
		END
	NEXT I
	
	PrintRDSLotCnts = RDSLotCnts
	
	SWAP @SVM WITH CRLF$ IN RDSLotNos
	SWAP @SVM WITH CRLF$ IN PrintRDSLotCnts
END ELSE
	RDSLotNos = XLATE('RDS',RDSNos,RDS_LOT_NUM$,'X')
	RDSLotCnts = XLATE('RDS',RDSNos,'WFRS_OUT','X')
	PrintRDSLotCnts = RDSLotCnts
END


FirstRDSNo		= RDSNos<1,1>
FirstRDSRec		= XLATE( 'RDS',FirstRDSNo , '', 'X' )

Font = 'Arial'
Font<FONT_SIZE$>	= '18'		;* Big type
Font<FONT_BOLD$>	= 1			;* Bold on
Font<FONT_ITALIC$>	= 1			;* Italics

IF Prelim THEN
	stat = Set_Printer('TEXTXY','Preliminary Wafer Shipment List',1.4:@FM:-0.80,Font,0)			;* This branch is obsolete JCH 12/8/2015
END ELSE
    stat = Set_Printer('TEXTXY','Certificate of Compliance',2.1:@FM:-0.80,Font,0)
END

Font<FONT_NAME$>	= 'Courier New'		;* Basic font
Font<FONT_SIZE$>	= 9
Font<FONT_JUST$>	= 'L'
Font<FONT_BOLD$>	= 0
Font<FONT_ITALIC$>	= 0

TFont				= Font
TFont<FONT_SIZE$>	= 12
                  
Void = Set_Printer( 'FONT', TFont )


TextOut = 'Customer: ':OCONV( FirstRDSRec<RDS_CUST_NO$>, '[XLATE_CONV,COMPANY*CO_NAME]' )
Void = Set_Printer( 'TEXT', TextOut )
stat = Set_Printer('TEXT')				;* Blank Line

IF ShipDt = '' THEN	ShipDt = OCONV( DATE(), 'D4/' )

WOStepKeys = WORec<WO_LOG_WO_STEP_KEY$>

IF INDEX(WOStepKeys,@VM,1) THEN
	WOStepKey = FirstRDSRec<RDS_WO_STEP_KEY$>
	WONo = WOStepKey
	CONVERT '*' TO '.' IN WONo
END

* Common Information from First RDS record
	
colHeader = 'PO Number'						; colFormat = '^2880'
colHeader<1,2> = 'WO Number'				; colFormat<1,2> = '^2880'
colHeader<1,3> = 'Manufacturing Quote'		; colFormat<1,3> = '^2880'
colHeader<1,4> = 'Date'						; colFormat<1,4> = '^2160'

colData = FirstRdsRec<RDS_PO$>
colData<1,2> = WONo
colData<1,3> = FirstRDSRec<RDS_QUOTE_NO$>
colData<1,4> = ShipDt


IF ProdOrdNo NE '' THEN
	colHeader<1,3> = 'Prod Order No'
	colData<1,3> = ProdOrdNo
END


font<FONT_SIZE$> = 10		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,6)

font<FONT_BOLD$> = 0		;* Bold off
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,6)

stat = Set_Printer('TEXT')


* Specification information *

colHeader = 'Spec No'					; colFormat = '^2700'			; colData = PSNo
colHeader<1,2> = 'Cust Spec'			; colFormat<1,2> = '^2700'		; colData<1,2> = CustSpecIDs
colHeader<1,3> = 'Cust Spec Rev'		; colFormat<1,3> = '^2700'		; colData<1,3> = CustSpecRevs
colHeader<1,4> = 'Cust Spec Rev Dt'		; colFormat<1,4> = '^2700'		; colData<1,4> = CustSpecRevDts

font<FONT_SIZE$> = 10		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,6)

font<FONT_BOLD$> = 0		;* Bold off
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,6)

stat = Set_Printer('TEXT')


* Layer Targets *

colHeader = 'Layer':@VM						; colFormat = '^1080':@VM
colHeader<1,2> = 'Dopant':@VM				; colFormat<1,2> = '^1980':@VM
colHeader<1,3> = 'Measure':@VM				; colFormat<1,3> = '<1800':@VM
colHeader<1,4> = 'Minimum':@VM				; colFormat<1,4> = '^1980':@VM
colHeader<1,5> = 'Target':@VM				; colFormat<1,5> = '^1980':@VM
colHeader<1,6> = 'Maximum'					; colFormat<1,6> = '^1980'

SortedLSKeys = XLATE('RDS',FirstRDSNo,'RDS_LS_SORTED','X')
LayerCnt = COUNT(SortedLSKeys,@VM) + (SortedLSKeys NE '')

colData = ''
FOR I = 1 TO LayerCnt
	LSKey 			= SortedLSKeys<1,I>
	LayerRec		= XLATE('RDS_LAYER',LSKey,'','X')
	FirstTestKey	= LayerRec<RDS_LAYER_RDS_TEST_KEYS$,1>
	TestRec			= XLATE('RDS_TEST',FirstTestKey,'','X')
	
	Dopant		= LayerRec<RDS_LAYER_DOPANT$>
	ThickMin	= TestRec<RDS_TEST_SPEC_THICK_MIN$>
	ThickTarget = TestRec<RDS_TEST_SPEC_THICK_TARGET$>
	ThickMax	= TestRec<RDS_TEST_SPEC_THICK_MAX$>
	ThickUnits	= TestRec<RDS_TEST_SPEC_THICK_UNITS$>
	
	ResMin		= TestRec<RDS_TEST_SPEC_RES_MIN$>
	ResTarget	= TestRec<RDS_TEST_SPEC_RES_TARGET$>
	ResMax		= TestRec<RDS_TEST_SPEC_RES_MAX$>
	ResUnits	= TestRec<RDS_TEST_SPEC_RES_UNITS$>
	
	IF I = 1 THEN FirstResUnits = ResUnits
	
	ConMin		= TestRec<RDS_TEST_SPEC_CON_MIN$>
	ConTarget	= TestRec<RDS_TEST_SPEC_CON_TARGET$>
	ConMax		= TestRec<RDS_TEST_SPEC_CON_MAX$>
	ConUnits	= TestRec<RDS_TEST_SPEC_CON_UNITS$>
	
	colData<I,1> = FIELD(LSKey,'*',2):CRLF$
	colData<I,2> = Dopant:CRLF$
	colData<I,3> = 'Thickness':CRLF$:'Resistivity'
	colData<I,4> = OCONV(ThickMin,'MD3'):ThickUnits:CRLF$:OCONV(ResMin,'MD3'):ResUnits
	colData<I,5> = OCONV(ThickTarget,'MD3'):ThickUnits:CRLF$:OCONV(ResTarget,'MD3'):ResUnits
	colData<I,6> = OCONV(ThickMax,'MD3'):ThickUnits:CRLF$:OCONV(ResMax,'MD3'):ResUnits
	
	IF ConTarget NE '' THEN
		colData<I,1> = colData<I,1>:CRLF$
		colData<I,2> = colData<I,2>:CRLF$
		colData<I,3> = colData<I,3>:CRLF$:'Concentration'
		colData<I,4> = colData<I,4>:CRLF$:OCONV(ConMin,'MS21'):ConUnits
		colData<I,5> = colData<I,5>:CRLF$:OCONV(ConTarget,'MS21'):ConUnits
		colData<I,6> = colData<I,6>:CRLF$:OCONV(ConMax,'MS21'):ConUnits
	END ELSE
		colData<I,1> = colData<I,1>:CRLF$
		colData<I,2> = colData<I,2>:CRLF$
		colData<I,3> = colData<I,3>:CRLF$
		colData<I,4> = colData<I,4>:CRLF$
		colData<I,5> = colData<I,5>:CRLF$
		colData<I,6> = colData<I,6>:CRLF$
	END

NEXT I

font<FONT_SIZE$> = 10		;* 10 point
font<FONT_BOLD$> = 1		;* Bold
stat = Set_Printer('FONT',font)

stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

TFont<FONT_NAME$> = 'MS LineDraw'
TFont<FONT_SIZE$> = 9
TFont<FONT_BOLD$> = 0
Void = Set_Printer( 'FONT', TFont )

stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)

stat = Set_Printer('TEXT')

* * *  Print and QA Met results specified to be on documents  * * *

colData		= ''
WOMatKeys 	= ''
wmoCnt		= COUNT(WMOutKeys,@VM) + (WMOutKeys NE '')

FOR I = 1 TO wmoCnt
	CassNo = WMOutKeys<1,I>[-1,'B*']
	WOMatKey = WONo:'*':CassNo
	WOMatRec = XLATE('WO_MAT',WOMatKey,'','X')
	
	colData<I,1> = XLATE('WO_MAT',WOMatKey,'CASS_ID_SAP','X')
	colData<I,2> = WOMatRec<WO_MAT_SAP_BATCH_NO$>
	colData<I,3> = WOMatRec<WO_MAT_CUST_PART_NO$>
	
	LotNos =  WOMatRec<WO_MAT_LOT_NO$>
	SWAP @VM WITH CRLF$ IN LotNos
	
	colData<I,4> = LotNos
	
	ShipQAMet = obj_WO_Mat_QA('GetShipDoc',WONo:@RM:CassNo)
	
	SWAP @VM WITH CRLF$ in ShipQAMet
	
	colData<I,5>	= ShipQAMet<1>	;* QA Props
	colData<I,6>	= ShipQAMet<2>	;* QAMins
	colData<I,7>	= ShipQAMet<3>	;* QAMaxs
	colData<I,8>	= ShipQAMet<4>	;* QAResults
	
NEXT I

testString = colData<1,5>
CONVERT @VM TO '' IN testString

IF testString NE '' THEN

	* QA Metrology *
	
	colHeader 		= 'Cass ID'				; colFormat = '^1080'
	colHeader<1,2>	= 'Batch No'			; colFormat<1,2> = '^1440'
	colHeader<1,3>	= 'Cust Part No'		; colFormat<1,3> = '^1440'
	colHeader<1,4>	= 'Lot No'				; colFormat<1,4> = '^1440'
	colHeader<1,5>	= 'Property'			; colFormat<1,5> = '^1440'
	colHeader<1,6>	= 'Spec Min'			; colFormat<1,6> = '^1440'
	colHeader<1,7>	= 'Spec Max'			; colFormat<1,7> = '^1440'
	colHeader<1,8>	= 'Measured'			; colFormat<1,8> = '^1440'
	
	font<FONT_SIZE$> = 8		;* 10 point
	font<FONT_BOLD$> = 1		;* Bold
	stat = Set_Printer('FONT',font)

	stat = Set_Printer('ADDTABLE', colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)

	TFont<FONT_NAME$> = 'MS LineDraw'
	TFont<FONT_SIZE$> = 9
	TFont<FONT_BOLD$> = 0
	Void = Set_Printer( 'FONT', TFont )

	stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)

	stat = Set_Printer('TEXT')
END		;* End of check for QAMet specified

font<FONT_BOLD$> = 0		;* Bold off
stat = Set_Printer('FONT',font)

TFont = "Courier New,8,L,1"
CONVERT ',' TO @FM in TFont

Void = Set_Printer( 'FONT', TFont )

* * *  Print Summary of shipment metrology  * * *

RDSCnt = COUNT(RDSNos,@VM) + (RDSNos NE '')

*CustNo = FirstRdsRec<RDS_CUST_NO$>		;* Set from Cust_Epi_Part record above

IF Prelim THEN

	* This branch is obsolete 12/8/2015 JCH
	
	Void = Set_Printer( 'TEXT', Lout )
	Lout = fmt( 'PART #', 'L#12' ):' '
	Lout:= fmt( 'LOT #', 'L#14' ):' '
	Lout:= fmt( 'RUN #', 'L#9' ):' '
	Lout:= fmt( 'QTY', 'L#5' ):' '
	Lout:= fmt( 'MFG Pre Epi Rej', 'L#15' ):' '
	Lout:= fmt( 'MFG Post Epi Rej', 'L#16' ):' '
	Lout:= fmt( 'Cust Pre Epi Rej', 'L#16' ):' '
	Lout:= fmt( 'Cust Post Epi Rej', 'L#17' )
	Void = Set_Printer( 'TEXT', Lout )
	Lout = '____________ ______________ _________ _____ _______________ ________________ ________________ _________________'
	Void = Set_Printer( 'TEXT', Lout )
	QtyOut = 0
	TFont<4> = 0
	Void = Set_Printer( 'FONT', TFont )
	
	FOR I = 1 TO RDSCnt
		
	    ThisRdsRec = XLATE( 'RDS', RDSNos<1,I>, '', 'X' )
	    Lout = fmt( ThisRdsRec<RDS_PART_NUM$>, 'L#12' ):' '
	    Lout:= fmt( ThisRdsRec<RDS_LOT_NUM$>, 'L#14' ):' '
	    Lout:= fmt( ThisRdsRec<RDS_REACTOR$>:'-':LastSeplayIds<1,I>, 'L#9' ):' '
	    WafOut = obj_RDS('WafersOut',RDSNos<1,I>:@RM:ThisRdsRec)
	    Lout:= fmt( WafOut, 'R#5' ):' '
	    QtyOut += WafOut
	    Lout:= fmt( XLATE('RDS',RDSNos<1,I>,'LSL_PRE_EPI_REJ','X'), 'R#15' ):' '
	    Lout:= fmt( XLATE('RDS',RDSNos<1,I>,'LSL_POST_EPI_REJ','X'), 'R#16' ):' '
	    Lout:= fmt( XLATE('RDS',RDSNos<1,I>,'CUST_PRE_EPI_REJ','X'), 'R#16' ):' '
	    Lout:= fmt( XLATE('RDS',RDSNos<1,I>,'CUST_POST_EPI_REJ','X'), 'R#17')
	    Void = Set_Printer( 'TEXT', Lout )
	NEXT I
	
END ELSE

 	IF FirstResUnits = 'ê/Ü' THEN
		ResLabel = 'Sheet Rho'		;* ohms squared label sheetRHO
	END ELSE
		ResLabel = 'Resistivity'
	END
	
	TestMetKeys = XLATE('RDS',RDSNos<1,1>,'MET_KEYS','X')
	
	IF TestMetKeys NE '' THEN
		colHeader = 'Run No'									; colFormat = '^1080'
		colHeader<1,2> = 'Batch No'								; colFormat<1,2> = '^1080'
		colHeader<1,3> = 'Cust Part No'							; colFormat<1,3> = '^1440'
		colHeader<1,4> = 'Lot No'								; colFormat<1,4> = '^1440'
		colHeader<1,5> = 'Qty'									; colFormat<1,5> = '<720'
		colHeader<1,6> = 'Layer'								; colFormat<1,6> = '^660'
		colHeader<1,7> = 'Thickness':CRLF$:'Mean'				; colFormat<1,7> = '^1080'
		colHeader<1,8> = 'Thickness':CRLF$:'Std Dev'			; colFormat<1,8> = '^1080'
		colHeader<1,9> = ResLabel:CRLF$:'Mean'					; colFormat<1,9> = '^1260'
		colHeader<1,10> = ResLabel:CRLF$:'StdDev'				; colFormat<1,10> = '^1260'
	END ELSE
		colHeader = 'Run No'									; colFormat = '^1080'
		colHeader<1,2> = 'Batch No'								; colFormat<1,2> = '^1080'
		colHeader<1,3> = 'Cust Part No'							; colFormat<1,3> = '^1440'
		colHeader<1,4> = 'Lot No'								; colFormat<1,4> = '^1440'
		colHeader<1,5> = 'Qty'									; colFormat<1,5> = '^540'
		colHeader<1,6> = 'Zone'									; colFormat<1,6> = '^600'
		colHeader<1,7> = 'Layer'								; colFormat<1,7> = '^660'
		colHeader<1,8> = 'Thickness':CRLF$:'Mean'				; colFormat<1,8> = '^1080'
		colHeader<1,9> = 'Thickness':CRLF$:'Std Dev'			; colFormat<1,9> = '^1080'
		colHeader<1,10> = ResLabel:CRLF$:'Mean'					; colFormat<1,10> = '^1260'
		colHeader<1,11> = ResLabel:CRLF$:'StdDev'				; colFormat<1,11> = '^1260'
	END
	
	FirstLine = 1
	QtyOut = 0
	
	TotHgCvSRP		= 0
	TotWafOut		= 0
	TotMfgPre		= 0
	TotMfgPost		= 0
	TotCustPre		= 0
	TotCustPost		= 0
	ShipTotHgCvSRP	= 0
	
	HgCvSRPSummary     = ''
	RejectSummary      = ''
	RejString          = ''
	ShipHgCvSRPSummary = ''
	NCRKeys            = ''
	RunNos             = ''
	FOR I = 1 TO RDSCnt
		thisRDSNo    = RDSNos<1,I>
		
		ThisRdsRec      = XLATE( 'RDS', thisRDSNo, '', 'X' )
		
		WONo				= ThisRdsRec<RDS_WO$>										;* SAP update
		CassNo				= ThisRdsRec<RDS_CASS_NO$>									;* SAP update
		SAPBatchNo 			= XLATE('WO_MAT',WONo:'*':CassNo,WO_MAT_SAP_BATCH_NO$,'X')	;* SAP update  
		
		HrsReceivedToShip	= XLATE( 'RDS', thisRDSNo, 'HRS_EPITRONICS_FAB', 'X' )
		PartNo				= ThisRdsRec<RDS_PART_NUM$>
		LotNo				= RDSLotNos<1,I>
		RunNo				= ThisRdsRec<RDS_REACTOR$>:'-':RDSNos<1,I>
		RunNos<I>			= RunNo
		WafOut				= SUM(RDSLotCnts<1,I>)
		
		TotWafOut += WafOut
		
		colData = RunNo
		colData<1,2> = SAPBatchNo
		colData<1,3> = PartNo
		colData<1,4> = LotNo
		colData<1,5> = PrintRDSLotCnts<1,I>
		
		AllTWKeys = ''
		
		UseZone1Data = 0
		UseZone2Data = 0
		
		ThisRDSPocketProfile = ThisRDSRec<RDS_POCKET$>
		ThisRDSPocketChar    = ThisRDSRec<RDS_POCKET_CHAR$>
		ThisRDSPocketZone    = ThisRDSRec<RDS_ZONE$>
		ThisRDSPocketNCR     = ThisRDSRec<RDS_OUT_NCR$>
		ThisRDSPocketOutCass = ThisRDSRec<RDS_OUT_CASS_NO$>
		for each RDSPocket in ThisRDSPocketProfile    using @VM setting RDSPocketPos
		    WaferPocketChar = ThisRDSPocketChar<1, RDSPocketPos>
		    if WaferPocketChar NE 'TEST' then
		        ThisSlotOutCass = ThisRDSPocketOutCass<1,RDSPocketPos>
		        ThisWMOId       = WONo : '*1*' : ThisSlotOutCass
		        Locate ThisWMOId in WMOutKeys using @VM setting WMOPos then
		            //Check, does it have an NCR assoiciated
		            NCRKeyId = ThisRDSPocketNCR<1, RDSPocketPos>
		            If NCRKeyId EQ '' then
		                //Get the zone for this pocket.
		                ThisWfrZone = ThisRDSPocketZone<1, RDSPocketPos>
		                Begin Case
		                    Case ThisWfrZone EQ 1
		                        UseZone1Data = 1
		                    Case ThisWfrZone EQ 2
		                        UseZone2Data = 1
		                End Case
		            end
		        end else
		            //It might be found in a WMO if it's a makeup wafer
		            for each WMOKey in WMOutkeys using @VM setting WMOPos2
		                ThisWMOutRec       = Database_Services('ReadDataRow', 'WM_OUT', WMOKey, 1, 0, 0)
                        ThisWMOSlotProfile = ThisWMOutRec<WM_OUT_SLOT_NO$>
                        for each Slot in ThisWMOSlotProfile using @VM setting SlotPos
                            ThisSlotRDS    = ThisWMOutRec<WM_OUT_RDS$, SlotPos>
                            If ThisSlotRDS EQ thisRDSNo then
                                 ThisSlotInZone = ThisWMOutRec<WM_OUT_ZONE$, SlotPos>
                                 Begin Case
                                    Case ThisSlotInZone EQ 1
                                        UseZone1Data = 1
                                    Case ThisSlotInZone EQ 2
                                        UseZone2Data = 1
                                End Case
                            end
                        Next Slot
		            Next WMOKey
		        end
		    end
		Next RDSPocket
        
		MetKeys   = ''
		MetKeysZ1 = ''
		MetKeysZ2 = ''
		MetKeys   = XLATE('RDS',thisRDSNo,'MET_KEYS','X')
		if UseZone1Data then
		    MetKeysZ1 = XLATE('RDS',thisRDSNo,'MET_KEYS_Z1','X')
		end
		if UseZone2Data then
		   MetKeysZ2 = XLATE('RDS',thisRDSNo,'MET_KEYS_Z2','X') 
		end
		
		IF MetKeys NE ''	THEN AllTWKeys<1,-1> = MetKeys
		IF MetKeysZ1 NE ''	THEN AllTWKeys<1,-1> = MetKeysZ1
		IF MetKEysZ2 NE ''	THEN AllTWKeys<1,-1> = MetKeysZ2
		
		IF MetKeys NE '' THEN
		    //Non-EpiPro
			FOR L = 1 TO COUNT(MetKeys,@VM) + (MetKeys NE '')
				MetKey = MetKeys<1,L>
				TestRec		= XLATE('RDS_TEST',MetKey,'','X')
				LSId		= TestRec<RDS_TEST_LS_ID$>
				ThickAvg	= OCONV( TestRec<RDS_TEST_THICK_AVG$>, 'MD2' )
				ThickStdDev	= OCONV( TestRec<RDS_TEST_THICK_STDV$>, 'MD4' )
				
				IF FirstResUnits = 'ê/Ü' THEN
					ResAvg		= OCONV( TestRec<RDS_TEST_SHEETRHO_AVG$>,'MD3')
					ResStdDev	= OCONV( TestRec<RDS_TEST_SHEETRHO_STDV$>,'MD4')
				END ELSE
					ResAvg		= OCONV( TestRec<RDS_TEST_RES_AVG$>,'MD4')
					ResStdDev	= OCONV( TestRec<RDS_TEST_RES_STDV$>,'MD4')
					
					IF ResAvg = '' THEN
						ResAvg		= OCONV( TestRec<RDS_TEST_HGCV1_RES_AVG$>,'MD3')
						ResStdDev	= OCONV( TestRec<RDS_TEST_HGCV1_RES_STDV$>,'MD4')
					END
				END
				
				IF colData<L,6> = '' 	THEN colData<L,6> = LSId 		ELSE colData<L,6> = CRLF$:LSId
				IF colData<L,7> = '' 	THEN colData<L,7> = ThickAvg	ELSE colData<L,7> = CRLF$:ThickAvg
				IF colData<L,8> = '' 	THEN colData<L,8> = ThickStdDev	ELSE colData<L,8> = CRLF$:ThickStdDev
				IF colData<L,9> = '' 	THEN colData<L,9> = ResAvg		ELSE colData<L,9> = CRLF$:ResAvg
				IF colData<L,10> = ''	THEN colData<L,10> = ResStdDev	ELSE colData<L,10> = CRLF$:ResStdDev
			NEXT L
		END ELSE
		    //EpiPro
			LineCnt = 0
			IF MetKeysZ1 NE '' THEN
				FOR L = 1 TO COUNT(MetKeysZ1,@VM) + (MetKeysZ1 NE '')
					LineCnt += 1
					MetKey = MetKeysZ1<1,L>
					TestRec		= XLATE('RDS_TEST',MetKey,'','X')
					LSId		= TestRec<RDS_TEST_LS_ID$>
					Zone		= TestRec<RDS_TEST_ZONE$>
					ThickAvg	= OCONV( TestRec<RDS_TEST_THICK_AVG$>, 'MD2' )
					ThickStdDev	= OCONV( TestRec<RDS_TEST_THICK_STDV$>, 'MD4' )
					
					IF FirstResUnits = 'ê/Ü' THEN
						ResAvg		= OCONV( TestRec<RDS_TEST_SHEETRHO_AVG$>,'MD3')
						ResStdDev	= OCONV( TestRec<RDS_TEST_SHEETRHO_STDV$>,'MD4')
					END ELSE
						ResAvg		= OCONV( TestRec<RDS_TEST_RES_AVG$>,'MD4')
						ResStdDev	= OCONV( TestRec<RDS_TEST_RES_STDV$>,'MD4')
						
						IF ResAvg = '' THEN
							ResAvg		= OCONV( TestRec<RDS_TEST_HGCV1_RES_AVG$>,'MD3')
							ResStdDev	= OCONV( TestRec<RDS_TEST_HGCV1_RES_STDV$>,'MD4')
						END
					END
					
					IF colData<LineCnt,6> = '' 	THEN colData<LineCnt,6> = Zone			ELSE colData<LineCnt,6> = CRLF$:Zone
					IF colData<LineCnt,7> = '' 	THEN colData<LineCnt,7> = LSId 			ELSE colData<LineCnt,7> = CRLF$:LSId
					IF colData<LineCnt,8> = '' 	THEN colData<LineCnt,8> = ThickAvg		ELSE colData<LineCnt,8> = CRLF$:ThickAvg
					IF colData<LineCnt,9> = '' 	THEN colData<LineCnt,9> = ThickStdDev	ELSE colData<LineCnt,9> = CRLF$:ThickStdDev
					IF colData<LineCnt,10> = '' THEN colData<LineCnt,10> = ResAvg		ELSE colData<LineCnt,10> = CRLF$:ResAvg
					IF colData<LineCnt,11> = '' THEN colData<LineCnt,11> = ResStdDev	ELSE colData<LineCnt,11> = CRLF$:ResStdDev
				NEXT L
			
			END
			IF MetKeysZ2 NE '' THEN
				FOR L = 1 TO COUNT(MetKeysZ2,@VM) + (MetKeysZ2 NE '')
					LineCnt += 1
					MetKey = MetKeysZ2<1,L>
					TestRec		= XLATE('RDS_TEST',MetKey,'','X')
					LSId		= TestRec<RDS_TEST_LS_ID$>
					Zone		= TestRec<RDS_TEST_ZONE$>
					ThickAvg	= OCONV( TestRec<RDS_TEST_THICK_AVG$>, 'MD2' )
					ThickStdDev	= OCONV( TestRec<RDS_TEST_THICK_STDV$>, 'MD4' )
					
					IF FirstResUnits = 'ê/Ü' THEN
						ResAvg		= OCONV( TestRec<RDS_TEST_SHEETRHO_AVG$>,'MD3')
						ResStdDev	= OCONV( TestRec<RDS_TEST_SHEETRHO_STDV$>,'MD4')
					END ELSE
						ResAvg		= OCONV( TestRec<RDS_TEST_RES_AVG$>,'MD4')
						ResStdDev	= OCONV( TestRec<RDS_TEST_RES_STDV$>,'MD4')
						
						IF ResAvg = '' THEN
							ResAvg		= OCONV( TestRec<RDS_TEST_HGCV1_RES_AVG$>,'MD3')
							ResStdDev	= OCONV( TestRec<RDS_TEST_HGCV1_RES_STDV$>,'MD4')
						END
					END
					
					IF colData<LineCnt,6> = '' 	THEN colData<LineCnt,6> = Zone			ELSE colData<LineCnt,6> = CRLF$:Zone
					IF colData<LineCnt,7> = '' 	THEN colData<LineCnt,7> = LSId 			ELSE colData<LineCnt,7> = CRLF$:LSId
					IF colData<LineCnt,8> = '' 	THEN colData<LineCnt,8> = ThickAvg		ELSE colData<LineCnt,8> = CRLF$:ThickAvg
					IF colData<LineCnt,9> = ''	THEN colData<LineCnt,9> = ThickStdDev	ELSE colData<LineCnt,9> = CRLF$:ThickStdDev
					IF colData<LineCnt,10> = '' THEN colData<LineCnt,10> = ResAvg		ELSE colData<LineCnt,10> = CRLF$:ResAvg
					IF colData<LineCnt,11> = '' THEN colData<LineCnt,11> = ResStdDev	ELSE colData<LineCnt,11> = CRLF$:ResStdDev
				NEXT L
			END
		END
		GOSUB PrintTable
		
		
		FOR T = 1 TO COUNT(AllTWKeys,@VM) + (AllTWKeys NE '')
			TestRec = XLATE('RDS_TEST',AllTWKeys<1,T>,'','X')
			TWTools = TestRec<RDS_TEST_TW_TOOL$>
			FOR TW = 1 TO COUNT(TWTools,@VM) + (TWTools NE '')
				TWTool	= TWTools<1,TW> 
				TWQty	= TestRec<RDS_TEST_TW_CNT$,TW>
				IF TWTool = 'SRP' OR TWTool = 'HgCv' THEN
					ShipTotHgCvSRP += TWQty
					ShipHgCvSRPSummary<-1> = RunNo:' ':TWQty:' used for ':TWTool
				END
			NEXT TW
		NEXT T
		
		NCRKeys = ThisRDSRec<RDS_NCR_KEYS$>
		
		* Calculate the NCR summary here
		
			*WMOutNCRKeys = XLATE('WM_OUT',WMOutKeys,WM_OUT_NCR_KEYS$,'X')		;* Dead 2/20/2007 JCH
		WMOutNCRKeys = XLATE('WM_OUT',WMOutKeys,'NCR_NOS','X')
		
		NCRKeys<1,-1> = WMOutNCRKeys
		
		FOR R = 1 TO COUNT(NCRKeys,@VM) + (NCRKeys NE '')
			NCRKey = NCRKeys<1,R>
			IF NCRKey NE '' THEN
				NCRRec = XLATE('NCR',NCRKey,'','X')
				
				NCRWfrCnt		= SUM(obj_NCR('RejQty',NCRKey:@RM:NCRRec))
				NCRLossCodeDesc = XLATE('LOSS_CODES',NCRRec<NCR_LOSS_CODE$>,1,'X')
				
				BEGIN CASE
					CASE NCRRec<NCR_LOSS_STAGE$> = 'PRE' AND NCRRec<NCR_LOSS_BY$> = 'M'
						TotMfgPre += NCRWfrCnt
						RejString<-1> = RunNo:' ':NCRWfrCnt:' Manufacturing Pre Epi Reject(s) FOR ':NCRLossCodeDesc
						
					CASE NCRRec<NCR_LOSS_STAGE$> = 'POST' AND NCRRec<NCR_LOSS_BY$> = 'M'
						TotMfgPost += NCRWfrCnt
						RejString<-1> = RunNo:' ':NCRWfrCnt:' Manufacturing Post Epi Reject(s) FOR ':NCRLossCodeDesc
						
					CASE NCRRec<NCR_LOSS_STAGE$> = 'PRE' AND NCRRec<NCR_LOSS_BY$> = 'C'
						TotCustPre += NCRWfrCnt
						RejString<-1> = RunNo:' ':NCRWfrCnt:' Customer Pre Epi Reject(s) FOR ':NCRLossCodeDesc
						
					CASE NCRRec<NCR_LOSS_STAGE$> = 'POST' AND NCRRec<NCR_LOSS_BY$> = 'C'
						TotCustPost += NCRWfrCnt
						RejString<-1> = RunNo:' ':NCRWfrCnt:' Customer Post Epi Reject(s) FOR ':NCRLossCodeDesc
						
				END CASE
			END
		NEXT R
	
	NEXT I
	
	IF RDSCnt > 9 THEN
	
		* Show the Cp and CpK for the work order
		
		stat = Set_Printer('TEXT')		;* Blank Line
		
		Results = Calc_WO_Stats(RDSNos)
		
		colHeader = 'Thickness'									; colFormat = '^5400'
		colHeader<1,2> = 'Resistivity'							; colFormat<1,2> = '^5400'
		
		colData = ''
		FirstLine = 1
		GOSUB PrintTable
		
		colHeader = ''
		colFormat = '<3240':@VM:'^2160':@VM:'<3240':@VM:'^2160'
		
		colData = ''
		colData<1,1> = 'Mean'					; colData<1,2> = Results<1,1>	; colData<1,3> = 'Mean'					; colData<1,4> = Results<1,2>
		colData<2,1> = 'Sigma Capability'		; colData<2,2> = Results<1,15>	; colData<2,3> = 'Sigma Capability'		; colData<2,4> = Results<1,16>
		colData<3,1> = 'Sigma Level'			; colData<3,2> = Results<1,17>	; colData<3,3> = 'Sigma Level'			; colData<3,4> = Results<1,18>
		colData<4,1> = 'CP'						; colData<4,2> = Results<1,11>	; colData<4,3> = 'CP'					; colData<4,4> = Results<1,12>
		colData<5,1> = 'CPK'					; colData<5,2> = Results<1,13>	; colData<5,3> = 'CPK'					; colData<5,4> = Results<1,14>
		
		FirstLine = 1
		
		GOSUB PrintTable
	   
	END
		
	stat = Set_Printer('TEXT')		; * Blank Line
	
	TextOut = 'Total Quantity: ':TotWafOut
	Void = Set_Printer( 'TEXT', TextOut )
	
	IF SuppliedBy = 'C' THEN
		Lout = 'Rejects Due to Manufacturing ------ PRE EPI: ':TotMfgPre:' - POST EPI: ':TotMfgPost
		Void = Set_Printer( 'TEXT', Lout )
		
		Lout = 'Rejects Due to Customer - PRE EPI: ':TotCustPre:' - POST EPI: ':TotCustPost
		Void = Set_Printer( 'TEXT', Lout )
		
	END
	
	TextOut = 'HgCv/SRP WAFERS: ':ShipTotHgCvSRP
	Void = Set_Printer( 'TEXT', TextOut )

	IF RejString NE '' THEN
		
		Void = Set_Printer( 'TEXT', '' )
		
		colHeader = 'Wafer Rejection Information'
		colFormat = '<10800'
		colData = RejString
		
		FirstLine = 1
		
		GOSUB PrintTable
      
	END

	
	IF ShipHgCvSRPSummary NE ''THEN
		Void = Set_Printer( 'TEXT', '' )

		colHeader = 'HgCv/SRP Information:'      
		colFormat = '<10800'
		colData = ShipHgCvSRPSummary
		
		FirstLine = 1
		
		GOSUB PrintTable

	END
	
END ;* preliminary or full shipment

RETURN



* * * * * *
PrintTable:
* * * * * * 

stat = Set_Printer('CALCTABLE',colFormat:@FM:colData)
TableSize = Get_Printer('CALCTABLE')
TableHeight = TableSize<2>
Test = Get_Printer('POS')<2>

IF Get_Printer('POS')<2> + TableHeight > PrintableHeight OR FirstLine THEN
	IF NOT(FirstLine) THEN
		stat = Set_Printer('PAGEBREAK')
	END
	FirstLine = 0
	font<2> = 8
	font<4> = 1		;* Bold
	stat = Set_Printer('FONT',font,'100')

	stat = Set_Printer('ADDTABLE',colFormat,colHeader,'',LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)
	
	
	font<4> = 0
	stat = Set_Printer('FONT',font,fontSpacing)
	
	stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',0,TB_COLUMNS_TOP_BOTTOM)
	
END ELSE
	font<2> = 8
	font<4> = 0
	stat = Set_Printer('FONT',font,fontSpacing)
	stat = Set_Printer('ADDTABLE',colFormat,'',colData,LTGREY$,'',1,TB_COLUMNS_TOP_BOTTOM)

END
	
							
RETURN	 


