FUNCTION THRUPUT_REPORT_NEW(dummy)

#pragma precomp SRP_PreCompiler

* General Manager Report - goes straight to Excel

* 9/23/2006 John C. Henry, J.C. Henry & Co., Inc.  Initial coding

DECLARE SUBROUTINE  ErrMsg, Btree.Extract, Set_Status, SetInitDirOptions, ErrMsg, Logging_Services
DECLARE FUNCTION    Msg, Get_Status, obj_Calendar, Utility, SetInitDirOptions, Dialog_Box, obj_RDS_Test
Declare function    Logging_Services, Environment_Services, Gan_Services, obj_NCR

$INSERT RDS_EQU
$INSERT COMPANY_EQU
$INSERT REACTOR_EQUATES
$INSERT FISCAL_QTR_EQUATES
$INSERT COC_EQUATES
$INSERT MSG_EQUATES
$INSERT EXCEL_EQU
$INSERT LOGICAL

EQU COMMA$                  TO ','
EQU ROW$TOT_REACTOR_OUTS    TO  2
EQU ROW$TOT_YIELD_OUTS      TO  3
EQU ROW$TOT_CUST_SCRAP      TO  4
EQU ROW$TOT_EPI_SCRAP       TO  5
EQU ROW$TOT_OTHER           TO  6
EQU ROW$TOT_YIELD           TO  7
EQU ROW$TOT_SCRAP_RATE      TO  8
EQU ROW$TOT_SHIP            TO  9
EQU ROW$BLANK_LINE_1        TO 10
EQU ROW$CAP_OUT             TO 11
EQU ROW$CAP_FOUNDRY         TO 12
EQU ROW$CAP_FAB2            TO 13
EQU ROW$CAP_FAB10           TO 14
EQU ROW$CAP_FAB11           TO 15
EQU ROW$CAP_CUST_SCRAP      TO 16
EQU ROW$CAP_EPI_SCRAP       TO 17
EQU ROW$CAP_OTHER           TO 18
EQU ROW$CAP_YIELD           TO 19
EQU ROW$CAP_SCRAP_RATE      TO 20
EQU ROW$CAP_SHIP            TO 21
EQU ROW$BLANK_LINE_2        TO 22
EQU ROW$MER_TOT_OUT         TO 23
EQU ROW$MER_BL_OUT          TO 24
EQU ROW$MER_BLANKET_OUT     TO 25
EQU ROW$MER_CUST_SCRAP      TO 26
EQU ROW$MER_EPI_SCRAP       TO 27
EQU ROW$MER_OTHER           TO 28
EQU ROW$MER_YIELD           TO 29
EQU ROW$MER_SCRAP_RATE      TO 30
EQU ROW$MER_SHIP            TO 31
EQU ROW$BLANK_LINE_3        TO 32
EQU ROW$ASMP_OUT            TO 33
EQU ROW$ASMP_CUST_SCRAP     TO 34
EQU ROW$ASMP_EPI_SCRAP      TO 35
EQU ROW$ASMP_OTHER          TO 36
EQU ROW$ASMP_YIELD          TO 37
EQU ROW$ASMP_SCRAP_RATE     TO 38
EQU ROW$BLANK_LINE_4        TO 39
EQU ROW$ASM_OUT             TO 40
EQU ROW$ASM_CUST_SCRAP      TO 41
EQU ROW$ASM_EPI_SCRAP       TO 42
EQU ROW$ASM_OTHER           TO 43
EQU ROW$ASM_YIELD           TO 44
EQU ROW$ASM_SCRAP_RATE      TO 45
EQU ROW$BLANK_LINE_5        TO 46
EQU ROW$HTR3_OUT            TO 47
EQU ROW$HTR3_CUST_SCRAP     TO 48
EQU ROW$HTR3_EPI_SCRAP      TO 49
EQU ROW$HTR3_OTHER          TO 50
EQU ROW$HTR3_YIELD          TO 51
EQU ROW$HTR3_SCRAP_RATE     TO 52
EQU ROW$BLANK_LINE_6        TO 53
EQU ROW$EPIPRO_OUT          TO 54
EQU ROW$EPIPRO_CUST_SCRAP   TO 55
EQU ROW$EPIPRO_EPI_SCRAP    TO 56
EQU ROW$EPIPRO_OTHER        TO 57
EQU ROW$EPIPRO_YIELD        TO 58
EQU ROW$EPIPRO_SCRAP_RATE   TO 59

EQU CRLF$ TO \0D0A\

Main:
	
	errCode = ''
	
	eXcelCols = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,BB,CC,DD,EE,FF,GG,HH,II,JJ,KK,LL'
	SWAP "','" WITH ',' IN eXcelCols
	CONVERT ',' TO @VM IN eXcelCols
	
	NoteText  = 'Enter an ending date for data selection.':CRLF$:CRLF$
	NoteText := 'The report will calculate the Quarter and Week '
	NoteText := 'beginning and ending dates and report on the QTD '
	NoteText := 'through the ending date entered.'
	
	
	Dates = Dialog_Box("DIALOG_DATE_RANGE",@WINDOW,NoteText)
	
	StartDt = Dates<1>
	CutOffDt = Dates<2>
	
	
	
	thisCutOffDt = ICONV(CutOffDt,'D4/')
	thisStartDt = ICONV(StartDt,'D4/')
	
	IF thisCutOffDt = '' THEN
		RETURN
	END
	
	LogPath     = Environment_Services('GetApplicationRootPath') : '\LogFiles\ThruPut'
	LogDate     = Oconv(Date(), 'D4/')
	LogTime     = Oconv(Time(), 'MTS')
	LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' ThruPut Log.csv'
	Headers     = 'RDS' : @FM : 'Work Order' : @FM : 'Date Out' : @FM : 'Time Out' : @FM : 'Wafers'
	objLog      = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, Comma$, Headers, '', False$, True$)
	LoggingDTM  = LogDate : ' ' : LogTime   ; // Logging DTM
	
	CutOffDt = OCONV(thisCutOffDt,'D4/')
	StartDt = OCONV(thisStartDt,'D4/')
	
	IF CutOffDt = '' THEN RETURN
	
	FiscalYear = obj_Calendar('IRFiscalYear',CutOffDt)
	
	FWData = obj_Calendar('IRFiscalWeek',CutOffDt)
	FiscalWeek  = FWData[1,@FM]
	FWStartDt   = FWData[COL2()+1,@FM]
	FWEndDt     = FWData[COL2()+1,@FM]
	
	StartDt = ICONV(StartDt, 'D')
	EndDt = ICONV(CutOffDt, 'D')
	
	*GoSub Silicon
	*GoSub GaN
	
	
	* * * * * * * * *	
