COMPILE SUBROUTINE REPORT_THRUPUT_MONTH(Dummy)

* 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
DECLARE FUNCTION Msg, Get_Status, obj_Calendar, Utility, SetInitDirOptions, Dialog_Box, obj_RDS_Test, Environment_Services

$INSERT RDS_EQU
$INSERT COMPANY_EQU
$INSERT REACTOR_EQUATES
$INSERT MSG_EQUATES
$INSERT POPUP_EQUATES
$INSERT LOGICAL
$INSERT EXCEL_EQU

EQU ROW$TOT_OUT				TO 2
EQU ROW$TOT_CUST_SCRAP		TO 3
EQU ROW$TOT_EPI_SCRAP		TO 4
EQU ROW$TOT_OTHER			TO 5
EQU ROW$TOT_YIELD			TO 6

EQU ROW$CAP_OUT				TO 8
EQU ROW$CAP_FOUNDRY			TO 9
EQU ROW$CAP_FAB2			TO 10
EQU ROW$CAP_FAB10			TO 11
EQU ROW$CAP_FAB11			TO 12

EQU ROW$CAP_CUST_SCRAP		TO 13
EQU ROW$CAP_EPI_SCRAP		TO 14
EQU ROW$CAP_OTHER			TO 15
EQU ROW$CAP_YIELD			TO 16

EQU ROW$MER_TOT_OUT			TO 18
EQU ROW$MER_BL_OUT			TO 19
EQU ROW$MER_BLANKET_OUT		TO 20
EQU ROW$MER_CUST_SCRAP		TO 21
EQU ROW$MER_EPI_SCRAP		TO 22
EQU ROW$MER_OTHER			TO 23
EQU ROW$MER_YIELD			TO 24

EQU ROW$ASMP_OUT			TO 26
EQU ROW$ASMP_CUST_SCRAP		TO 27
EQU ROW$ASMP_EPI_SCRAP		TO 28
EQU ROW$ASMP_OTHER			TO 29
EQU ROW$ASMP_YIELD			TO 30

EQU ROW$ASM_OUT				TO 32
EQU ROW$ASM_CUST_SCRAP		TO 33
EQU ROW$ASM_EPI_SCRAP		TO 34
EQU ROW$ASM_OTHER			TO 35
EQU ROW$ASM_YIELD			TO 36

EQU ROW$HTR3_OUT			TO 38
EQU ROW$HTR3_CUST_SCRAP		TO 39
EQU ROW$HTR3_EPI_SCRAP		TO 40
EQU ROW$HTR3_OTHER			TO 41
EQU ROW$HTR3_YIELD			TO 42

EQU ROW$EPIPRO_OUT			TO 44
EQU ROW$EPIPRO_CUST_SCRAP	TO 45
EQU ROW$EPIPRO_EPI_SCRAP	TO 46
EQU ROW$EPIPRO_OTHER		TO 47
EQU ROW$EPIPRO_YIELD		TO 48

EQU COL$M1		TO 2
EQU COL$M2		TO 3
EQU COL$M3		TO 4
EQU COL$M4		TO 5
EQU COL$M5		TO 6
EQU COL$M6		TO 7
EQU COL$M7		TO 8
EQU COL$M8		TO 9
EQU COL$M9		TO 10
EQU COL$M10		TO 11
EQU COL$M11		TO 12
EQU COL$M12		TO 13
EQU COL$YTD		TO 14

EQU COL$PERIOD			TO 15
EQU COL$PERIOD_VALUE	TO 16
EQU COL$PERIOD_START	TO 17
EQU COL$PERIOD_END		TO 18

EQU CRLF$ TO \0D0A\