Silicon:
* * * * * * * * *		
	
	WeekDates = ''
	
	FOR I = StartDt TO EndDt
		WeekDates<1,-1> = OCONV(I,'D4/')
	NEXT I
	
	FQData = obj_Calendar('IRFiscalQuarter',CutOffDt)
	
	FiscalQuarter   = FQData<1>
	FQStartDt       = FQData<2>
	FQEndDt         = FQData<3>
	
	DataArray = ''
	DataArray<1,ROW$TOT_REACTOR_OUTS>   = '  Reactor Outs'
	DataArray<1,ROW$TOT_YIELD_OUTS>     = '  Yield Outs'
	DataArray<1,ROW$TOT_CUST_SCRAP>     = '  Sup/Cust Scrap'
	DataArray<1,ROW$TOT_EPI_SCRAP>      = '  IFX Scrap'
	DataArray<1,ROW$TOT_OTHER>          = '  Prod Test'
	DataArray<1,ROW$TOT_YIELD>          = '  Yield %'
	DataArray<1,ROW$TOT_SCRAP_RATE>     = '  Scrap/1k'
	DataArray<1,ROW$TOT_SHIP>           = '  Shipped'
	
	For I = 1 To DCOUNT(WeekDates, @VM)
		DataArray<I + 1, 1> = WeekDates<1, I>
		DayColIndex = I + 1
	Next I
	
	
	*Put in the equates to make them relative to the Day Columns
	EQU COL$WTD_ACTUAL		to	DayColIndex + 1
	EQU COL$QTD_ACTUAL		to	DayColIndex + 2
	EQU COL$QTD_MF_PLAN		to	DayColIndex + 3
	EQU COL$QTD_MF_REMAIN	to DayColIndex + 4
	EQU COL$ORG_MF_DAILY_PLAN	to DayColIndex + 5
	EQU COL$QTD_MF_OVER_UNDER to I DayColIndex + 6
	EQU COL$PERIOD				TO DayColIndex + 7
	EQU COL$PERIOD_VALUE		TO DayColIndex + 8
	EQU COL$PERIOD_START		TO DayColIndex + 9
	EQU COL$PERIOD_END			TO DayColIndex + 10
	
	DataArray<COL$WTD_ACTUAL,1>         = 'WTD Actual'
	DataArray<COL$QTD_ACTUAL,1>         = 'QTD Actual'
	DataArray<COL$QTD_MF_PLAN,1>    	= 'MF QTY Plan'            
	DataArray<COL$QTD_MF_REMAIN,1>  	= 'MF QTD Remain'          
	DataArray<COL$ORG_MF_DAILY_PLAN,1>  = 'MF Plan Daily'          
	* DataArray<COL$QTD_MF_OVER_UNDER,1>  = 'MF QTD   +/-'
	
	
	OPEN 'DICT.RDS' TO @DICT ELSE
		ErrMsg('Unable to open "DICT.RDS" for index lookup')
		RETURN
	END
	
	OPEN 'RDS' TO RDSTable ELSE
		ErrMsg('Unable to open "DICT.RDS" for index lookup')
		RETURN
	END
	
	For	a = 2 to DayColIndex
		Today = Date()
		
		DateToFind = ICONV(DataArray<a>, 'D4/')
		
		if DateToFind LE Today then
			SearchString = 'DATE_OUT':@VM:OConv(DateToFind, 'D4/')
			
			RDSKeys = ''
			Option = ''
			Flag = ''
			
			*Def = ""
			*Def<MTEXT$> = "Selecting RDS records..."
			*Def<MTYPE$> = "U"
			*MsgUp = Msg(@window, Def)   ;* display the processing message
			
			Set_Status(0)
			Btree.Extract(SearchString, 'RDS', @DICT, RDSKeys, Option, Flag)
			
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
				RETURN
			END
			IF RDSKeys = '' THEN
				*Errmsg('No RDS Records found for the current quarter!')
				
			END ELSE
				RDSCnt  = COUNT(RDSKeys,@VM) + (RDSKeys NE '')
				LoopCnt = 0
				LastCheck = 0
				
				Def = ""
				Def<MCAPTION$>      = "Building Si Report... Day ": a - 1 : " of " : DayColIndex
				Def<MTYPE$>         = "GC"
				Def<MEXTENT$>       = RDSCnt
				Def<MTEXTWIDTH$>    = 600
				
				AArray = ''
				AATot = 0
				MerProdRow = ''     ;* Moved from line 588 - dkk 1/13/14
				CapFabRow = 9       ;* Moved from line 589 - dkk 1/13/14
				
				MsgUp = Msg(@WINDOW, Def)
				
				LOOP
					
					@ID = RDSKeys[1,@VM]
					RDSKeys[1,COL2()] = ''
					LoopCnt += 1
					
					READ @RECORD FROM RDSTable,@ID THEN
						AATot = 0
						AArray = ''
						ReactorsOut = {WAFERS_IN}
						AATot = AATot + ReactorsOut
						
						WafersOut = {WFRS_OUT_THRUPUT}
						
						AArray<LoopCnt,1> = @ID
						AArray<LoopCnt,2> = AATot
						AArray<LoopCnt,3> = ReactorsOut
						
						NCRKeys = @RECORD<RDS_NCR_KEYS$>
						CustScrap   = {CUST_TOT_REJ}
						IFXEpiScrap  = {LSL_TOT_REJ}
						
						TestKeys = XLATE('RDS_LAYER',@RECORD<RDS_RDS_LAYER_KEYS$>,3,'X')
						TWProd = obj_RDS_Test('ProdTestCount',TestKeys)
						
						SRPBillable = @RECORD<RDS_RESEARCH_SRP_BILLABLE$>
						
						OtherWafers = TWProd + SRPBillable
						
						Reactor = @RECORD<RDS_REACTOR$>
						ReactorType = XLATE('REACTOR',Reactor,REACTOR_REACT_TYPE$ ,'X')
						
						BEGIN CASE
							CASE ReactorType = 'ASM+'
								ReactTotRow         = ROW$ASMP_OUT
								ReactCustScrapRow   = ROW$ASMP_CUST_SCRAP
								ReactIFXEpiScrapRow  = ROW$ASMP_EPI_SCRAP
								ReactOtherRow       = ROW$ASMP_OTHER
								ReactYieldRow       = ROW$ASMP_YIELD
								ReactScrapRateRow   = ROW$ASMP_SCRAP_RATE
								
							CASE ReactorType = 'HTR'
								ReactTotRow         = ROW$HTR3_OUT
								ReactCustScrapRow   = ROW$HTR3_CUST_SCRAP
								ReactIFXEpiScrapRow  = ROW$HTR3_EPI_SCRAP
								ReactOtherRow       = ROW$HTR3_OTHER
								ReactYieldRow       = ROW$HTR3_YIELD
								ReactScrapRateRow   = ROW$HTR3_SCRAP_RATE
								
							CASE ReactorType = 'EPP'
								ReactTotRow         = ROW$EPIPRO_OUT
								ReactCustScrapRow   = ROW$EPIPRO_CUST_SCRAP
								ReactIFXEpiScrapRow  = ROW$EPIPRO_EPI_SCRAP
								ReactOtherRow       = ROW$EPIPRO_OTHER
								ReactYieldRow       = ROW$EPIPRO_YIELD
								ReactScrapRateRow   = ROW$EPIPRO_SCRAP_RATE
								
							CASE 1
								ReactTotRow         = ROW$ASM_OUT
								ReactCustScrapRow   = ROW$ASM_CUST_SCRAP
								ReactIFXEpiScrapRow  = ROW$ASM_EPI_SCRAP
								ReactOtherRow       = ROW$ASM_OTHER
								ReactYieldRow       = ROW$ASM_YIELD
								ReactScrapRateRow   = ROW$ASM_SCRAP_RATE
								
						END CASE
						
						CustNo = @RECORD<RDS_CUST_NO$>
						
						Captive   = 0 ; // Disable Captive
						CustReportExclude = XLATE('COMPANY',CustNo,COMPANY_REPORT_EXCLUDE$,'X')
						
						Product = {PRODUCT}
						DateOut = {DATE_OUT}
						TimeOut = {TIME_OUT}
						Day = MOD(DateOut,7)
						
						
						
						/*BEGIN CASE
																            CASE Day = 0 ; DayCol = COL$SUN
																            CASE Day = 1 ; DayCol = COL$MON
																            CASE Day = 2 ; DayCol = COL$TUE
																            CASE Day = 3 ; DayCol = COL$WED
																            CASE Day = 4 ; DayCol = COL$THU
																            CASE Day = 5 ; DayCol = COL$FRI
																            CASE Day = 6 ; DayCol = COL$SAT
																          END CASE
																          */
						DateOut = OCONV(DateOut,'D4/')
						TimeOut = OCONV(TimeOut,'MTS')
						*debug
						
						DayCol = a
						
						
						*debug
						LogData     = ''
						LogData<1>  = @ID
						LogData<2>  = {WO}
						LogData<3>  = DateOut
						LogData<4>  = TimeOut
						If ReactorsOut NE '' then            
							LogData<5>  = ReactorsOut
						end else
							LogData<5> = 0
						end
						Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
						
						
						RDSFiscalWeek = obj_Calendar('IRFiscalWeek',DateOut)<1> ;* 2nd and 3rd fields are the start and end dates of the week
						
						BEGIN CASE
							CASE Captive AND CustNo = '6593'
								CapFabRow = ROW$CAP_FAB2
								
							CASE Captive AND (CustNo = '7053' OR CustNo = '7092' OR CustNo = '7102' OR CustNo = '7103' OR CustNo = '7108' )
								CapFabRow = ROW$CAP_FOUNDRY
								
							CASE Captive AND CustNo = '6874' OR CustNo = '7055'
								IF {WAFER_MM} = '200 mm' THEN
									CapFabRow = ROW$CAP_FAB11
								END ELSE
									CapFabRow = ROW$CAP_FAB10
								END
								
							CASE Captive AND CustNo = '7087'
								CapFabRow = ROW$CAP_FAB11
								
							CASE NOT(Captive) AND Product _EQC '041-B/L'
								MerProdRow = ROW$MER_BL_OUT
								
							CASE NOT(Captive) AND Product _EQC '044-Blanket'
								MerProdRow = ROW$MER_BLANKET_OUT
								
							CASE 1
								NULL        
								
						END CASE
						
						DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS>  = DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
						DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
						DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
						DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
						DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
						
						Yield = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
						
						DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
						
						**********************
						* IFX Scrap Rate Row *
						**********************
						IF DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
							ScrapRate = (DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> / DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>) * 1000
						END ELSE
							ScrapRate = 0
						END
						DataArray<COL$QTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
						
						**********************************
						* Begin of Planning Calculations *
						**********************************
						/*
																          *************
																          * Scrap Row *
																          *************
																          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>,'MD0'))
																          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP> = OCONV(QTDRem,'MD0,')
																          
																          IF PlanWorkingDays = 0 THEN
																              OrgDailyPlan = 0
																          END ELSE
																              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanDaysRem
																          END
																          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_EPI_SCRAP> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
																          
																          IF OrgDailyPlan NE 0 THEN
																              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
																              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> - PlanQTD,'MD0')
																              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_EPI_SCRAP> = OCONV(QTDOverUnder,'MD0,')
																          END
																      */
						/*
																          ******************
																          * Yield Outs Row *
																          ******************
																          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>,'MD0'))
																          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS> = OCONV(QTDRem,'MD0,')
																          
																          IF PlanWorkingDays = 0 THEN
																              OrgDailyPlan = 0
																          END ELSE
																              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanDaysRem
																          END
																          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_YIELD_OUTS> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
																          
																          IF OrgDailyPlan NE 0 THEN
																              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
																              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> - PlanQTD,'MD0')
																              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_YIELD_OUTS> = OCONV(QTDOverUnder,'MD0,')
																          END
																          */
						********************************
						* End of Planning Calculations *
						********************************
						
						*IF RDSFiscalWeek = FiscalWeek THEN
						
						
						IF DayCol NE '' THEN
							DataArray<DayCol,ROW$TOT_REACTOR_OUTS>   = DataArray<DayCol,ROW$TOT_REACTOR_OUTS> + ReactorsOut
							DataArray<DayCol,ROW$TOT_YIELD_OUTS>     = DataArray<DayCol,ROW$TOT_YIELD_OUTS> + WafersOut
							DataArray<DayCol,ROW$TOT_CUST_SCRAP>    = DataArray<DayCol,ROW$TOT_CUST_SCRAP> + CustScrap
							DataArray<DayCol,ROW$TOT_EPI_SCRAP>     = DataArray<DayCol,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
							DataArray<DayCol,ROW$TOT_OTHER>         = DataArray<DayCol,ROW$TOT_OTHER> + OtherWafers
							
							IF DataArray<DayCol,ROW$TOT_YIELD_OUTS> > 0 THEN
								Yield = DataArray<DayCol,ROW$TOT_YIELD_OUTS> / (DataArray<DayCol,ROW$TOT_YIELD_OUTS> + DataArray<DayCol,ROW$TOT_EPI_SCRAP>)
							END ELSE
								Yield = 0
							END
							
							DataArray<DayCol,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
						END
						
						DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS>   = DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
						DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
						DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
						DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
						DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
						
						IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
							Yield = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
						END ELSE
							Yield = 0
						END
						DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
						
						* Scrap Rate
						IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
							ScrapRate = (DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>/DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>)*1000
						END ELSE
							ScrapRate = 0
						END
						DataArray<COL$WTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
						
						*END     ;*  End of check for current fiscal week
						
					END ;* End of RDS Record read
					
					Running = Msg(@WINDOW, MsgUp, LoopCnt, MSGINSTUPDATE$) 
					
					
				UNTIL RDSKeys = '' OR NOT(Running)
				REPEAT
				Msg(@WINDOW,MsgUp)
			end
		end
	Next a
	
	/* Fudge the dates - '~' is not inclusive of the end dates
			    StartDt = ICONV(StartDt,'D')
			    EndDt   = thisCutOffDt
			
			
			
			    SearchString = 'DATE_OUT':@VM:thisStartDt:'~':EndDt:@FM     ;**************
			debug
			    RDSKeys = ''
			    Option = ''
			    Flag = ''
			
			    Def = ""
			    Def<MTEXT$> = "Selecting RDS records..."
			    Def<MTYPE$> = "U"
			    MsgUp = Msg(@window, Def)   ;* display the processing message
			
			    Set_Status(0)
			    Btree.Extract(SearchString, 'RDS', @DICT, RDSKeys, Option, Flag)
			
			    Msg(@WINDOW, MsgUp)
			
			    IF Get_Status(errCode) THEN
			      ErrMsg(errCode)
			      RETURN
			    END
			
			    IF RDSKeys = '' THEN
			      ErrMsg('No RDS Records found for the current quarter!')
			      RETURN
			    END
			
			    RDSCnt  = COUNT(RDSKeys,@VM) + (RDSKeys NE '')
			    LoopCnt = 0
			    LastCheck = 0
			
			    Def = ""
			    Def<MCAPTION$>      = "Building Report..."
			    Def<MTYPE$>         = "GC"
			    Def<MEXTENT$>       = RDSCnt
			    Def<MTEXTWIDTH$>    = 600
			
			    AArray = ''
			    AATot = 0
			    MerProdRow = ''     ;* Moved from line 588 - dkk 1/13/14
			    CapFabRow = 9       ;* Moved from line 589 - dkk 1/13/14
			
			    MsgUp = Msg(@WINDOW, Def)
			    LOOP
			    	
			      @ID = RDSKeys[1,@VM]
			      RDSKeys[1,COL2()] = ''
			      LoopCnt += 1
			      
			      READ @RECORD FROM RDSTable,@ID THEN
			      
			          ReactorsOut = {WAFERS_IN}
			          AATot = AATot + ReactorsOut
			          
			          WafersOut = {WFRS_OUT_THRUPUT}
			       
			          AArray<LoopCnt,1> = @ID
			          AArray<LoopCnt,2> = AATot
			          AArray<LoopCnt,3> = ReactorsOut
			          
			          NCRKeys = @RECORD<RDS_NCR_KEYS$>
			          CustScrap   = {CUST_TOT_REJ}
			          IFXEpiScrap  = {LSL_TOT_REJ}
			          
			          TestKeys = XLATE('RDS_LAYER',@RECORD<RDS_RDS_LAYER_KEYS$>,3,'X')
			          TWProd = obj_RDS_Test('ProdTestCount',TestKeys)
			
			          SRPBillable = @RECORD<RDS_RESEARCH_SRP_BILLABLE$>
			          
			          OtherWafers = TWProd + SRPBillable
			          
			          Reactor = @RECORD<RDS_REACTOR$>
			          ReactorType = XLATE('REACTOR',Reactor,REACTOR_REACT_TYPE$ ,'X')
			          
			          BEGIN CASE
			              CASE ReactorType = 'ASM+'
			                  ReactTotRow         = ROW$ASMP_OUT
			                  ReactCustScrapRow   = ROW$ASMP_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$ASMP_EPI_SCRAP
			                  ReactOtherRow       = ROW$ASMP_OTHER
			                  ReactYieldRow       = ROW$ASMP_YIELD
			                  ReactScrapRateRow   = ROW$ASMP_SCRAP_RATE
			                  
			              CASE ReactorType = 'HTR'
			                  ReactTotRow         = ROW$HTR3_OUT
			                  ReactCustScrapRow   = ROW$HTR3_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$HTR3_EPI_SCRAP
			                  ReactOtherRow       = ROW$HTR3_OTHER
			                  ReactYieldRow       = ROW$HTR3_YIELD
			                  ReactScrapRateRow   = ROW$HTR3_SCRAP_RATE
			                  
			              CASE ReactorType = 'EPP'
			                  ReactTotRow         = ROW$EPIPRO_OUT
			                  ReactCustScrapRow   = ROW$EPIPRO_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$EPIPRO_EPI_SCRAP
			                  ReactOtherRow       = ROW$EPIPRO_OTHER
			                  ReactYieldRow       = ROW$EPIPRO_YIELD
			                  ReactScrapRateRow   = ROW$EPIPRO_SCRAP_RATE
			                  
			              CASE 1
			                  ReactTotRow         = ROW$ASM_OUT
			                  ReactCustScrapRow   = ROW$ASM_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$ASM_EPI_SCRAP
			                  ReactOtherRow       = ROW$ASM_OTHER
			                  ReactYieldRow       = ROW$ASM_YIELD
			                  ReactScrapRateRow   = ROW$ASM_SCRAP_RATE
			                  
			          END CASE
			                  
			          CustNo = @RECORD<RDS_CUST_NO$>
			          
			          Captive   = 0 ; // Disable Captive
			          CustReportExclude = XLATE('COMPANY',CustNo,COMPANY_REPORT_EXCLUDE$,'X')
			          
			          Product = {PRODUCT}
			          DateOut = {DATE_OUT}
			          TimeOut = {TIME_OUT}
			          Day = MOD(DateOut,7)
			          
			          
			           
			          /*BEGIN CASE
			            CASE Day = 0 ; DayCol = COL$SUN
			            CASE Day = 1 ; DayCol = COL$MON
			            CASE Day = 2 ; DayCol = COL$TUE
			            CASE Day = 3 ; DayCol = COL$WED
			            CASE Day = 4 ; DayCol = COL$THU
			            CASE Day = 5 ; DayCol = COL$FRI
			            CASE Day = 6 ; DayCol = COL$SAT
			          END CASE
			          */
	/*
			          DateOut = OCONV(DateOut,'D4/')
			          TimeOut = OCONV(TimeOut,'MTS')
			          *debug
			          For a = 2 to DayColIndex
			          	*debug
			          	dateToCompare = DataArray<a,1>
						if dateToCompare EQ DateOut then
							 	DayCol = a
						end else
							DayCol = ''
						end
			          Next a
			          *debug
			          LogData     = ''
			          LogData<1>  = @ID
			          LogData<2>  = {WO}
			          LogData<3>  = DateOut
			          LogData<4>  = TimeOut
			          If ReactorsOut NE '' then            
			              LogData<5>  = ReactorsOut
			          end else
			              LogData<5> = 0
			          end
			          Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
			                        
			          
			          RDSFiscalWeek = obj_Calendar('IRFiscalWeek',DateOut)<1> ;* 2nd and 3rd fields are the start and end dates of the week
			          
			          BEGIN CASE
			              CASE Captive AND CustNo = '6593'
			                  CapFabRow = ROW$CAP_FAB2
			                  
			              CASE Captive AND (CustNo = '7053' OR CustNo = '7092' OR CustNo = '7102' OR CustNo = '7103' OR CustNo = '7108' )
			                  CapFabRow = ROW$CAP_FOUNDRY
			                              
			              CASE Captive AND CustNo = '6874' OR CustNo = '7055'
			                  IF {WAFER_MM} = '200 mm' THEN
			                      CapFabRow = ROW$CAP_FAB11
			                  END ELSE
			                      CapFabRow = ROW$CAP_FAB10
			                  END
			                  
			              CASE Captive AND CustNo = '7087'
			                  CapFabRow = ROW$CAP_FAB11
			                      
			              CASE NOT(Captive) AND Product _EQC '041-B/L'
			                  MerProdRow = ROW$MER_BL_OUT
			                  
			              CASE NOT(Captive) AND Product _EQC '044-Blanket'
			                  MerProdRow = ROW$MER_BLANKET_OUT
			                  
			              CASE 1
			                  NULL        
			          
			          END CASE
			          
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS>  = DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
			          
			          Yield = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
			          
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			
			          **********************
			          * IFX Scrap Rate Row *
			          **********************
			          IF DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
			              ScrapRate = (DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> / DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>) * 1000
			          END ELSE
			              ScrapRate = 0
			          END
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
			
			          **********************************
			          * Begin of Planning Calculations *
			          **********************************
			          /*
			          *************
			          * Scrap Row *
			          *************
			          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>,'MD0'))
			          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP> = OCONV(QTDRem,'MD0,')
			          
			          IF PlanWorkingDays = 0 THEN
			              OrgDailyPlan = 0
			          END ELSE
			              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanDaysRem
			          END
			          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_EPI_SCRAP> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
			          
			          IF OrgDailyPlan NE 0 THEN
			              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
			              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> - PlanQTD,'MD0')
			              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_EPI_SCRAP> = OCONV(QTDOverUnder,'MD0,')
			          END
			      */
	/*
			          ******************
			          * Yield Outs Row *
			          ******************
			          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>,'MD0'))
			          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS> = OCONV(QTDRem,'MD0,')
			          
			          IF PlanWorkingDays = 0 THEN
			              OrgDailyPlan = 0
			          END ELSE
			              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanDaysRem
			          END
			          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_YIELD_OUTS> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
			          
			          IF OrgDailyPlan NE 0 THEN
			              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
			              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> - PlanQTD,'MD0')
			              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_YIELD_OUTS> = OCONV(QTDOverUnder,'MD0,')
			          END
			          
			          ********************************
			          * End of Planning Calculations *
			          ********************************
			          
			          *IF RDSFiscalWeek = FiscalWeek THEN
			              
			                      
			              IF DayCol NE '' THEN
			                  DataArray<DayCol,ROW$TOT_REACTOR_OUTS>   = DataArray<DayCol,ROW$TOT_REACTOR_OUTS> + ReactorsOut
			                  DataArray<DayCol,ROW$TOT_YIELD_OUTS>     = DataArray<DayCol,ROW$TOT_YIELD_OUTS> + WafersOut
			                  DataArray<DayCol,ROW$TOT_CUST_SCRAP>    = DataArray<DayCol,ROW$TOT_CUST_SCRAP> + CustScrap
			                  DataArray<DayCol,ROW$TOT_EPI_SCRAP>     = DataArray<DayCol,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
			                  DataArray<DayCol,ROW$TOT_OTHER>         = DataArray<DayCol,ROW$TOT_OTHER> + OtherWafers
			                  
			                  IF DataArray<DayCol,ROW$TOT_YIELD_OUTS> > 0 THEN
			                      Yield = DataArray<DayCol,ROW$TOT_YIELD_OUTS> / (DataArray<DayCol,ROW$TOT_YIELD_OUTS> + DataArray<DayCol,ROW$TOT_EPI_SCRAP>)
			                  END ELSE
			                      Yield = 0
			                  END
			                  
			                  DataArray<DayCol,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			              END
			                  
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS>   = DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
			              
			              IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
			                  Yield = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
			              END ELSE
			                  Yield = 0
			              END
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			              
			              * Scrap Rate
			              IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
			                  ScrapRate = (DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>/DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>)*1000
			              END ELSE
			                  ScrapRate = 0
			              END
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
			                                                          
			          *END     ;*  End of check for current fiscal week
			
			      END ;* End of RDS Record read
			      
			      Running = Msg(@WINDOW, MsgUp, LoopCnt, MSGINSTUPDATE$) 
			      
			      
			    UNTIL RDSKeys = '' OR NOT(Running)
			    REPEAT*/
	SiArray = DataArray
	Msg(@WINDOW,MsgUp)
	
	
	* * * * * * * *	
GaN:
* * * * * * * *	
	
	WeekDates = ''
	
	FOR I = StartDt TO EndDt
		WeekDates<1,-1> = OCONV(I,'D4/')
	NEXT I
	
	FQData = obj_Calendar('IRFiscalQuarter',CutOffDt)
	
	FiscalQuarter   = FQData<1>
	FQStartDt       = FQData<2>
	FQEndDt         = FQData<3>
	
	DataArray = ''
	DataArray<1,ROW$TOT_REACTOR_OUTS>   = '  Reactor Outs'
	DataArray<1,ROW$TOT_YIELD_OUTS>     = '  Yield Outs'
	DataArray<1,ROW$TOT_CUST_SCRAP>     = '  Sup/Cust Scrap'
	DataArray<1,ROW$TOT_EPI_SCRAP>      = '  IFX Scrap'
	DataArray<1,ROW$TOT_OTHER>          = '  Prod Test'
	DataArray<1,ROW$TOT_YIELD>          = '  Yield %'
	DataArray<1,ROW$TOT_SCRAP_RATE>     = '  Scrap/1k'
	DataArray<1,ROW$TOT_SHIP>           = '  Shipped'
	
	For I = 1 To DCOUNT(WeekDates, @VM)
		DataArray<I + 1, 1> = WeekDates<1, I>
		DayColIndex = I + 1
	Next I
	
	
	*Put in the equates to make them relative to the Day Columns
	*EQU COL$WTD_ACTUAL		to	DayColIndex + 1
	*EQU COL$QTD_ACTUAL		to	DayColIndex + 2
	*EQU COL$QTD_MF_PLAN		to	DayColIndex + 3
	*EQU COL$QTD_MF_REMAIN	to DayColIndex + 4
	*EQU COL$ORG_MF_DAILY_PLAN	to DayColIndex + 5
	*EQU COL$QTD_MF_OVER_UNDER to I DayColIndex + 6
	*EQU COL$PERIOD				TO DayColIndex + 7
	*EQU COL$PERIOD_VALUE		TO DayColIndex + 8
	*EQU COL$PERIOD_START		TO DayColIndex + 9
	*EQU COL$PERIOD_END			TO DayColIndex + 10
	
	DataArray<COL$WTD_ACTUAL,1>         = 'WTD Actual'
	DataArray<COL$QTD_ACTUAL,1>         = 'QTD Actual'
	DataArray<COL$QTD_MF_PLAN,1>    	= 'MF QTY Plan'            
	DataArray<COL$QTD_MF_REMAIN,1>  	= 'MF QTD Remain'          
	DataArray<COL$ORG_MF_DAILY_PLAN,1>  = 'MF Plan Daily'          
	* DataArray<COL$QTD_MF_OVER_UNDER,1>  = 'MF QTD   +/-'
	
	
	OPEN 'DICT.REACT_RUN' TO @DICT ELSE
		ErrMsg('Unable to open "DICT.REACT_RUN" for index lookup')
		RETURN
	END
	
	OPEN 'REACT_RUN' TO ReactRunTable ELSE
		ErrMsg('Unable to open "REACT_RUN" to read records')
		RETURN
	END
	
	For	a = 2 to DayColIndex
		Today = Date()
		
		DateToFind = ICONV(DataArray<a>, 'D4/')
		
		if DateToFind LE Today then
			SearchString = 'UNLOAD_DT':@VM:OConv(DateToFind, 'D4/'):@FM:'REACTOR_TYPE':@VM:"GAN":@FM     ;
			
			ReactRunKeys = ''
			Option = ''
			Flag = ''
			
			*Def = ""
			*Def<MTEXT$> = "Selecting RDS records..."
			*Def<MTYPE$> = "U"
			*MsgUp = Msg(@window, Def)   ;* display the processing message
			
			Set_Status(0)
			Btree.Extract(SearchString, 'REACT_RUN', @DICT, ReactRunKeys, Option, Flag)
			
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
				RETURN
			END
			IF ReactRunKeys = '' THEN
				*Errmsg('No RDS Records found for the current quarter!')
				*GoSub SendToExcel
			END else
				RDSCnt  = COUNT(ReactRunKeys,@VM) + (ReactRunKeys NE '')
				LoopCnt = 0
				LastCheck = 0
				
				Def = ""
				Def<MCAPTION$>      = "Building GaN Report... Day ": a - 1 : " of " : DayColIndex
				Def<MTYPE$>         = "GC"
				Def<MEXTENT$>       = RDSCnt
				Def<MTEXTWIDTH$>    = 600
				
				AArray = ''
				AATot = 0
				MerProdRow = ''     ;* Moved from line 588 - dkk 1/13/14
				CapFabRow = 9       ;* Moved from line 589 - dkk 1/13/14
				
				MsgUp = Msg(@WINDOW, Def)
				
				LOOP
					@ID = ReactRunKeys[1,@VM]
					ReactRunKeys[1,COL2()] = ''
					LoopCnt += 1
					
					READ @RECORD FROM ReactRunTable,@ID THEN
						
						YieldInfo = Gan_Services('GetYieldInfo', @ID)
						GRWfrQty  = YieldInfo<1>
						ScrapQty  = YieldInfo<2>
						ProdTWQty = YieldInfo<3>
						DummyQty  = YieldInfo<4>
						WafersOut = GRWfrQty - ScrapQty - ProdTWQty - DummyQty
						ReactorsOut = GRWfrQty
						AATot = AATot + ReactorsOut
						
						AArray<LoopCnt,1> = @ID
						AArray<LoopCnt,2> = AATot
						AArray<LoopCnt,3> = ReactorsOut
						
						NCRNos        = Xlate('REACT_RUN', @ID, 'NCR_NOS', 'X')
						NCRsByStage   = obj_NCR('StageBy', NCRNos)
						LSLPreScrap   = Sum(Xlate('NCR', NCRsByStage<1>, 'REJ_CNT', 'X'))
						LSLPostScrap  = Sum(Xlate('NCR', NCRsByStage<2>, 'REJ_CNT', 'X'))
						CustPreScrap  = Sum(Xlate('NCR', NCRsByStage<3>, 'REJ_CNT', 'X'))
						CustPostScrap = Sum(Xlate('NCR', NCRsByStage<4>, 'REJ_CNT', 'X'))
						CustScrap     = CustPreScrap + CustPostScrap
						IFXEpiScrap   = LSLPreScrap + LSLPostScrap
						
						OtherWafers = ProdTWQty
						
						DateOut = {UNLOAD_DT}
						DateOut = OCONV(DateOut,'D4/')
						TimeOut = OCONV(TimeOut,'MTS')
						*debug
						
						DayCol = a
						
						*debug
						*debug
						LogData     = ''
						LogData<1>  = @ID
						
						*LogData<2>  = {WO}
						LogData<3>  = DateOut
						LogData<4>  = TimeOut
						If ReactorsOut NE '' then            
							LogData<5>  = ReactorsOut
						end else
							LogData<5> = 0
						end
						Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
						
						
						RDSFiscalWeek = obj_Calendar('IRFiscalWeek',DateOut)<1> ;* 2nd and 3rd fields are the start and end dates of the week
						
						/*BEGIN CASE
												CASE Captive AND CustNo = '6593'
													CapFabRow = ROW$CAP_FAB2
													
												CASE Captive AND (CustNo = '7053' OR CustNo = '7092' OR CustNo = '7102' OR CustNo = '7103' OR CustNo = '7108' )
													CapFabRow = ROW$CAP_FOUNDRY
													
												CASE Captive AND CustNo = '6874' OR CustNo = '7055'
													IF {WAFER_MM} = '200 mm' THEN
														CapFabRow = ROW$CAP_FAB11
													END ELSE
														CapFabRow = ROW$CAP_FAB10
													END
													
												CASE Captive AND CustNo = '7087'
													CapFabRow = ROW$CAP_FAB11
													
												CASE NOT(Captive) AND Product _EQC '041-B/L'
													MerProdRow = ROW$MER_BL_OUT
													
												CASE NOT(Captive) AND Product _EQC '044-Blanket'
													MerProdRow = ROW$MER_BLANKET_OUT
													
												CASE 1
													NULL        
													
											END CASE*/
						
						DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS>  = DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
						DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
						DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
						DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
						DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
						
						Yield = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
						
						DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
						
						**********************
						* IFX Scrap Rate Row *
						**********************
						IF DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
							ScrapRate = (DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> / DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>) * 1000
						END ELSE
							ScrapRate = 0
						END
						DataArray<COL$QTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
						
						**********************************
						* Begin of Planning Calculations *
						**********************************
						/*
																          *************
																          * Scrap Row *
																          *************
																          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>,'MD0'))
																          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP> = OCONV(QTDRem,'MD0,')
																          
																          IF PlanWorkingDays = 0 THEN
																              OrgDailyPlan = 0
																          END ELSE
																              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanDaysRem
																          END
																          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_EPI_SCRAP> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
																          
																          IF OrgDailyPlan NE 0 THEN
																              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
																              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> - PlanQTD,'MD0')
																              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_EPI_SCRAP> = OCONV(QTDOverUnder,'MD0,')
																          END
																      */
						/*
																          ******************
																          * Yield Outs Row *
																          ******************
																          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>,'MD0'))
																          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS> = OCONV(QTDRem,'MD0,')
																          
																          IF PlanWorkingDays = 0 THEN
																              OrgDailyPlan = 0
																          END ELSE
																              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanDaysRem
																          END
																          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_YIELD_OUTS> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
																          
																          IF OrgDailyPlan NE 0 THEN
																              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
																              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> - PlanQTD,'MD0')
																              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_YIELD_OUTS> = OCONV(QTDOverUnder,'MD0,')
																          END
																          */
						********************************
						* End of Planning Calculations *
						********************************
						
						*IF RDSFiscalWeek = FiscalWeek THEN
						
						
						IF DayCol NE '' THEN
							DataArray<DayCol,ROW$TOT_REACTOR_OUTS>   = DataArray<DayCol,ROW$TOT_REACTOR_OUTS> + ReactorsOut
							DataArray<DayCol,ROW$TOT_YIELD_OUTS>     = DataArray<DayCol,ROW$TOT_YIELD_OUTS> + WafersOut
							DataArray<DayCol,ROW$TOT_CUST_SCRAP>    = DataArray<DayCol,ROW$TOT_CUST_SCRAP> + CustScrap
							DataArray<DayCol,ROW$TOT_EPI_SCRAP>     = DataArray<DayCol,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
							DataArray<DayCol,ROW$TOT_OTHER>         = DataArray<DayCol,ROW$TOT_OTHER> + OtherWafers
							
							IF DataArray<DayCol,ROW$TOT_YIELD_OUTS> > 0 THEN
								Yield = DataArray<DayCol,ROW$TOT_YIELD_OUTS> / (DataArray<DayCol,ROW$TOT_YIELD_OUTS> + DataArray<DayCol,ROW$TOT_EPI_SCRAP>)
							END ELSE
								Yield = 0
							END
							
							DataArray<DayCol,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
						END
						
						DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS>   = DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
						DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
						DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
						DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
						DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
						
						IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
							Yield = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
						END ELSE
							Yield = 0
						END
						DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
						
						* Scrap Rate
						IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
							ScrapRate = (DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>/DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>)*1000
						END ELSE
							ScrapRate = 0
						END
						DataArray<COL$WTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
						
						*END     ;*  End of check for current fiscal week
						
					END ;* End of RDS Record read
					
					Running = Msg(@WINDOW, MsgUp, LoopCnt, MSGINSTUPDATE$) 
					
					
				UNTIL ReactRunKeys = '' OR NOT(Running)
				REPEAT
				Msg(@WINDOW,MsgUp)
			end
		end
	Next a
	
	/* Fudge the dates - '~' is not inclusive of the end dates
			    StartDt = ICONV(StartDt,'D')
			    EndDt   = thisCutOffDt
			
			
			
			    SearchString = 'DATE_OUT':@VM:thisStartDt:'~':EndDt:@FM     ;**************
			
			    RDSKeys = ''
			    Option = ''
			    Flag = ''
			
			    Def = ""
			    Def<MTEXT$> = "Selecting RDS records..."
			    Def<MTYPE$> = "U"
			    MsgUp = Msg(@window, Def)   ;* display the processing message
			
			    Set_Status(0)
			    Btree.Extract(SearchString, 'RDS', @DICT, RDSKeys, Option, Flag)
			
			    Msg(@WINDOW, MsgUp)
			
			    IF Get_Status(errCode) THEN
			      ErrMsg(errCode)
			      RETURN
			    END
			
			    IF RDSKeys = '' THEN
			      ErrMsg('No RDS Records found for the current quarter!')
			      RETURN
			    END
			
			    RDSCnt  = COUNT(RDSKeys,@VM) + (RDSKeys NE '')
			    LoopCnt = 0
			    LastCheck = 0
			
			    Def = ""
			    Def<MCAPTION$>      = "Building Report..."
			    Def<MTYPE$>         = "GC"
			    Def<MEXTENT$>       = RDSCnt
			    Def<MTEXTWIDTH$>    = 600
			
			    AArray = ''
			    AATot = 0
			    MerProdRow = ''     ;* Moved from line 588 - dkk 1/13/14
			    CapFabRow = 9       ;* Moved from line 589 - dkk 1/13/14
			
			    MsgUp = Msg(@WINDOW, Def)
			    LOOP
			    	
			      @ID = RDSKeys[1,@VM]
			      RDSKeys[1,COL2()] = ''
			      LoopCnt += 1
			      
			      READ @RECORD FROM RDSTable,@ID THEN
			      
			          ReactorsOut = {WAFERS_IN}
			          AATot = AATot + ReactorsOut
			          
			          WafersOut = {WFRS_OUT_THRUPUT}
			       
			          AArray<LoopCnt,1> = @ID
			          AArray<LoopCnt,2> = AATot
			          AArray<LoopCnt,3> = ReactorsOut
			          
			          NCRKeys = @RECORD<RDS_NCR_KEYS$>
			          CustScrap   = {CUST_TOT_REJ}
			          IFXEpiScrap  = {LSL_TOT_REJ}
			          
			          TestKeys = XLATE('RDS_LAYER',@RECORD<RDS_RDS_LAYER_KEYS$>,3,'X')
			          TWProd = obj_RDS_Test('ProdTestCount',TestKeys)
			
			          SRPBillable = @RECORD<RDS_RESEARCH_SRP_BILLABLE$>
			          
			          OtherWafers = TWProd + SRPBillable
			          
			          Reactor = @RECORD<RDS_REACTOR$>
			          ReactorType = XLATE('REACTOR',Reactor,REACTOR_REACT_TYPE$ ,'X')
			          
			          BEGIN CASE
			              CASE ReactorType = 'ASM+'
			                  ReactTotRow         = ROW$ASMP_OUT
			                  ReactCustScrapRow   = ROW$ASMP_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$ASMP_EPI_SCRAP
			                  ReactOtherRow       = ROW$ASMP_OTHER
			                  ReactYieldRow       = ROW$ASMP_YIELD
			                  ReactScrapRateRow   = ROW$ASMP_SCRAP_RATE
			                  
			              CASE ReactorType = 'HTR'
			                  ReactTotRow         = ROW$HTR3_OUT
			                  ReactCustScrapRow   = ROW$HTR3_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$HTR3_EPI_SCRAP
			                  ReactOtherRow       = ROW$HTR3_OTHER
			                  ReactYieldRow       = ROW$HTR3_YIELD
			                  ReactScrapRateRow   = ROW$HTR3_SCRAP_RATE
			                  
			              CASE ReactorType = 'EPP'
			                  ReactTotRow         = ROW$EPIPRO_OUT
			                  ReactCustScrapRow   = ROW$EPIPRO_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$EPIPRO_EPI_SCRAP
			                  ReactOtherRow       = ROW$EPIPRO_OTHER
			                  ReactYieldRow       = ROW$EPIPRO_YIELD
			                  ReactScrapRateRow   = ROW$EPIPRO_SCRAP_RATE
			                  
			              CASE 1
			                  ReactTotRow         = ROW$ASM_OUT
			                  ReactCustScrapRow   = ROW$ASM_CUST_SCRAP
			                  ReactIFXEpiScrapRow  = ROW$ASM_EPI_SCRAP
			                  ReactOtherRow       = ROW$ASM_OTHER
			                  ReactYieldRow       = ROW$ASM_YIELD
			                  ReactScrapRateRow   = ROW$ASM_SCRAP_RATE
			                  
			          END CASE
			                  
			          CustNo = @RECORD<RDS_CUST_NO$>
			          
			          Captive   = 0 ; // Disable Captive
			          CustReportExclude = XLATE('COMPANY',CustNo,COMPANY_REPORT_EXCLUDE$,'X')
			          
			          Product = {PRODUCT}
			          DateOut = {DATE_OUT}
			          TimeOut = {TIME_OUT}
			          Day = MOD(DateOut,7)
			          
			          
			           
			          /*BEGIN CASE
			            CASE Day = 0 ; DayCol = COL$SUN
			            CASE Day = 1 ; DayCol = COL$MON
			            CASE Day = 2 ; DayCol = COL$TUE
			            CASE Day = 3 ; DayCol = COL$WED
			            CASE Day = 4 ; DayCol = COL$THU
			            CASE Day = 5 ; DayCol = COL$FRI
			            CASE Day = 6 ; DayCol = COL$SAT
			          END CASE
			          */
	/*
			          DateOut = OCONV(DateOut,'D4/')
			          TimeOut = OCONV(TimeOut,'MTS')
			          *debug
			          For a = 2 to DayColIndex
			          	*debug
			          	dateToCompare = DataArray<a,1>
						if dateToCompare EQ DateOut then
							 	DayCol = a
						end else
							DayCol = ''
						end
			          Next a
			          *debug
			          LogData     = ''
			          LogData<1>  = @ID
			          LogData<2>  = {WO}
			          LogData<3>  = DateOut
			          LogData<4>  = TimeOut
			          If ReactorsOut NE '' then            
			              LogData<5>  = ReactorsOut
			          end else
			              LogData<5> = 0
			          end
			          Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
			                        
			          
			          RDSFiscalWeek = obj_Calendar('IRFiscalWeek',DateOut)<1> ;* 2nd and 3rd fields are the start and end dates of the week
			          
			          BEGIN CASE
			              CASE Captive AND CustNo = '6593'
			                  CapFabRow = ROW$CAP_FAB2
			                  
			              CASE Captive AND (CustNo = '7053' OR CustNo = '7092' OR CustNo = '7102' OR CustNo = '7103' OR CustNo = '7108' )
			                  CapFabRow = ROW$CAP_FOUNDRY
			                              
			              CASE Captive AND CustNo = '6874' OR CustNo = '7055'
			                  IF {WAFER_MM} = '200 mm' THEN
			                      CapFabRow = ROW$CAP_FAB11
			                  END ELSE
			                      CapFabRow = ROW$CAP_FAB10
			                  END
			                  
			              CASE Captive AND CustNo = '7087'
			                  CapFabRow = ROW$CAP_FAB11
			                      
			              CASE NOT(Captive) AND Product _EQC '041-B/L'
			                  MerProdRow = ROW$MER_BL_OUT
			                  
			              CASE NOT(Captive) AND Product _EQC '044-Blanket'
			                  MerProdRow = ROW$MER_BLANKET_OUT
			                  
			              CASE 1
			                  NULL        
			          
			          END CASE
			          
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS>  = DataArray<COL$QTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$QTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$QTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
			          
			          Yield = DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
			          
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			
			          **********************
			          * IFX Scrap Rate Row *
			          **********************
			          IF DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
			              ScrapRate = (DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> / DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>) * 1000
			          END ELSE
			              ScrapRate = 0
			          END
			          DataArray<COL$QTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
			
			          **********************************
			          * Begin of Planning Calculations *
			          **********************************
			          /*
			          *************
			          * Scrap Row *
			          *************
			          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP>,'MD0'))
			          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP> = OCONV(QTDRem,'MD0,')
			          
			          IF PlanWorkingDays = 0 THEN
			              OrgDailyPlan = 0
			          END ELSE
			              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanDaysRem
			          END
			          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_EPI_SCRAP> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
			          
			          IF OrgDailyPlan NE 0 THEN
			              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_EPI_SCRAP>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
			              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_EPI_SCRAP> - PlanQTD,'MD0')
			              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_EPI_SCRAP> = OCONV(QTDOverUnder,'MD0,')
			          END
			      */
	/*
			          ******************
			          * Yield Outs Row *
			          ******************
			          QTDRem = (ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0') - ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS>,'MD0'))
			          DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS> = OCONV(QTDRem,'MD0,')
			          
			          IF PlanWorkingDays = 0 THEN
			              OrgDailyPlan = 0
			          END ELSE
			              OrgDailyPlan = ICONV(DataArray<COL$QTD_MF_REMAIN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanDaysRem
			          END
			          DataArray<COL$ORG_MF_DAILY_PLAN,ROW$TOT_YIELD_OUTS> = OCONV(ICONV(OrgDailyPlan,'MD0'),'MD0')
			          
			          IF OrgDailyPlan NE 0 THEN
			              PlanQTD = ICONV((ICONV(DataArray<COL$QTD_MF_PLAN,ROW$TOT_YIELD_OUTS>,'MD0')/PlanWorkingDays)*DaysWorked,'MD0')
			              QTDOverUnder = ICONV(DataArray<COL$QTD_ACTUAL,ROW$TOT_YIELD_OUTS> - PlanQTD,'MD0')
			              DataArray<COL$QTD_MF_OVER_UNDER,ROW$TOT_YIELD_OUTS> = OCONV(QTDOverUnder,'MD0,')
			          END
			          
			          ********************************
			          * End of Planning Calculations *
			          ********************************
			          
			          *IF RDSFiscalWeek = FiscalWeek THEN
			              
			                      
			              IF DayCol NE '' THEN
			                  DataArray<DayCol,ROW$TOT_REACTOR_OUTS>   = DataArray<DayCol,ROW$TOT_REACTOR_OUTS> + ReactorsOut
			                  DataArray<DayCol,ROW$TOT_YIELD_OUTS>     = DataArray<DayCol,ROW$TOT_YIELD_OUTS> + WafersOut
			                  DataArray<DayCol,ROW$TOT_CUST_SCRAP>    = DataArray<DayCol,ROW$TOT_CUST_SCRAP> + CustScrap
			                  DataArray<DayCol,ROW$TOT_EPI_SCRAP>     = DataArray<DayCol,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
			                  DataArray<DayCol,ROW$TOT_OTHER>         = DataArray<DayCol,ROW$TOT_OTHER> + OtherWafers
			                  
			                  IF DataArray<DayCol,ROW$TOT_YIELD_OUTS> > 0 THEN
			                      Yield = DataArray<DayCol,ROW$TOT_YIELD_OUTS> / (DataArray<DayCol,ROW$TOT_YIELD_OUTS> + DataArray<DayCol,ROW$TOT_EPI_SCRAP>)
			                  END ELSE
			                      Yield = 0
			                  END
			                  
			                  DataArray<DayCol,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			              END
			                  
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS>   = DataArray<COL$WTD_ACTUAL,ROW$TOT_REACTOR_OUTS> + ReactorsOut
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + WafersOut
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP>    = DataArray<COL$WTD_ACTUAL,ROW$TOT_CUST_SCRAP> + CustScrap
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>     = DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP> + IFXEpiScrap
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER>         = DataArray<COL$WTD_ACTUAL,ROW$TOT_OTHER> + OtherWafers
			              
			              IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
			                  Yield = DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> / (DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> + DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>)
			              END ELSE
			                  Yield = 0
			              END
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD> = OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
			              
			              * Scrap Rate
			              IF DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS> > 0 THEN
			                  ScrapRate = (DataArray<COL$WTD_ACTUAL,ROW$TOT_EPI_SCRAP>/DataArray<COL$WTD_ACTUAL,ROW$TOT_YIELD_OUTS>)*1000
			              END ELSE
			                  ScrapRate = 0
			              END
			              DataArray<COL$WTD_ACTUAL,ROW$TOT_SCRAP_RATE> = OCONV(ICONV(ScrapRate,'MD2'),'MD2')
			                                                          
			          *END     ;*  End of check for current fiscal week
			
			      END ;* End of RDS Record read
			      
			      Running = Msg(@WINDOW, MsgUp, LoopCnt, MSGINSTUPDATE$) 
			      
			      
			    UNTIL RDSKeys = '' OR NOT(Running)
			    REPEAT*/
	
	GaNArray = DataArray
	Msg(@WINDOW,MsgUp)
	
	* * * * * * * * *	