Main:
    
    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

    DataArray = ''
    DataArray<1,ROW$TOT_OUT>			= 'Total Out'
    DataArray<1,ROW$TOT_CUST_SCRAP>		= '  Cust  Scrap'
    DataArray<1,ROW$TOT_EPI_SCRAP>		= '  IREP Scrap'
    DataArray<1,ROW$TOT_OTHER>			= '  Prod Test'
    DataArray<1,ROW$TOT_YIELD>			= '  Yield'

    DataArray<1,ROW$CAP_OUT>			= 'Captive Out'
    DataArray<1,ROW$CAP_FAB2>			= '  Fab 2'
    DataArray<1,ROW$CAP_FOUNDRY>			= '  Foundry'
    DataArray<1,ROW$CAP_FAB10>			= '  Fab 10'
    DataArray<1,ROW$CAP_FAB11>			= '  Fab 11'
    DataArray<1,ROW$CAP_CUST_SCRAP>		= '  Cust Scrap'
    DataArray<1,ROW$CAP_EPI_SCRAP>		= '  IREP Scrap'
    DataArray<1,ROW$CAP_OTHER>			= '  Prod Test'
    DataArray<1,ROW$CAP_YIELD>			= '  Yield'

    DataArray<1,ROW$MER_TOT_OUT>		= 'Merchant Out'
    DataArray<1,ROW$MER_BL_OUT>			= '  B/L'
    DataArray<1,ROW$MER_BLANKET_OUT>	= '  Blanket'
    DataArray<1,ROW$MER_CUST_SCRAP>			= '  Cust Scrap'
    DataArray<1,ROW$MER_EPI_SCRAP>			= '  IREP Scrap'
    DataArray<1,ROW$MER_OTHER>			= '  Prod Test'
    DataArray<1,ROW$MER_YIELD>			= '  Yield'

    DataArray<1,ROW$ASMP_OUT>			= 'ASM+ Out'
    DataArray<1,ROW$ASMP_CUST_SCRAP>	= '   Cust Scrap'
    DataArray<1,ROW$ASMP_EPI_SCRAP>		= '   IREP Scrap'
    DataArray<1,ROW$ASMP_OTHER>			= '   Prod Test'
    DataArray<1,ROW$ASMP_YIELD>			= '   Yield'

    DataArray<1,ROW$ASM_OUT>			= 'ASM Out'
    DataArray<1,ROW$ASM_CUST_SCRAP>		= '   Cust Scrap'
    DataArray<1,ROW$ASM_EPI_SCRAP>		= '   IREP Scrap'
    DataArray<1,ROW$ASM_OTHER>			= '   Prod Test'
    DataArray<1,ROW$ASM_YIELD>			= '   Yield'

    DataArray<1,ROW$HTR3_OUT>			= 'HTR3 Out'
    DataArray<1,ROW$HTR3_CUST_SCRAP>	= '   Cust Scrap'
    DataArray<1,ROW$HTR3_EPI_SCRAP>		= '   IREP Scrap'
    DataArray<1,ROW$HTR3_OTHER>			= '   Prod Test'
    DataArray<1,ROW$HTR3_YIELD>			= '   Yield'

    DataArray<1,ROW$EPIPRO_OUT>			= 'EpiPRO Out'
    DataArray<1,ROW$EPIPRO_CUST_SCRAP>	= '   Cust Scrap'
    DataArray<1,ROW$EPIPRO_EPI_SCRAP>	= '   IREP Scrap'
    DataArray<1,ROW$EPIPRO_OTHER>		= '   Prod Test'
    DataArray<1,ROW$EPIPRO_YIELD>		= '   Yield'

    DataArray<COL$M1,1>					= 'Month 1'		;* put this AFTER the data load
    DataArray<COL$M2,1>					= 'Month 2'
    DataArray<COL$M3,1>					= 'Month 3'
    DataArray<COL$M4,1>					= 'Month 4'
    DataArray<COL$M5,1>					= 'Month 5'
    DataArray<COL$M6,1>					= 'Month 6'
    DataArray<COL$M7,1>					= 'Month 7'
    DataArray<COL$M8,1>					= 'Month 8'
    DataArray<COL$M9,1>					= 'Month 9'
    DataArray<COL$M10,1>				= 'Month 10'
    DataArray<COL$M11,1>				= 'Month 11'
    DataArray<COL$M12,1>				= 'Month 12'
    DataArray<COL$YTD,1>				= 'YTD Total'


    FiscalYear = Popup(@WINDOW,'','IR_FISCAL_YEAR')
    FYStartDt = FiscalYear<1,2>
    FYEndDt = OCONV(ICONV(FYStartDt,'D') + 363,'D4-')


    DataArray<COL$PERIOD,1>				= 'Period'
    DataArray<COL$PERIOD_VALUE,1>		= ''
    DataArray<COL$PERIOD_START,1>		= 'Start Date'
    DataArray<COL$PERIOD_END,1>			= 'End Date'

    DataArray<COL$PERIOD,3>				= 'Fiscal Year'
    DataArray<COL$PERIOD_VALUE,3>		= FiscalYear<1,1>
    DataArray<COL$PERIOD_START,3>		= FYStartDt
    DataArray<COL$PERIOD_END,3>			= FYEndDt

    DataArray<COL$PERIOD,5>				= 'Ran At'
    DataArray<COL$PERIOD_VALUE,5>		= ''
    DataArray<COL$PERIOD_START,5>		= OCONV(Date(),'D4/')
    DataArray<COL$PERIOD_END,5>			= OCONV(Time(),'MTH')


    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


    * Fudge the dates - '~' is not inclusive of the end dates

    StartDt = ICONV(FYStartDt,'D') - 1
    EndDt 	= ICONV(FYEndDt,'D') + 1

    SearchString = 'DATE_OUT':@VM:StartDt:'~':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)
    errCode = ''
    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

    Def = ""
    Def<MCAPTION$>		= "Building Report..."
    Def<MTYPE$>			= "GC"
    Def<MEXTENT$>		= RDSCnt
    Def<MTEXTWIDTH$>	= 600


    MsgUp = Msg(@WINDOW, Def)

    LOOP
        @ID = RDSKeys[1,@VM]
        RDSKeys[1,COL2()] = ''
        LoopCnt += 1
        
        READ @RECORD FROM RDSTable,@ID THEN
        
            WafersOut = {WFRS_OUT_NOMU}
            
            NCRKeys = @RECORD<RDS_NCR_KEYS$>
            CustScrap	= {CUST_TOT_REJ}
            IREpiScrap	= {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
                    ReactIREpiScrapRow	= ROW$ASMP_EPI_SCRAP
                    ReactOtherRow		= ROW$ASMP_OTHER
                    ReactYieldRow		= ROW$ASMP_YIELD
                    
                CASE ReactorType = 'HTR'
                    ReactTotRow			= ROW$HTR3_OUT
                    ReactCustScrapRow	= ROW$HTR3_CUST_SCRAP
                    ReactIREpiScrapRow	= ROW$HTR3_EPI_SCRAP
                    ReactOtherRow		= ROW$HTR3_OTHER
                    ReactYieldRow		= ROW$HTR3_YIELD
                    
                CASE ReactorType = 'EPP'
                    ReactTotRow			= ROW$EPIPRO_OUT
                    ReactCustScrapRow	= ROW$EPIPRO_CUST_SCRAP
                    ReactIREpiScrapRow	= ROW$EPIPRO_EPI_SCRAP
                    ReactOtherRow		= ROW$EPIPRO_OTHER
                    ReactYieldRow		= ROW$EPIPRO_YIELD
                    
                CASE 1
                    ReactTotRow			= ROW$ASM_OUT
                    ReactCustScrapRow	= ROW$ASM_CUST_SCRAP
                    ReactIREpiScrapRow	= ROW$ASM_EPI_SCRAP
                    ReactOtherRow		= ROW$ASM_OTHER
                    ReactYieldRow		= ROW$ASM_YIELD
                    
            END CASE
                    
            CustNo = @RECORD<RDS_CUST_NO$>
            
            Captive = {CUST_CAPTIVE}
            CustReportExclude = XLATE('COMPANY',CustNo,COMPANY_REPORT_EXCLUDE$,'X')
            
            Product = {PRODUCT}
            DateOut = {DATE_OUT}
            RDSMonthData = obj_Calendar('IRFiscalMonth',OCONV(DateOut,'D4-'))
            
            MonthCol = RDSMonthData<1> + 1		;* Leave room on the left for the category labels
            MonthStartDt = RDSMonthData<2>
            MonthEndDt	= RDSMonthData<3>
            
            IF FIELD(DataArray<MonthCol,1>,' ',3) = '' THEN
                DataArray<MonthCol,1> = DataArray<MonthCol,1>:' ':MonthStartDt:' ':MonthEndDt
            END
            
            DateOut = OCONV(DateOut,'D4/')
            
            IF NOT(CustReportExclude) THEN
                BEGIN CASE
                    CASE Captive AND CustNo = '6593'
                        CapFabRow = ROW$CAP_FAB2
                        
                    CASE Captive AND (CustNo = '7053' OR CustNo = '7102' OR CustNo = '7108')
                        CapFabRow = ROW$CAP_FOUNDRY
                                    
                    CASE Captive AND CustNo = '6874'
                        IF {WAFER_MM} = '200 mm' THEN
                            CapFabRow = ROW$CAP_FAB11
                        END ELSE
                            CapFabRow = ROW$CAP_FAB10
                        END
                            
                    CASE NOT(Captive) AND Product = '041-B/L'
                        MerProdRow = ROW$MER_BL_OUT
                        
                    CASE NOT(Captive) AND Product = '044-Blanket'
                        MerProdRow = ROW$MER_BLANKET_OUT
                        
                    CASE 1
                        MerProdRow = ''
                        
                END CASE
                
                IF Captive OR MerProdRow NE '' THEN
                                        
                    DataArray<COL$YTD,ROW$TOT_OUT>			= DataArray<COL$YTD,ROW$TOT_OUT> + WafersOut
                    DataArray<COL$YTD,ROW$TOT_CUST_SCRAP>	= DataArray<COL$YTD,ROW$TOT_CUST_SCRAP> + CustScrap
                    DataArray<COL$YTD,ROW$TOT_EPI_SCRAP>	= DataArray<COL$YTD,ROW$TOT_EPI_SCRAP> + IREpiScrap
                    DataArray<COL$YTD,ROW$TOT_OTHER>		= DataArray<COL$YTD,ROW$TOT_OTHER> + OtherWafers
                    
                    IF DataArray<COL$YTD,ROW$TOT_OUT> > 0 THEN
                        Yield = DataArray<COL$YTD,ROW$TOT_OUT>/(DataArray<COL$YTD,ROW$TOT_OUT> + DataArray<COL$YTD,ROW$TOT_EPI_SCRAP>)
                    END ELSE
                        Yield = 0
                    END
                    
                    DataArray<COL$YTD,ROW$TOT_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                    
                    DataArray<MonthCol,ROW$TOT_OUT>			= DataArray<MonthCol,ROW$TOT_OUT> + WafersOut
                    DataArray<MonthCol,ROW$TOT_CUST_SCRAP>	= DataArray<MonthCol,ROW$TOT_CUST_SCRAP> + CustScrap
                    DataArray<MonthCol,ROW$TOT_EPI_SCRAP>	= DataArray<MonthCol,ROW$TOT_EPI_SCRAP> + IREpiScrap
                    DataArray<MonthCol,ROW$TOT_OTHER>		= DataArray<MonthCol,ROW$TOT_OTHER> + OtherWafers
                    
                    IF DataArray<MonthCol,ROW$TOT_OUT> > 0 THEN
                        Yield = DataArray<MonthCol,ROW$TOT_OUT>/(DataArray<MonthCol,ROW$TOT_OUT> + DataArray<MonthCol,ROW$TOT_EPI_SCRAP>)
                    END ELSE
                        Yield = 0
                    END
                    
                    DataArray<MonthCol,ROW$TOT_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                                
                    IF Captive THEN
                    
                        DataArray<COL$YTD,ROW$CAP_OUT>			= DataArray<COL$YTD,ROW$CAP_OUT> + WafersOut
                        DataArray<COL$YTD,CapFabRow>			= DataArray<COL$YTD,CapFabRow> + WafersOut
                        DataArray<COL$YTD,ROW$CAP_CUST_SCRAP>	= DataArray<COL$YTD,ROW$CAP_CUST_SCRAP> + CustScrap
                        DataArray<COL$YTD,ROW$CAP_EPI_SCRAP>	= DataArray<COL$YTD,ROW$CAP_EPI_SCRAP> + IREpiScrap
                        DataArray<COL$YTD,ROW$CAP_OTHER>		= DataArray<COL$YTD,ROW$CAP_OTHER> + OtherWafers
                        
                        IF DataArray<COL$YTD,ROW$CAP_OUT> > 0 THEN
                            Yield = DataArray<COL$YTD,ROW$CAP_OUT> / ( DataArray<COL$YTD,ROW$CAP_OUT> + DataArray<COL$YTD,ROW$CAP_EPI_SCRAP> )
                        END ELSE
                            Yield = 0
                        END
                        
                        DataArray<COL$YTD,ROW$CAP_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                        
                        DataArray<MonthCol,ROW$CAP_OUT>			= DataArray<MonthCol,ROW$CAP_OUT> + WafersOut
                        DataArray<MonthCol,CapFabRow>			= DataArray<MonthCol,CapFabRow> + WafersOut
                        DataArray<MonthCol,ROW$CAP_CUST_SCRAP>	= DataArray<MonthCol,ROW$CAP_CUST_SCRAP> + CustScrap
                        DataArray<MonthCol,ROW$CAP_EPI_SCRAP>	= DataArray<MonthCol,ROW$CAP_EPI_SCRAP> + IREpiScrap
                        DataArray<MonthCol,ROW$CAP_OTHER>		= DataArray<MonthCol,ROW$CAP_OTHER> + OtherWafers
                        
                        IF DataArray<MonthCol,ROW$CAP_OUT> > 0 THEN
                            Yield = DataArray<MonthCol,ROW$CAP_OUT> / ( DataArray<MonthCol,ROW$CAP_OUT> + DataArray<MonthCol,ROW$CAP_EPI_SCRAP> )
                        END ELSE
                            Yield = 0
                        END
                        
                        DataArray<MonthCol,ROW$CAP_YIELD>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                                
                    END ELSE
                    
                        DataArray<COL$YTD,ROW$MER_TOT_OUT>		= DataArray<COL$YTD,ROW$MER_TOT_OUT> + WafersOut
                        DataArray<COL$YTD,MerProdRow>			= DataArray<COL$YTD,MerProdRow> + WafersOut
                        DataArray<COL$YTD,ROW$MER_CUST_SCRAP>	= DataArray<COL$YTD,ROW$MER_CUST_SCRAP> + CustScrap
                        DataArray<COL$YTD,ROW$MER_EPI_SCRAP>	= DataArray<COL$YTD,ROW$MER_EPI_SCRAP> + IREpiScrap
                        DataArray<COL$YTD,ROW$MER_OTHER>		= DataArray<COL$YTD,ROW$MER_OTHER> + OtherWafers
                        
                        IF DataArray<COL$YTD,ROW$MER_TOT_OUT> > 0 THEN
                            Yield = DataArray<COL$YTD,ROW$MER_TOT_OUT> / ( DataArray<COL$YTD,ROW$MER_TOT_OUT> + DataArray<COL$YTD,ROW$MER_EPI_SCRAP> )
                        END ELSE
                            Yield = 0
                        END
                        
                        DataArray<COL$YTD,ROW$MER_YIELD>		= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                        
                        DataArray<MonthCol,ROW$MER_TOT_OUT>		= DataArray<MonthCol,ROW$MER_TOT_OUT> + WafersOut
                        DataArray<MonthCol,MerProdRow>			= DataArray<MonthCol,MerProdRow> + WafersOut
                        DataArray<MonthCol,ROW$MER_CUST_SCRAP>	= DataArray<MonthCol,ROW$MER_CUST_SCRAP> + CustScrap
                        DataArray<MonthCol,ROW$MER_EPI_SCRAP>	= DataArray<MonthCol,ROW$MER_EPI_SCRAP> + IREpiScrap
                        DataArray<MonthCol,ROW$MER_OTHER>		= DataArray<MonthCol,ROW$MER_OTHER> + OtherWafers
                        
                        IF DataArray<MonthCol,ROW$MER_TOT_OUT> > 0 THEN
                            Yield = DataArray<MonthCol,ROW$MER_TOT_OUT> / ( DataArray<MonthCol,ROW$MER_TOT_OUT> + DataArray<MonthCol,ROW$MER_EPI_SCRAP> )
                        END ELSE
                            Yield = 0
                        END
                        
                        DataArray<MonthCol,ROW$MER_YIELD>		= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')

                    END
                    
                    DataArray<COL$YTD,ReactTotRow>			= DataArray<COL$YTD,ReactTotRow> + WafersOut
                    DataArray<COL$YTD,ReactCustScrapRow>	= DataArray<COL$YTD,ReactCustScrapRow> + CustScrap
                    DataArray<COL$YTD,ReactIREpiScrapRow>	= DataArray<COL$YTD,ReactIREpiScrapRow> + IREpiScrap
                    DataArray<COL$YTD,ReactOtherRow>		= DataArray<COL$YTD,ReactOtherRow> + OtherWafers
                    
                    IF DataArray<COL$YTD,ReactTotRow> > 0 THEN
                        Yield = DataArray<COL$YTD,ReactTotRow> / ( DataArray<COL$YTD,ReactTotRow> + DataArray<COL$YTD,ReactIREpiScrapRow> )
                    END ELSE
                        Yield = 0
                    END
                    
                    DataArray<COL$YTD,ReactYieldRow>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                    
                    DataArray<MonthCol,ReactTotRow>			= DataArray<MonthCol,ReactTotRow> + WafersOut
                    DataArray<MonthCol,ReactCustScrapRow>	= DataArray<MonthCol,ReactCustScrapRow> + CustScrap
                    DataArray<MonthCol,ReactIREpiScrapRow>	= DataArray<MonthCol,ReactIREpiScrapRow> + IREpiScrap
                    DataArray<MonthCol,ReactOtherRow>		= DataArray<MonthCol,ReactOtherRow> + OtherWafers
                    
                    IF DataArray<MonthCol,ReactTotRow> > 0 THEN
                        Yield = DataArray<MonthCol,ReactTotRow> / ( DataArray<MonthCol,ReactTotRow> + DataArray<MonthCol,ReactIREpiScrapRow> )
                    END ELSE
                        Yield = 0
                    END
                    
                    DataArray<MonthCol,ReactYieldRow>	= OCONV(ICONV(Yield*100,'MD2'),'MD2S%')
                    
                END		;* End of check for Merchant and unknown Product code
            END		;* End of check for Report Exclude flag on customer

        END	;* End of RDS Record read
        
        Running = Msg(@WINDOW, MsgUp, LoopCnt, MSGINSTUPDATE$) 
        
    UNTIL RDSKeys = '' OR NOT(Running)
    REPEAT

    FOR I = ROW$TOT_OUT TO ROW$TOT_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    FOR I = ROW$CAP_OUT TO ROW$CAP_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    FOR I = ROW$MER_TOT_OUT TO ROW$MER_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    FOR I = ROW$ASMP_OUT TO ROW$ASMP_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    FOR I = ROW$ASM_OUT TO ROW$ASM_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    FOR I = ROW$HTR3_OUT TO ROW$HTR3_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    FOR I = ROW$EPIPRO_OUT TO ROW$EPIPRO_OTHER
        FOR J = COL$M1 TO COL$YTD
            DataArray<J,I> = OCONV(DataArray<J,I>,'MD0,Z')
        NEXT J
    NEXT I

    Msg(@WINDOW,MsgUp)


    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

    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 )										;* 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(DataArray,@FM) + (DataArray NE '')
    LineCnt = COUNT(DataArray<1>,@VM) + (DataArray<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', DataArray<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 = COL$M1 TO COL$YTD
        eXcelCol = eXcelCols<1,I>
        column = OleGetProperty( xlSht, 'Range' , eXcelCol:':':exCelCol )		;* Set the day columns to a standard width
        OlePutProperty( column , 'ColumnWidth' , '10.3' )
        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_YIELD:':':RangeColumn:ROW$TOT_OUT)

    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

    edge = OleGetProperty( range, 'Borders' , xlEdgeBottom )					;* Set border segment for bottom to medium weight line
    olePutProperty( edge , 'LineStyle', xlContinuous )
    olePutProperty( edge , 'Weight' , xlMedium )
    olePutProperty( edge , 'ColorIndex', xlColorIndexAutomatic )

    range = OleGetProperty( xlSht, 'Range', 'A':ROW$MER_YIELD:':':RangeColumn:ROW$TOT_OUT)	;* Set border for range (underline entire row)

    FOR I = 1 TO COUNT(EdgeList,@VM) + (EdgeList NE '')
        edge = OleGetProperty( range, 'Borders' , EdgeList<1,I> )				
        OlePutProperty( edge , 'LineStyle' , xlLineStyleNone )
    NEXT I

    edge = OleGetProperty( range, 'Borders' , xlEdgeBottom )
    olePutProperty( edge , 'LineStyle', xlContinuous )
    olePutProperty( edge , 'Weight' , xlMedium )
    olePutProperty( edge , 'ColorIndex', xlColorIndexAutomatic )

    Void = OleCallMethod( xlWkb, 'SaveAs',Environment_Services('GetReportsRootPath') : '\YTDThruPut.xls', xlWorkbookNormal )		;* Save to local drive

RETURN


* * * * * * *
HadError:
* * * * * * *

    xlChart = ''
    Charts = ''
    range = ''
    xlSht = ''
    xlWkb=''
    xlWorkBooks = ''
    x = OleCallMethod(xlApp, 'Quit')

RETURN 