SendToExcel:
* * * * * * * * *
	
	xlApp = OleCreateInstance("excel.Application")                              ;* Create instance of Excel
	OlePutProperty(XlApp, 'Visible', xlSheetVisible)
	if OleStatus() then Goto HadError
	
	xlWorkBooks =OleGetProperty(xlApp, "Workbooks")                             ;* Create workbook
	xlWkb = OleCallMethod(xlWorkbooks,"Add")
	if OleStatus() then Goto HadError
	
	
	****Si
	xlSht = OleGetProperty(xlWkb, "Worksheets",1)                               ;* Select worksheet 1
	if OleStatus() then Goto HadError
	
	xlPageSetup = OleGetProperty(xlSht,"PageSetup")                             ;* Get PageSetup object for Page/Printing stuff
	if OleStatus() then GOTO HadError
	
	OlePutProperty( xlPageSetup , 'PrintGridLines', xlTrue )
	OlePutProperty( xlSht , 'Worksheet.Name', 'Silicon' )                                        ;* Print Gridlines on
	OlePutProperty( xlPageSetup , 'Orientation' , xlLandscape )                                     ;* Orientation to Landscape
	OlePutProperty( xlPageSetup , 'HeaderMargin', '20')                                             ;* HeaderMargin to 20pts
	
	OlePutProperty( xlPageSetup , 'CenterHeader' , '&14Epi SERVICES - Thruput Report - w/o Makeup Activity' )       ;* Set Center Header
	OlePutProperty( xlPageSetup , 'LeftHeader' , '&G' )                                             ;* Set graphic in Left Header
	
	graphic = OleGetProperty( xlPageSetup , 'LeftHeaderPicture' )                                   ;* Get graphic object for Left Header Picture
	OlePutProperty( graphic , 'FileName' , 'R:\Oinsight\BMPS\EpiSvcs.png' )                         ;* Set filename for graphic
	OlePutProperty( graphic , 'Height' , '51.75' )                                                  ;* Scale graphic to fit header      
	OlePutProperty( graphic , 'Width' , '81')
	
	OlePutProperty( xlPageSetup , 'RightHeader' , 'Page &P' )                   ;* Set Right Header to show current page number
	
	
	ColCnt = COUNT(SiArray,@FM) + (SiArray NE '')
	LineCnt = COUNT(SiArray<1>,@VM) + (SiArray<1> NE '')
	FOR LineNo = 1 TO LineCnt
		FOR Column = 1 to ColCnt
			RangeColumn = eXcelCols<1,Column>
			range = OleGetProperty( xlSht, 'Range',RangeColumn:LineNo)
			OlePutProperty(range, 'Value', SiArray<Column,LineNo>)            ;* Load report array into spreadsheet cells
			IF OleStatus() THEN GOTO HadError
		NEXT Column
	NEXT LineCnt
	
	LastColumn = eXcelCols<1,ColCnt>
	range = OleGetProperty( xlSht, 'Range','B1:':LastColumn:'1')                ;* Turn on word wrap in columns from B through end
	OlePutProperty( range, 'WrapText', xlTrue)
	IF OleStatus() THEN GOTO HadError
	
	RangeColumn = eXcelCols<1,ColCnt>
	range = OleGetProperty( xlSht, 'Range','A1:':RangeColumn:LineCnt)
	
	Void = OleCallMethod( range, 'AutoFormat', xlRangeAutoFormatClassic1 )      ;* Turn on autoformat (FormatClassic1)
	IF OleStatus() THEN GOTO HadError
	
	FOR I = 2 TO DayColIndex
		eXcelCol = eXcelCols<1,I>
		column = OleGetProperty( xlSht, 'Range' , eXcelCol:':':exCelCol )       ;* Set the day columns to a standard width
		OlePutProperty( column , 'ColumnWidth' , '10.6' )                       ;* Originally 10.3 - changed to 10.6 to fit Wednesday - dkk 12/30/13
		a = OleStatus()
	NEXT I
	
	EdgeList = xlDiagonalDown:@VM:xlDiagonalup:@VM:xlEdgeLeft:@VM:xlEdgeTop:@VM:xlEdgeRight:@VM:xlInsideVertical
	
	* Put border on the BOTTOM of this row
	
	range = OleGetProperty( xlSht, 'Range', 'A':ROW$TOT_SHIP:':':RangeColumn:ROW$TOT_SHIP)
	
	FOR I = 1 TO COUNT(EdgeList,@VM) + (EdgeList NE '')
		edge = OleGetProperty( range, 'Borders' , EdgeList<1,I> )
		OlePutProperty( edge , 'LineStyle' , xlLineStyleNone )                  ;* Clear border segments EXCEPT bottom
	NEXT I
	* Set border segment for bottom to medium weight line
	edge = OleGetProperty( range, 'Borders' , xlEdgeBottom )                    
	olePutProperty( edge , 'LineStyle', xlContinuous )
	olePutProperty( edge , 'Weight' , xlMedium )
	olePutProperty( edge , 'ColorIndex', xlColorIndexAutomatic )
	
	
	***GaN
	
	xlSht = OleGetProperty(xlWkb, "Worksheets",2)                               ;* Select worksheet 1
	if OleStatus() then Goto HadError
	
	xlPageSetup = OleGetProperty(xlSht,"PageSetup")                             ;* Get PageSetup object for Page/Printing stuff
	if OleStatus() then GOTO HadError
	
	OlePutProperty( xlPageSetup , 'PrintGridLines', xlTrue )                                        ;* Print Gridlines on
	OlePutProperty( xlPageSetup , 'Orientation' , xlLandscape )                                     ;* Orientation to Landscape
	OlePutProperty( xlPageSetup , 'HeaderMargin', '20')                                             ;* HeaderMargin to 20pts
	
	OlePutProperty( xlPageSetup , 'CenterHeader' , '&14Epi SERVICES - Thruput Report - w/o Makeup Activity' )       ;* Set Center Header
	OlePutProperty( xlPageSetup , 'LeftHeader' , '&G' )                                             ;* Set graphic in Left Header
	
	graphic = OleGetProperty( xlPageSetup , 'LeftHeaderPicture' )                                   ;* Get graphic object for Left Header Picture
	OlePutProperty( graphic , 'FileName' , 'R:\Oinsight\BMPS\EpiSvcs.png' )                         ;* Set filename for graphic
	OlePutProperty( graphic , 'Height' , '51.75' )                                                  ;* Scale graphic to fit header      
	OlePutProperty( graphic , 'Width' , '81')
	
	OlePutProperty( xlPageSetup , 'RightHeader' , 'Page &P' )                   ;* Set Right Header to show current page number
	
	
	ColCnt = COUNT(GaNArray,@FM) + (GaNArray NE '')
	LineCnt = COUNT(GaNArray<1>,@VM) + (GaNArray<1> NE '')
	FOR LineNo = 1 TO LineCnt
		FOR Column = 1 to ColCnt
			RangeColumn = eXcelCols<1,Column>
			range = OleGetProperty( xlSht, 'Range',RangeColumn:LineNo)
			OlePutProperty(range, 'Value', GaNArray<Column,LineNo>)            ;* Load report array into spreadsheet cells
			IF OleStatus() THEN GOTO HadError
		NEXT Column
	NEXT LineCnt
	
	LastColumn = eXcelCols<1,ColCnt>
	range = OleGetProperty( xlSht, 'Range','B1:':LastColumn:'1')                ;* Turn on word wrap in columns from B through end
	OlePutProperty( range, 'WrapText', xlTrue)
	IF OleStatus() THEN GOTO HadError
	
	RangeColumn = eXcelCols<1,ColCnt>
	range = OleGetProperty( xlSht, 'Range','A1:':RangeColumn:LineCnt)
	
	Void = OleCallMethod( range, 'AutoFormat', xlRangeAutoFormatClassic1 )      ;* Turn on autoformat (FormatClassic1)
	IF OleStatus() THEN GOTO HadError
	
	FOR I = 2 TO DayColIndex
		eXcelCol = eXcelCols<1,I>
		column = OleGetProperty( xlSht, 'Range' , eXcelCol:':':exCelCol )       ;* Set the day columns to a standard width
		OlePutProperty( column , 'ColumnWidth' , '10.6' )                       ;* Originally 10.3 - changed to 10.6 to fit Wednesday - dkk 12/30/13
		a = OleStatus()
	NEXT I
	
	EdgeList = xlDiagonalDown:@VM:xlDiagonalup:@VM:xlEdgeLeft:@VM:xlEdgeTop:@VM:xlEdgeRight:@VM:xlInsideVertical
	
	* Put border on the BOTTOM of this row
	
	range = OleGetProperty( xlSht, 'Range', 'A':ROW$TOT_SHIP:':':RangeColumn:ROW$TOT_SHIP)
	
	FOR I = 1 TO COUNT(EdgeList,@VM) + (EdgeList NE '')
		edge = OleGetProperty( range, 'Borders' , EdgeList<1,I> )
		OlePutProperty( edge , 'LineStyle' , xlLineStyleNone )                  ;* Clear border segments EXCEPT bottom
	NEXT I
	* Set border segment for bottom to medium weight line
	edge = OleGetProperty( range, 'Borders' , xlEdgeBottom )                    
	olePutProperty( edge , 'LineStyle', xlContinuous )
	olePutProperty( edge , 'Weight' , xlMedium )
	olePutProperty( edge , 'ColorIndex', xlColorIndexAutomatic )
	
	
	* Save to local drive
	Void = OleCallMethod( xlWkb, 'SaveAs',Environment_Services('GetReportsRootPath') : '\ThruPut.xls', xlWorkbookNormal)        
	
RETURN


* * * * * * *
HadError:
* * * * * * *
	
	xlChart = ''
	Charts = ''
	range = ''
	xlSht = ''
	xlWkb=''
	xlWorkBooks = ''
	x = OleCallMethod(xlApp, 'Quit')
	
RETURN 

