Function Test_Daniel7()
#pragma precomp SRP_PreCompiler

Declare subroutine Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Send_Message, Logging_Services
Declare subroutine Btree.Extract, Send_Event, Security_Err_Msg, Forward_Event, End_Window, Start_Window, FTP_Services
Declare subroutine EditCell, obj_NCR, obj_Notes, Post_Event, obj_WO_Mat, obj_WO_Mat_Log, obj_WO_Wfr, obj_Tables, obj_RDS
Declare subroutine Error_Services, RDS_Services, Dialog_Box, Insert, Unlock, QA_Services, Validate, Development_Services
Declare subroutine Update_Index, Database_Services, Obj_WO_Mat_QA, Fmt, Yield, WinYield, Sleepery, Qa_Services, 
Declare subroutine Obj_Post_Log, GaN_Services, Excel_Services, obj_WO_React, Activate_Save_Select, Reduce, FSMsg
Declare subroutine SRP_Stopwatch, Copy_Record_To_SQL, SQL_Services, Material_Services, Messaging_Services
Declare subroutine Reactor_Services, Reactor_Services_Dev, SRP_Stopwatch, Btree.Extract, Set_Env, RDS_React_Run
Declare subroutine obj_Prod_Spec, Security_Services, Make.List, Write_OI_To_SQL, Send_Info, PSN_Services
Declare subroutine Work_Order_Services
Declare function Get_Property, Get_Status, Popup, Send_Message, Msg, Security_Check, Dialog_Box, RowExists, Utility
Declare function Dialog_Box, obj_WO_Log, obj_NCR, Check_Notes, obj_MUWafers, obj_WO_Mat, Error_Services, RDS_Services
Declare function MemberOf, obj_Tables, obj_RDS, Environment_Services, Logging_Services, Material_Services, ErrMsg
Declare function Work_Order_Services, RetStack, Min, Max, Obj_Prod_Spec, Insert, SRP_Trim, Xlate, Obj_Wo_Mat
Declare function Security_Services, QA_Services, Database_Services, RowExists, Rti_Lh_Info, UNICODE_ANSI, UNICODE_UTF8
Declare function index, Httpclient_Services, SRP_Encode, SRP_Decode, DirList, Obj_Rds_Test, Tool_Parms_Services
Declare function SQL_Services, RDS_Services, Obj_WM_out, Schedule_Services, Obj_Tool, SRP_Sort_Array, ICONV
Declare function Development_Services, Obj_WO_Mat_QA, SRP_Join_Arrays, NextKey, Obj_Prod_Spec, FTP_Services, SQL_Format
Declare function DateTime, GaN_Services, SRP_Array, Excel_Services, EpiPro_Services, Repository, RTI_Task_Submit
Declare function RTI_Task_Status, Rds_Services, StartDotNet, Reactor_Services, SRP_Get_FileVersion, Direct_Print
Declare function obj_React_Run, RTI_Lock_Owner, obj_WM_In, Get_Repos_Entities, Get_Printer, Schedule_Services
Declare function Location_Services, Replication_Services, obj_Clean_Insp, Epi_Part_Services

$INSERT ENVIRON_CONSTANTS

$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT WM_IN_EQUATES
$Insert WM_OUT_EQUATES
$INSERT WO_LOG_EQU
$INSERT WO_STEP_EQU
$INSERT WO_MAT_EQUATES
$INSERT ORDER_EQU
$INSERT RDS_EQUATES
$INSERT PROD_SPEC_EQU
$INSERT NOTIFICATION_EQU
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT LOGICAL
$INSERT POPUP_EQUATES
$INSERT RTI_LH_INFO_EQUATES
$INSERT WO_MAT_QA_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$INSERT PRS_STAGE_EQUATES
$Insert RLIST_EQUATES
$Insert CLEAN_INSP_EQUATES
$Insert TOOL_PARMS_EQUATES
$Insert SCHEDULE_EQU
$Insert SCHED_DET_EQUATES
$Insert SCHEDULER_EQUATES
$Insert NCR_EQUATES
$Insert REACT_RUN_EQUATES
$Insert TOOL_EQUATES
$Insert TOOL_LOG_EQUATES
$Insert PM_EQUATES
$Insert WO_WFR_EQUATES
$Insert REVDOTNETEQUATES
$Insert REACTOR_EQUATES
$Insert RDS_TEST_EQUATES
$Insert RUN_STAGE_WFR_EQUATES
$Insert RTI_DEBUG_COMMON
$Insert DICT_EQUATES
$Insert SRPMAIL_INSERTS
$Insert SCHED_DET_NG_EQUATES
$Insert PROD_VER_EQUATES
$Insert DAILY_PERFORMANCE_EQUATES

// Reduce modes (for Select statement)
Equ NEW_EXIST$ To 0 
Equ NEXT_CUR$  To 1
Equ ADD_EXIST$ To 2   

EQU COL$QA_MET_PHASE_MIN TO 17

Equ Tab$                    to \09\
Equ CRLF$                   to \0D0A\
Equ LF$                     to \0A\
Equ Comma$                  to ','

$INSERT PRINTSETUP_EQUATES

DailyPerformance:
    
    SRP_Stopwatch('Reset')
    SRP_Stopwatch('Start', 'Runtime')
    
    DateOut    = '09/14/2022'
    ReportDate = IConv(DateOut, 'D')
    
    // Clear out previous daily_performance metrics
    table_name = "DAILY_PERFORMANCE"

    flag      = ""
    done      = False$
    CursorVar = ""

    * Clears all cursors
    For counter = 0 To 8
        ClearSelect counter
    Next counter

    sort_list     = "DATE_OUT"
    Reduce_Script = "WITH {DATE_OUT} EQ '":OConv(ReportDate, 'D4/'):"'"
    mode          = NEXT_CUR$
    DeleteKeyList = ''
    Reduce(reduce_script, sort_list, mode, table_name, Cursorvar, flag)
    If flag then
        Select table_name By sort_list Using Cursorvar then
            Open table_name To file_var then
                Loop
                    ReadNext KeyID Using Cursorvar By AT Else done = TRUE$
                Until done
                    DeleteKeyList<-1> = KeyID
                Repeat
            End Else
                FsMsg()
            End
        End Else
            FsMsg()
        end
    End Else
        FsMsg()
    End
    
    If DeleteKeyList NE '' then
        For each KeyID in DeleteKeyList using @FM
            Database_Services('DeleteDataRow', 'DAILY_PERFORMANCE', KeyID, True$, False$)
        Next KeyID
    end
    
    Query      = 'SELECT RDS WITH DATE_OUT EQ ':Quote(OConv(ReportDate, 'D4/')): ' BY REACTOR'
    EOF        = False$
    ErrCode    = ''
    ReportData = ''
    RawData    = ''
    // Reactor, PSN, PartNo, Hours, %ofDay, MPW, WPD, OEE, ProjectedOut, TimeAdjProjectedOut,
    // PartChangeOutsAdj, TotalProjectedOuts, ActualOuts, TotalActualOuts, TotalDelta, Comment 
    RList(Query, TARGET_ACTIVELIST$, '', '', '')
    RowIndex   = 0
    If Not(Get_Status(ErrCode)) then
        Loop
            ReadNext KeyID else EOF = True$
        Until EOF
            RowIndex += 1
            Database_Services('ActivateRecord', 'RDS', KeyID)
            If Error_Services('NoError') then
                Reactor          = {REACTOR}
                PSN              = {PROD_SPEC_ID}
                DateOut          = {DATE_OUT}
                PartNo                                    = {PART_NUM}
                WafersOut                                 = {WFRS_OUT}
                DtmIn                                     = {DTM_IN}
                DtmOut                                    = {DTM_OUT}
                ReportKey                                 = DateOut:'*':Reactor:'*':PSN:'*':PartNo
                ReportRow                                 = Database_Services('ReadDataRow', 'DAILY_PERFORMANCE', ReportKey)
                RepWafersOut                              = ReportRow<DAILY_PERFORMANCE.WAFERS_OUT$>
                RepWafersOut                             += WafersOut
                ReportRow<DAILY_PERFORMANCE.WAFERS_OUT$>  = RepWafersOut
*                FWIDtm                                    = ReportRow<DAILY_PERFORMANCE.FWI_DTM$>
*                LWODtm                                    = ReportRow<DAILY_PERFORMANCE.LWO_DTM$>
                If FWIDtm EQ '' or DtmIn LT FWIDtm then FWIDtm = DtmIn
*                ReportRow<DAILY_PERFORMANCE.FWI_DTM$>     = DtmIn
                If LWODtm EQ '' or DtmOut GT LWODtm then LWODtm = DtmOut
*                ReportRow<DAILY_PERFORMANCE.LWO_DTM$>     = LWODtm
                Database_Services('WriteDataRow', 'DAILY_PERFORMANCE', ReportKey, ReportRow)
            end
        Repeat
    end
    
    Reactors = Reactor_Services('GetReactorNumbers')
    For each ReactorNo in Reactors using @FM setting RowIndex
*        If ReactorNo EQ 55 then debug
        KeyList         = ''
        ReportRow       = ''
        ReportRow<0, 1> = ReactorNo

        table_name = "DAILY_PERFORMANCE"

        flag = ""
        done = False$
        CursorVar = ""

        * Clears all cursors
        For counter = 0 To 8
            ClearSelect counter
        Next counter

        sort_list     = "DATE_OUT"
        Reduce_Script = "WITH {REACTOR} EQ '":ReactorNo:"' AND WITH {DATE_OUT} EQ '":OConv(ReportDate, 'D4/'):"'"
        mode          = NEXT_CUR$

        Reduce(reduce_script, sort_list, mode, table_name, Cursorvar, flag)
        If flag then
            Select table_name By sort_list Using Cursorvar then
                Open table_name To file_var then
                    Loop
                        ReadNext KeyID Using Cursorvar By AT Else done = TRUE$
                    Until done
                        KeyList<-1> = KeyID
                    Repeat
                End Else
                    FsMsg()
                End
            End Else
                FsMsg()
            end
        End Else
            FsMsg()
        End
        If KeyList NE '' then             
            // Determine if a part change has taken place. If so, which day
            // did the part change take place? (i.e. the day before report date, the day of
            // report date, or the day after the report date)
            ClearSelect TARGET_ACTIVELIST$
            Query = 'SELECT REACT_MODE_NG WITH REACT_NO EQ ':ReactorNo:' AND WITH START_DT BETWEEN ':Quote(OConv(ReportDate - 2, 'D4/')):' AND ':Quote(OConv(ReportDate + 2, 'D4/'))
            RList(Query, TARGET_ACTIVELIST$, '', '', '')
            If Not(Get_Status(ErrCode)) then
                Query = 'SELECT REACT_MODE_NG WITH MODE EQ "CHANGEOVER_SCHEDULED" OR WITH MODE EQ "CHANGEOVER_UNSCHEDULED"'
                RList(Query, TARGET_ACTIVELIST$, '', '', '')
                If Not(Get_Status(ErrCode)) then
                    If @RecCount then
                        // A changeover has taken place
                        EOF = False$
                        Loop
                            ReadNext RMKey else EOF = True$
                        Until EOF
                            RMStartDt = Xlate('REACT_MODE_NG', RMKey, 'START_DT', 'X')
                            Begin Case
                                Case RMStartDt EQ (ReportDate - 1)
                                    // Part change began the day before.
                                    // Get the mode change end datetime to determine uptime
                                    // from a changeover perspective
                                    RMEndDtm = Xlate('REACT_MODE_NG', RMKey, 'STOP_DTM', 'X')
                                    If RMEndDtm GT ReportDate then
                                        // Part change finished during reporting period
                                        UptimePcts        = RMEndDtm - ReportDate
                                        UpHours           = UptimePct * 24
                                        PartChgCorrection = True$
                                    end else
                                        // Part change concluded the day prior
                                        UptimePct         = 1
                                        UpHours           = 24
                                        PartChgCorrection = True$
                                    end
                                Case RMStartDt EQ ReportDate
                                    // Part change took place on the day of
                                    // Get the mode change end time to determine uptime
                                    // from a changeover perspective
                                    RMStartDtm           = Xlate('REACT_MODE_NG', RMKey, 'START_DTM', 'X')
                                    RMEndDtm             = Xlate('REACT_MODE_NG', RMKey, 'STOP_DTM', 'X')
                                    UptimePcts           = ''
                                    UpHours              = ''
                                    PartChgCorrection    = ''
                                    // First part would have run until the start dtm of the changeover
                                    UptimePcts<1>        = RMStartDtm - ReportDate
                                    // Second part would have started running after the end dtm of the changeover
                                    UptimePcts<2>        = (ReportDate + 1) - RMEndDtm
                                    UpHours<1>           = UptimePcts<1> * 24
                                    UpHours<2>           = UptimePcts<2> * 24
                                    // The part change correction factor will only apply to the second part
                                    // running that day
                                    PartChgCorrection<1> = False$
                                    PartChgCorrection<2> = True$
                                Case RMStartDt EQ (ReportDate + 1)
                                    // Part change took place the day after
                                    // Uptime will be "100%" for the day of
                                    UptimePcts        = 1
                                    UpHours           = 24
                                    PartChgCorrection = False$
                            End Case
                        Repeat
                    end else
                        // No changeover event found
                        UptimePcts        = 1
                        UpHours           = 24
                        PartChgCorrection = False$
                    end
                end
                
                For each KeyID in KeyList using @FM setting fPos
                    ApplyPartChgCorrection  = PartChgCorrection<fPos>
                    UptimePct               = UptimePcts<fPos>
                    HoursUp                 = UpHours<fPos>
                    WafersOut               = Xlate('DAILY_PERFORMANCE', KeyID, 'WAFERS_OUT', 'X')
                    PSN                     = Field(KeyID, '*', 3)
                    PartNo                  = Field(KeyID, '*', 4)
                    ReactType               = Xlate('REACTOR', ReactorNo, 'REACT_TYPE', 'X')
                    MPW                     = Epi_Part_Services('GetMinutesPerWaferScheduler', PartNo, ReactType)
                    WPD                     = Epi_Part_Services('GetIdealWafersPerDayScheduler', PartNo, ReactType, MPW)
                    OEE                     = Xlate('APP_INFO', 'OEE*':ReactType, 1, 'X')
                    ReportRow<0, 2, -1>     = PSN
                    ReportRow<0, 3, -1>     = PartNo
                    ReportRow<0, 4, -1>     = UpHours<fPos>
                    ReportRow<0, 5, -1>     = UptimePcts<fPos>
                    ReportRow<0, 6, -1>     = MPW
                    ReportRow<0, 7, -1>     = WPD
                    ReportRow<0, 8, -1>     = OEE ; // OEE -> The front end should allow the user to modify this in a table and update it in OI
                    ProjOut                 = WPD * OEE
                    ReportRow<0, 9, -1>     = ProjOut ; // Projected out = WPD * OEE
                    TimeAdjustedProjOut     = ProjOut * UptimePct
                    ReportRow<0, 10, -1>    = TimeAdjustedProjOut
                    If ApplyPartChgCorrection then
                        PartChangeOutsAdj = TimeAdjustedProjOut * 0.5
                    end else
                        PartChangeOutsAdj = ''
                    end
                    ReportRow<0, 11, -1>  = PartChangeOutsAdj ; // PartChangeOutsAdj -> If Part change then TimeAdjustedProjectedOut * 50%
                    TotalProjOut          = ReportRow<0, 12>
                    TotalProjOut         += ProjOut
                    ReportRow<0, 12>      = TotalProjOut ; // TotalProjectedOuts
                    ReportRow<0, 13, -1>  = WafersOut ; // ActualOuts
                    TotalWafersOut        = ReportRow<0, 14>
                    TotalWafersOut       += WafersOut
                    ReportRow<0, 14>      = TotalWafersOut
                    ReportRow<0, 15>      = TotalWafersOut - TotalProjOut ; // TotalDelta = TotalWafersOut - TotalProjectedOut
                    ReportRow<0, 16>      = '' ; // Comments
                Next KeyID
            end
        end
        ReportData<RowIndex> = ReportRow
    Next ReactorNo
    
    SRP_Stopwatch('Stop', 'Runtime')
    SRP_Stopwatch('ShowAll')

    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL2', ReportData)
    
return


EpiPart:
    
    debug
    For Cursor = 1 to 8
        ClearSelect Cursor
    Next Cursor
    
    CustNo = 6593
    
*    Open 'PROD_SPEC' to hTable then
*        Query  = 'SELECT PROD_SPEC WITH CUST_NO EQ ':CustNo:' AND WITH STATUS NE "I"'
*        RList(Query, TARGET_ACTIVELIST$, '', '', '')
*        If Not(Get_Status(ErrCode)) then
*            EOF = False$
*            Loop
*                ReadNext KeyID else EOF = True$
*            Until EOF
*                Read Rec from hTable, KeyID then
*                    Rec<PROD_SPEC_STATUS$> = 'I'
*                    Write Rec on hTable, KeyID else
*                        ErrMsg(@FILE_ERROR)
*                    end
*                end
*    *            Rec = Database_Services('ReadDataRow', 'PROD_SPEC', KeyID)
*    *            If Rec NE '' then
*    *                Rec<PROD_SPEC_STATUS$> = 'I'
*    *                Database_Services('WriteDataRow', 'PROD_SPEC', KeyID, Rec)
*    *            end
*            Repeat
*        end
*    end
    
*    For Cursor = 1 to 8
*        ClearSelect Cursor
*    Next Cursor
    
    Query = 'SELECT PROD_VER WITH CUST_NO EQ ':CustNo:' AND WITH STATUS NE "I"'
    RList(Query, TARGET_ACTIVELIST$, '', '', '')
    If Not(Get_Status(ErrCode)) then
        EOF = False$
        Loop
            ReadNext KeyID else EOF = True$
        Until EOF
            Rec = Database_Services('ReadDataRow', 'PROD_VER', KeyID)
            If Error_Services('NoError') then
                Rec<PROD_VER_STATUS$> = 'I'
                Database_Services('WriteDataRow', 'PROD_VER', KeyID, Rec)
                If Error_Services('HasError') then
                    Error_Services('DisplayError')
                end
            end
        Repeat
    end
    
    
return


CleanInspCheck:
    
    debug
    Key      = 2511361
    Rec      = Database_Services('ReadDataRow', 'CLEAN_INSP', Key)
    Response = obj_Clean_Insp('SigComp', Key:@RM:Rec)
    
    If Response<1, 1> EQ 0 then
        // Clean prescribed, but not signed.
        Null
    end
    
    If Response<1, 2> EQ 0 then
        // Inspection prescribed, but not signed.
        Null
    end
    
return
    
    
MakeupWafersUpdate:
    
*    For Cursor = 1 to 8
*        ClearSelect Cursor
*    Next Cursor
*    
*    Open 'MAKEUP_WAFERS' to hTable then
*        Select hTable
*        EOF = False$
*        Loop
*            ReadNext KeyID else EOF = True$
*        Until EOF
*            WMOKey = Xlate('MAKEUP_WAFERS', KeyID, 'WM_OUT_NO', 'X')
*            If WMOKey NE '' then
*                Rec = Database_Services('ReadDataRow', 'WM_OUT', WMOKey)
*                Database_Services('WriteDataRow', 'WM_OUT', WMOKey, Rec)
*            end else
*                Rec = Database_Services('ReadDataRow', 'WO_MAT', KeyID)
*                Database_Services('WriteDataRow', 'WO_MAT', KeyID, Rec)
*            end
*        Repeat
*    end
    
return


DTMStart:
    
    debug
    WafersOut   = ''
    WafersIn    = 2
    TotalWafers = WafersOut + WafersIn
    
    If WafersOut EQ 0 then
        Null
    end else
        Null
    end
*    Database_Services('ActivateRecord', 'RDS', 550967)
*    WOMatRepStatus = XLATE('WO_MAT',{WO_MAT_KEY},'REP_STATUS','X')
*    RunStatus      = XLATE('REACT_RUN',@ID,'RUN_STATUS','X')
    
return


PopulateSAPHoldDTM:
    
    debug
    Open 'SAP_HOLD' to hTable then
        Select hTable
        EOF = False$
        Loop
            Readnext KeyID else EOF = True$
        Until EOF
            Read Rec from hTable, KeyID then
                WOMatKey   = Rec<2>
                HoldFlag   = Rec<4>
                InvActions = Xlate('WO_MAT', WOMatKey, 'INV_ACTION', 'X')
                InvDTMs    = Xlate('WO_MAT', WOMatKey, 'INV_DTM', 'X')
                If HoldFlag then
                    Locate 'HOLD_ON' in InvActions using @VM setting vPos then
                        TransDTM = InvDTMs<0, vPos>
                    end
                end else
                    Locate 'HOLD_OFF' in InvActions using @VM setting vPos then
                        TransDTM = InvDTMs<0, vPos>
                    end
                end
                Rec<5> = TransDTM
                Write Rec on hTable, KeyID else
                    ErrMsg('Error')
                end
            end
        Repeat
    end
    
    
return

AnotherTest:
    
    
    // This is our second change.
    
return


CleanInbox:
    
    KeyList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
    For each Key in KeyList
        Database_Services('DeleteDataRow', 'NOTES', Key)
    Next Key
    
return


MarkComp:
    
*    debug
    Recipients   = 'DANIEL_ST'
    SentFrom     = 'OI_ADMIN'
    Subject      = 'Auto-Scheduler Error'
    Message      = 'Invalid START_DTM and STOP_DTM calculated in AdjustScheduleEvents for event CC4E8D2AAE2F4632BF761320553910D4.'
    AttachWindow = ''
    AttachKey    = ''
    SendToGroup  = ''   
    Parms        = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
    obj_Notes('Create',Parms)
    
*    EOF      = False$
*    ReactNo  = 33
*    CurrDtm  = Datetime()
*    Query    = 'SELECT SCHED_DET_NG WITH REACT_NO EQ ':Quote(ReactNo):' AND WITH BLOCK_OUT EQ ':Quote(True$)
*    Query   := ' AND WITH STOP_DTM LT ':Quote(CurrDtm):' AND WITH EVENT_COMP NE ':Quote(True$)
*    For CursorIndex = 1 to 8
*        ClearSelect CursorIndex
*    Next CursorIndex
*    RList(Query, TARGET_ACTIVELIST$, '', '', '')
*    If Not(Get_Status(ErrCode)) then
*        Loop
*            ReadNext Key else EOF = True$
*        Until EOF
*            Rec = Database_Services('ReadDataRow', 'SCHED_DET_NG', Key)
*            If Error_Services('NoError') then
*                Rec<SCHED_DET_NG.EVENT_COMP$> = True$
*                Database_Services('WriteDataRow', 'SCHED_DET_NG', Key, Rec, True$, False$, True$)
*            end
*        Repeat
*    end
    
    
return


WafersIn:

    SchedList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
    For each Key in SchedList using @FM
        WorkOrder       = Xlate('CONFIG', Key, 'F2', 'X')
        WorkOrder       = Field(WorkOrder, ' ', 1)
        MUWfrs          = Material_Services('GetAvailableMakeupWafers', WorkOrder, 1)
        AvailableMUWfrs = MUWfrs<1>
        If DCount(AvailableMUWfrs, @VM) GT 1 then
            debug
        end
    Next Key
    
return


Syslists:
    debug
    Open 'SYSLISTS' to hTable then
        Select hTable
        Done = False$
        Loop
            errCode = ''
            Readnext Key else Done = True$
        Until Done
            KeyPart = Field(Key, '*', 1)
            If KeyPart EQ 'W' or KeyPart EQ 'T' or KeyPart EQ 'Q' then
                Set_Status(0)
                Delete hTable, Key else
                    ErrMsg(Get_Status(errCode))
                end
            end
        Repeat
    end
    
    
return


Reduce:
    SRP_Stopwatch('Reset')
    SRP_Stopwatch('Start', 'Reduce')
    Done         = False$
    SortList     = 'CASS_NO'
    CursorVar    = ''
    Flag         = ''
    Tablename    = 'WO_MAT'
    ReduceScript = 'WITH {WO_NO} EQ "171483" AND WITH {CURR_LOCATION} ] "SR*KTR"'
    Mode         = 1
    Reduce(ReduceScript, SortList, Mode, Tablename, CursorVar, Flag)
    If Flag then
        ReduceScript = 'WITH {HOLD} NOT 1'
        Reduce(ReduceScript, SortList, 2, Tablename, CursorVar, Flag)
        If Flag then 
            Select Tablename By SortList using CursorVar then
                Open Tablename to FileVar then
                    Loop
                        Readnext Key using CursorVar By AT else Done = True$
                    Until Done
                        
                    Repeat
                end
            end
        end
    end else
        FSMsg()
    end
    SRP_Stopwatch('Stop', 'Reduce')
    SRP_Stopwatch('ShowAll')
    
return

* WOMatStatus:
*    
*    CINo          = 2175647
*    ErrorMessage  = 'The clean & inspect record ':CINo:' has been updated since the form was opened! '
*    ErrorMessage := 'Metrology data has likely been imported since you read the record. '
*    ErrorMessage := 'Please close the form and try again.'
*    ErrMsg('Save error!':@SVM:ErrorMessage)
*    
*    WOMatKey         = '171358*54'
*    CassetteQty      = XLATE('WO_MAT', WOMatKey, 'WAFER_QTY', 'X')
*    RejectedWafers   = XLATE('WO_MAT', WOMatKey, 'TOT_REJ_WFRS', 'X')
*    RejectedMUWafers = XLATE('WO_MAT', WOMatKey, 'TOT_REJ_MU_WFRS', 'X')
*    ProdTestWafers   = XLATE('WO_MAT', WOMatKey, 'TW_PROD','X')
*    CurrWfrCount     = XLATE('WO_MAT', WOMatKey, 'CURR_WFR_CNT', 'X')
*    
*    
* return


* CleanRepMan:
*    debug
*    Open 'REPLICATION_QUEUE_LSL2_WM_OUT' to TableHandle then
*        Select TableHandle
*        EOF = False$
*        Loop
*            ReadNext @ID else EOF = True$
*        Until EOF
*            TransType = Field(@ID, '*', 1)
*            If TransType EQ 'WRITE' or TransType EQ 'DELETE' then
*                Delete TableHandle, @ID then Null
*            end
*        Repeat
*    end
*    
* return


Fix:
    
    
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,WO_DAILY_SCHED_SINGLE_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,REACTOR_LOG_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,NDW_ADD_COMMENT_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,REACTOR_SERVICES', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,REACTOR_MODE_HISTORY_EVENTS', '', '', '')
    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,PRINT_REACT_MODE_LOG_SERVICES', '', '', '')
    
return





CleanRDS:
    debug
    RDSNo = NextKey('RDS')
    
    // Delete old instance of this RDS if it exists ------------------------------------------------------------------------
    If RowExists('RDS', RDSNo) then
        Database_Services('DeleteDataRow', 'RDS', RDSNo, True$, False$)
        If Error_Services('NoError') then
            Results = 'RDS ' : RDSNo : ' deleted'
        end else
            Results = 'RDS ' : RDSNo : ' not deleted. Error : ' : Error_Services('GetMessage')
        end
    end
    // ---------------------------------------------------------------------------------------------------------------------


    // Delete related RDS_LAYER records ------------------------------------------------------------------------------------
    Layers = 'L1,L2,2'
    For each Layer in Layers using ','
        RDSLayerKey = RDSNo:'*':Layer
        If RowExists('RDS_LAYER', RDSLayerKey) then
            // Look for related RDS_TEST records and delete them first
            RDSTestKeys = Xlate('RDS_LAYER', RDSLayerKey, 'RDS_TEST_KEYS', 'X')
            If RDSTestKeys NE '' then
                For each RDSTestKey in RDSTestKeys using @VM setting vPos
                    // Look for related TW_USE records and delete them first
                    TWKeys = Xlate('RDS_TEST', RDSTestKey, 'TW_USE_ID', 'X')
                    If TWKeys NE '' then
                        For each TWKey in TWKeys using @VM setting vPos
                            Database_Services('DeleteDataRow', 'TW_USE', TWKey, True$, True$)
                        Next TWKey
                    end
                    Database_Services('DeleteDataRow', 'RDS_TEST', RDSTestKey, True$, True$)
                Next RDSTestKey
            end
            Database_Services('DeleteDataRow', 'RDS_LAYER', RDSLayerKey, True$, False$)
            If Error_Services('NoError') then
                Results = 'RDS_LAYER ' : RDSLayerKey : ' deleted'
            end else
                Results = 'RDS_LAYER ' : RDSLayerKey : ' not deleted. Error : ' : Error_Services('GetMessage')
            end
        end
    Next Layer
    // ---------------------------------------------------------------------------------------------------------------------


    // Delete old REACT_RUN record if it exists ----------------------------------------------------------------------------
    If RowExists('REACT_RUN', RDSNo) then
        // Delete old CLEAN_INSP record(s) if they exist
        CIKeys = Xlate('REACT_RUN', RDSNo, 'CI_NO', 'X')
        For each CIKey in CIKeys using @VM setting vPos
            If RowExists('CLEAN_INSP', CIKey) then
                Database_Services('DeleteDataRow', 'CLEAN_INSP', CIKey, True$, False$)
                If Error_Services('NoError') then
                    Results = 'CLEAN_INSP ' : CIKey : ' deleted'
                end else
                    Results = 'CLEAN_INSP ' : CIKey : ' not deleted. Error : ' : Error_Services('GetMessage')
                end          
            end
        Next CIKey
        Database_Services('DeleteDataRow', 'REACT_RUN', RDSNo, True$, False$)
        If Error_Services('NoError') then
            Results = 'REACT_RUN ' : RDSNo : ' deleted'
        end else
            Results = 'REACT_RUN ' : RDSNo : ' not deleted. Error : ' : Error_Services('GetMessage')
        end
    end
    // ---------------------------------------------------------------------------------------------------------------------

    
    
return


RDSKey:
    
    Debug

    
return


RDSTest:
    
*    DateIn = Xlate('RDS', 456789, 'DATE_IN', 'X')
    
    
    Fields = Xlate('DICT.WO_MAT', '%FIELDS%', 3, 'X')
    For each Field in Fields using @VM setting vPos
        Val = Xlate('WO_MAT', '171151*58', Field, 'X')
    Next Field
    
    
return


RepTest:
    
    Debug
    OITarget = Replication_Services('GetTargetServerPath')
    
return


TestMsg:
    
    Def            = ""
    Def<MICON$>    = '*'
*    Def<MBITMAP$>  = 'INFINEON'
    Def<MCAPTION$> = 'Success'
    Def<MTEXT$>    = "Metrology limits update complete!"
    Def<MTYPE$>    = "BO"
    MsgUp          = Msg(@window, Def)
return

* 
* SAPYield:
*    
*    debug
*    Yield = Xlate('WO_MAT', '171379*1', 'SAP_YIELD', 'X')
*    
*    
* return
* 

Push:
    
     Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,NDW_RDS_UPDATE_MET_LIMITS_EVENTS', '', '', '')
*     Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,WORK_ORDER_SERVICES', '', '', '')
    
return

* Verify:
*    
*    WOList     = 171402
*    WOList<-1> = 171396
*    WOList<-1> = 171179 
*    WOList<-1> = 171069
*    
*    For each WorkOrderNo in WOList using @FM
*        If RowExists('WO_LOG', WorkOrderNo) then
*            Work_Order_Services('UpdateReleasedQty', WorkOrderNo)
*            WORec          = Database_Services('ReadDataRow', 'WO_LOG', WorkOrderNo)
*            WOQty          = WORec<WO_LOG_QTY$>
*            RXQty          = obj_WO_Log('RxQty', WorkOrderNo:@RM:WORec)
*            RelQty         = obj_WO_Log('RelQty', WorkOrderNo:@RM:WORec)
*            If RelQty GT WOQty then
*                UnRelQty = 0
*            end else
*                UnRelQty = WOQty - RelQty
*            end
*            ShipQty        = obj_WO_Log('ShipQty', WorkOrderNo:@RM:WORec)
*            RxQtyStatic    = Xlate('WO_LOG', WorkOrderNo, 'RX_QTY_STATIC', 'X')
*            RelQtyStatic   = Xlate('WO_LOG', WorkOrderNo, 'REL_QTY_STATIC', 'X')
*            UnRelQtyStatic = Xlate('WO_LOG', WorkOrderNo, 'UNREL_QTY_STATIC', 'X')
*            ShipQtyStatic  = Xlate('WO_LOG', WorkOrderNo, 'SHIP_QTY_STATIC', 'X')
*            If RxQty NE RxQtyStatic then
*                Error<-1> = WorkOrderNo : ' RX_QTY mismatch'
*                Work_Order_Services('UpdateReceivedQty', WorkOrderNo)
*            end
*            If RelQty NE RelQtyStatic or UnRelQty NE UnRelQtyStatic then
*                Error<-1> = WorkOrderNo : ' REL_QTY and/or UNREL_QTY mismatch'
*                Work_Order_Services('UpdateReleasedQty', WorkOrderNo)
*            end
*            If ShipQty NE ShipQtyStatic then
*                Error<-1> = WorkOrderNo : ' SHIP_QTY mismatch'
*                Work_Order_Services('UpdateShippedQty', WorkOrderNo)
*            end
*        end
*    Next WorkOrderNo
*    
* return

WOAudit:
    debug
    Error = ''
    
    NextWO = Xlate('DICT.WO_LOG', '%SK%', 1, 'X')
    LastWO = NextWO - 1
    
    NumWO            = LastWO - 171000
    Def              = ""
    Def<MCAPTION$>   = "Verifying work order quantities..."
    Def<MTYPE$>      = "GC"
    Def<MEXTENT$>    = NumWO
    Def<MTEXTWIDTH$> = 600
    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
    Counter          = 1
    For WorkOrderNo = LastWO to 171000 Step -1
        Running        = Msg(@WINDOW, MsgUp, Counter, MSGINSTUPDATE$) ;* Update message
        If RowExists('WO_LOG', WorkOrderNo) then
            WORec          = Database_Services('ReadDataRow', 'WO_LOG', WorkOrderNo)
            WOQty          = WORec<WO_LOG_QTY$>
            RXQty          = obj_WO_Log('RxQty', WorkOrderNo:@RM:WORec)
            RelQty         = obj_WO_Log('RelQty', WorkOrderNo:@RM:WORec)
            If RelQty GT WOQty then
                UnRelQty = 0
            end else
                UnRelQty = WOQty - RelQty
            end
            ShipQty        = obj_WO_Log('ShipQty', WorkOrderNo:@RM:WORec)
            RxQtyStatic    = Xlate('WO_LOG', WorkOrderNo, 'RX_QTY_STATIC', 'X')
            RelQtyStatic   = Xlate('WO_LOG', WorkOrderNo, 'REL_QTY_STATIC', 'X')
            UnRelQtyStatic = Xlate('WO_LOG', WorkOrderNo, 'UNREL_QTY_STATIC', 'X')
            ShipQtyStatic  = Xlate('WO_LOG', WorkOrderNo, 'SHIP_QTY_STATIC', 'X')
            If RxQty NE RxQtyStatic then
                Error<-1> = WorkOrderNo : ' RX_QTY mismatch'
                Work_Order_Services('UpdateReceivedQty', WorkOrderNo)
            end
            If RelQty NE RelQtyStatic or UnRelQty NE UnRelQtyStatic then
                Error<-1> = WorkOrderNo : ' REL_QTY and/or UNREL_QTY mismatch'
                Work_Order_Services('UpdateReleasedQty', WorkOrderNo)
            end
            If ShipQty NE ShipQtyStatic then
                Error<-1> = WorkOrderNo : ' SHIP_QTY mismatch'
                Work_Order_Services('UpdateShippedQty', WorkOrderNo)
            end
        end
        Counter += 1
    Next WorkOrderNo
    
    Msg(@WINDOW,MsgUp)
    
    Database_Services('WriteDataRow', 'SYSLISTS', 'WO_QTY_ERROR', Error)
    
return 


UpdateWorkOrderQuantities:
    
    debug
    StartDate      = Date() - 120
    EndDate        = Date() + 120
    SchedDetKeyIDs = Schedule_Services('GetScheduleDetailKeys', StartDate, EndDate)
    If SchedDetKeyIDs NE '' then
        NumKeys          = DCount(SchedDetKeyIDs, @FM)
        Def              = ""
        Def<MCAPTION$>   = "Populating work order quantities..."
        Def<MTYPE$>      = "GC"
        Def<MEXTENT$>    = NumKeys
        Def<MTEXTWIDTH$> = 600
        MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
        
        For Each SchedDetKeyID in SchedDetKeyIDs using @FM setting fPos
            Running = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
            SchedDetRec = Database_Services('ReadDataRow', 'SCHED_DET_NG', SchedDetKeyID)
            WorkOrderNo = SchedDetRec<SCHED_DET_NG.WO_NO$>
            Work_Order_Services('UpdateReceivedQty', WorkOrderNo)
            Work_Order_Services('UpdateReleasedQty', WorkOrderNo)
            Work_Order_Services('UpdateShippedQty', WorkOrderNo)
            
        Next SchedDetKeyID
    end
    
    Msg(@WINDOW,MsgUp)
    
return

SAPAudit:
    
    WONo      = 171188
    WOMatKeys = Xlate('WO_LOG', WONo, 'WO_MAT_KEY', 'X')
    BatchIds  = Xlate('WO_LOG', WONo, 'SAP_BATCH_NO', 'X')
    SAPYields = Xlate('WO_LOG', WONo, 'WO_MAT_SAP_YIELD', 'X')
    SAPScrap  = Xlate('WO_LOG', WONo, 'WO_MAT_SAP_CONFIRM_SCRAP', 'X')
    
    ReportData = 'WO_MAT Key, SAP Batch Id, SAP Yield, SAP Scrap':CRLF$
    For each WOMatKey in WOMatKeys using @VM setting vPos
        ReportData := WOMatKey:',':BatchIds<0, vPos>:',':SAPYields<0, vPos>:',':SAPScrap<0, vPos>:CRLF$
    Next WOMatKey
    
    OSWrite ReportData on 'D:\FITemp\SAPExport.csv'
    
return


* PushCode:
*    
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_REACT_STATUS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,RDS_UNLOAD_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,DBW_RDS_OVERVIEW_NEPP_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,SCAN_SERVICES', '', '', '')
*    
* return


* CleanEPP:
*    debug
*    WONo     = 171177
*    CassList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
*    For each CassNo in CassList using @FM setting fPos
*        WMIKey   = WONo:'*1*':CassNo
*        WMOKey   = WONo:'*1*':CassNo
*        WOMatKey = WONo:'*':CassNo
*        Database_Services('DeleteDataRow', 'WM_IN', WMIKey)
*        Database_Services('DeleteDataRow', 'WM_OUT', WMOKey)
*        Database_Services('DeleteDataRow', 'WO_MAT', WOMatKey)
*    Next CassNo
* 
*    For CassNo = 39 to 52 Step 1
*        WMOKey   = WONo:'*1*':CassNo
*        Database_Services('DeleteDataRow', 'WM_OUT', WMOKey)
*    Next CassNo
*    
* return


* QAMetUpdate:
*    debug
*    WONo = 171309
*    
*    For CassNo = 8 to 24
*        WOMatQAKey = WONo:'*':CassNo
*        //PSN_Services('UpdateQAMetrologyLimits', WOMatQAKey, 'QA', '1ADE', 'L')
*        PSN_Services('UpdateAllQAMetrologyLimits', WOMatQAKey)
*        If Error_Services('HasError') then ErrMsg(Error_Services('GetMessage'))
*    Next CassNo
*    debug
* return


ReactStatus:
    
    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,REPORT_SERVICES_DEV', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_REACT_STATUS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,QA_SERVICES', '', '', '')
    
return

FormList:
    
    ReportList = ''
    List       = Get_Repos_Entities('LSL2', 'OIWIN', '', False$)
    For each Row in List using @FM setting fPos
        ReportList<fPos> = Field(Row, '*', 4)
    Next Row
    
    LastLaunch = 0
    FormCounts = ''
    EOF        = False$
    Open 'FORM_METRICS' to hTable then
        Select hTable
        Loop
            Readnext Key else EOF = True$
        Until EOF
            FormName = Field(Key, '*', 1)
            Locate FormName in ReportList using @FM setting fPos then
                FormCounts<fPos>    = FormCounts<fPos> + 1
            end
        Repeat
    end

    NumForms   = DCount(ReportList, @FM)
    For FormIndex = 1 to NumForms
        FormCount                = FormCounts<FormIndex>
        If FormCount EQ '' then FormCount = 0
        ReportList<FormIndex, 2> = FormCount
    Next FormIndex
    
    ReportList = Insert(ReportList, 1, 0, 0, 'Form Name':@VM:'Launch Count')
    Swap @VM with ',' in ReportList
    Swap @FM with CRLF$ in ReportList
    OSWrite ReportList on 'D:\FITemp\FormCounts.csv'
    
return

TestRep:
    debug
    KeyList = 73468
    For each KeyID in KeyList using @FM setting fPos then
        TableName = 'NOTES'

        If TableName NE '' and KeyID NE '' then
            TransID = ''
            TransID<1> = 'WRITE'
            TransID<2> = 'LSL2'
            TransID<3> = 'LSL'
            TransID<4> = TableName
            TransID<5> = KeyID
            Write_OI_To_Sql(TransID)
        end
        
        //Running = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
    Next KeyID
return





SendEmail:
    
    ConfigFile    = ''
    ConfigFile<1> = SendUsing_Port$
    ConfigFile<2> = ''
    ConfigFile<3> = 25                     			;* Server port
    *ConfigFile<4> = 'appmail.eu.infineon.com'		;* IFX Mail server
    ConfigFile<4> = 'mailrelay-external.infineon.com'
    ConfigFile<5> = Yes$                   			;* Authenticate
    ConfigFile<6> = 'oinotify@infineon.com'			;* Username
    ConfigFile<7> = 'oinotify1'		        		;* Password
    ConfigFile<8> =	No$								;* Use SSL

    SentFrom = 'oinotify@infineon.com'
    
    Message = ''
    Message<1> = 'Test'						; * Subject
    Message<2> = SentFrom		           		; * From (email address)
    Message<3> = 'dstieber@srpcs.com'; * Send to (email address)
    Message<5> = ''								; * Blind Carbon Copy (email address)
    Message<6> = ''								; * Reply To (email address)
    Message<7> = 'TEXT'							; * Content Type (TEXT or HTML)
    Message<8> = 'Testing'							; * Content / Body
    Message<9> = ''								; * Attachment(s) (path to file name(s))
    
    MsgSent = SRP_Send_Mail(Message, ConfigFile)    

return

* TestText:
*    
*    PrintPath = 'ZEBRA01'
*    NewPrintPath = Dialog_Box('NDW_EDIT_TEXT', @Window, PrintPath)
*    debug
*    
* return
* 
* 
* PushFix:
*    
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,REPORT_SERVICES_DEV2', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,PRINTSETUP', '', '', '')
*    
* return


KeyCheck:
    
    Open 'WO_MAT' to hTable then
        Query   = 'SELECT WO_MAT'
        RList(Query, TARGET_ACTIVELIST$, '', '', '')
        KeyID   = ''
        EOF     = False$
        Counter = 0
        Loop
            Counter += 1
            Readnext KeyID, Value else EOF = True$
            Until EOF
            If Value then
                !!! Error @VM in key ID
                DEBUG
            end else
                Read Rec from hTable, KeyID else
                    !!! Error @FM in key ID
                    DEBUG
                end
            end
            Send_Info('Key ':KeyID:' Loop ':Counter:' of ':@RecCount)
        Repeat
        
        
    end
    
return


Location:
    
    
    CurrLoc = Xlate('WO_MAT', '171087*16', 'CURR_LOCATION', 'X')
    
return


TestDebug:
	
	S.WONo = '171087'
	
	CRLocs        = ''
    CRLocs<0, -1> = 'CR*BE'
    CRLocs<0, -1> = 'CR*BO'
    CRLocs<0, -1> = 'CR*TUN'
    CRLocs<0, -1> = 'CR*EPR'
    CRLocs<0, -1> = 'CR*FE'
    CRLocs<0, -1> = 'CR*FEH'
    CRLocs<0, -1> = 'CR*FO'
    CRLocs<0, -1> = 'CR*FOH'
    
    LoadedData   = ''
    LocQueryList = CRLocs

    If @User4 EQ 'DANIEL_ST' and S.WONo EQ '171087' then debug
    LoadedCassList = ''
    ReactType      = Xlate('WO_LOG', S.WONo, 'REACT_TYPE', 'X')
    If ReactType NE 'EPP' then
        If LocQueryList NE '' then
            LoadedData     = Location_Services('GetLocationCassInfoRList', S.WONo, LocQueryList)
	    end
    end
    
return


RejQty:
    
    Debug
    WOMatKeys = '170520*11' ; //'171149*40':@VM:'170804*21'
    For each WOMatKey in WOMatKeys using @VM setting vPos
        WorkOrderNo      = Field(WOMatKey, '*', 1)
        ReactorType      = XLATE('WO_LOG', WorkOrderNo, 'REACT_TYPE', 'X')
        ReactorType      = Field(ReactorType, @VM, 1)
        CassetteQty      = XLATE('WO_MAT', WOMatKey, 'WAFER_QTY', 'X')
        RejectedWafers   = XLATE('WO_MAT', WOMatKey, 'TOT_REJ_WFRS', 'X')
        RejectedMUWafers = XLATE('WO_MAT', WOMatKey, 'TOT_REJ_MU_WFRS', 'X')
        ProdTestWafers   = XLATE('WO_MAT', WOMatKey, 'TW_PROD','X')
        CurrWfrCount     = XLATE('WO_MAT', WOMatKey, 'CURR_WFR_CNT', 'X')
        
        IF (RejectedWafers = '') then
            RejectedWafers = 0
        END
        IF (RejectedMUWafers = '') then
            RejectedMUWafers = 0
        END
        IF (ProdTestWafers = '') then
            ProdTestWafers = 0
        END
        
        IF ((ReactorType = 'EPP') OR (ReactorType = 'EpiPro')) THEN
            RejectedQty = RejectedWafers + RejectedMUWafers
        END ELSE
            RejectedQty = RejectedWafers + RejectedMUWafers + ProdTestWafers
        END
        
        If ( (CurrWfrCount EQ 0) and (RejectedQty GE CassetteQty) ) then
            Null ; // Mark cassette as full box reject
        end        
    Next WOMatKey
    
    
*    RejectedWafers   = 0
*    RejectedMUWafers = 0
*    ProdTestWafers   = 0
* 
*    Set_Status(0)
*    CassetteQty      = XLATE('WO_MAT', WOMatKey, 'WAFER_QTY', 'X')
*    RejectedWafers   = Sum(XLATE('WO_MAT', WOMatKey, 'TOT_REJ_WFRS', 'X'))
*    RejectedMUWafers = Sum(XLATE('WO_MAT', WOMatKey, 'TOT_REJ_MU_WFRS', 'X'))
* 
*    IF (RejectedWafers = '') then
*        RejectedWafers = 0
*    END
*    IF (RejectedMUWafers = '') then
*        RejectedMUWafers = 0
*    END
* 
*    RejectedQty = RejectedWafers + RejectedMUWafers
    
return


Schedule:
    
    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,SCHEDULER_DEV_EVENTS', '', '', '')
    
return


Status:
    
    debug
    WOMatKey     = '170964*21'
    WMOKey       = '170964*1*21'
    WOMatRec     = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
    WOMatStatus  = obj_WO_Mat('CurrStatus', WOMatKey:@RM:WOMatRec)
    ReportStatus = obj_WO_Mat('ReportStatus', WOMatKey:@RM:WOMatRec)
    WMORec       = Database_Services('ReadDataRow', 'WM_OUT', WMOKey)
    WMOStatus    = obj_WM_Out('CurrStatus', WMOKey:@RM:WMORec)
    
    
return

CleanEvents:
 	debug
 	Events = Get_Repos_Entities('LSL2', 'OIEVENT', '', '', '', '', '')
 	For each Event in Events using @FM setting fPos
		Key  = 'LSL2*':Field(Event, '*', 3, 1):'*':Field(Event, '*', 4, 1)
		Code = Database_Services('ReadDataRow', 'SYSREPOSEVENTS', Key)
		OrigCode = Code
		Swap '$insert sysprocs, ' with '$insert ' in Code
		Swap '$INSERT SYSPROCS, ' with '$INSERT ' in Code
		If Code NE OrigCode then
			Database_Services('WriteDataRow', 'SYSREPOSEVENTS', Key, Code)
		end
 	Next Event


// CleanStProcs
	
	StProcs = Get_Repos_Entities('LSL2', 'STPROC', '', '', '', '', '')
	For each StProc in StProcs using @FM setting fPos
	    StProcName = Field(StProc, '*', 4, 1)
	    If StProcName NE 'TEST_DANIEL3' then
            Key      = StProcName:'*LSL2'
            Code     = Database_Services('ReadDataRow', 'SYSPROCS', Key)
            OrigCode = Code
            Swap '$insert sysprocs, ' with '$insert ' in Code
            Swap '$INSERT SYSPROCS, ' with '$INSERT ' in Code
            If Code NE OrigCode then
                Database_Services('WriteDataRow', 'SYSPROCS', Key, Code)
            end
        end
	Next StProc

return


DeadCodeList:
    
    debug
    DeadList      = ''
    STProcList    = Get_Repos_Entities('LSL2', 'STPROC', '')
    STProcList    = SRP_Array('Rotate', STProcList, @FM, '*')
    STProcList    = STProcList<4>
    STProcExeList = Get_Repos_Entities('LSL2', 'STPROCEXE', '')
    STProcExeList = SRP_Array('Rotate', STProcExeList, @FM, '*')
    STProcExeList = STProcExeList<4>
    Swap '*' with @FM in STProcList
    Swap '*' with @FM in STProcExeList
    For each STProc in StProcList using @FM setting fPos
        Locate STProc in STProcExeList using @FM setting dummy else
            DeadList<-1> = STProc
        end
    Next STProc
    Swap @FM with CRLF$ in DeadList
    OSWrite DeadList on 'C:\Users\StieberD\Desktop\DeadList.txt'
    
return



PushSchema:
    
    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,COMM_RECIPE', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,COPY_RDS_LAYER_RECORD_TO_SQL', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,COPY_RECIPE_RECORD_TO_SQL', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_RDS_LAYER', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,NDW_TOOL_PARMS_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_RECIPE', '', '', '')
    
return





ReactMode:
    
    debug
    CurrModeKey = Xlate('REACTOR_CHILD_KEY_IDS_NG', 48, 1, 'X')
    
    
return


GanWIPJSON:
    
    JSON = Gan_Services('GetGaNWIPJSON')
    
    OSWrite JSON on 'C:\Users\StieberD\Documents\GaNWIP.json'
    
    
return


SAPScript:
    
    BadList          = ''
    KeyList          = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL8')
    Def              = ""
    Def<MCAPTION$>   = "Scanning old records..."
    Def<MTYPE$>      = "GC"
    Def<MEXTENT$>    = DCount(KeyList, @FM)
    Def<MTEXTWIDTH$> = 600
    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
    
    For each Key in KeyList setting fPos
        SAPBatchNo = Xlate('WO_MAT', Key, 'SAP_BATCH_NO', 'X')
        SAPTxDTM   = Xlate('WO_MAT', Key, 'SAP_TX_DTM', 'X')
        IF SAPBatchNo[-1,1] EQ 'R' and SAPTxDTM EQ '' then
            BadList<-1> = Key
        end
        Running  = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
    Next Key
    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL9', BadList)
    Msg(@WINDOW,MsgUp)
    
    
    BadList          = ''
    KeyList          = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL10')
    Def              = ""
    Def<MCAPTION$>   = "Scanning new records..."
    Def<MTYPE$>      = "GC"
    Def<MEXTENT$>    = DCount(KeyList, @FM)
    Def<MTEXTWIDTH$> = 600
    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
    
    For each Key in KeyList setting fPos
        SAPBatchNo = Xlate('WO_MAT', Key, 'SAP_BATCH_NO', 'X')
        SAPTxDTM   = Xlate('WO_MAT', Key, 'SAP_TX_DTM', 'X')
        IF SAPBatchNo[-1,1] EQ 'R' and SAPTxDTM EQ '' then
            BadList<-1> = Key
        end
        Running  = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
    Next Key
    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL11', BadList)
    Msg(@WINDOW,MsgUp)
    
    
    
    
return


EPPMetReport:
    
    ReportData    = ''
    Headers       = Database_Services('ReadDataRow', 'SYSLISTS', 'EPP_METROLOGY_HEADERS')
    Columns       = Xlate('EXPORTS', 'EPIPRO_METOROLGY', 'COLUMNS', 'X')
    Swap @FM with @VM in Headers
    ReportData<1> = Headers
    
    RDSFields  = Database_Services('ReadDataRow', 'DICT.RDS', '%FIELDS%')
    RDSColumns = RDSFields<DICT_DISPLAY$>
    RDSConvs   = RDSFields<DICT_GENERIC_TYPE$>
    
    WMOList = Database_Services('ReadDataRow', 'SYSLISTS', 'WM_OUT_401678F_20210831')
    NumWMO  = DCount(WMOList, @FM)
            
    Def              = ""
    Def<MCAPTION$>   = "Building report..."
    Def<MTYPE$>      = "GC"
    Def<MEXTENT$>    = NumWMO
    Def<MTEXTWIDTH$> = 600
    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
    
    For each WMOKey in WMOList using @FM setting fPos
        Running     = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
        RowIndex    = fPos + 1
        ThisRDSList = Xlate('WM_OUT', WMOKey, 'RDS', 'X')
        Zones       = Xlate('WM_OUT', WMOKey, 'ZONE', 'X')
        Pockets     = Xlate('WM_OUT', WMOKey, 'POCKET', 'X')
        SAPBatchNo  = Xlate('WM_OUT', WMOKey, 'SAP_BATCH_NO', 'X')
        PrevRDSNo   = ''
        For each RDSNo in ThisRDSList using @VM setting SlotNo
            If RDSNo NE PrevRDSNo then Database_Services('ActivateRecord', 'RDS', RDSNo)
            ReportRow = ''
            For each Column in Columns using @VM setting cPos
                Locate Column in RDSColumns using @VM setting ConvPos then
                    Conv = RDSConvs<0, ConvPos>
                    Begin Case
                        Case Column EQ 'WO'
                            ReportRow<0, cPos> = Field(WMOKey, '*', 1)
                        Case Column EQ 'SEQ'
                            ReportRow<0, cPos> = RDSNo
                        Case Column EQ 'ZONE'
                            ReportRow<0, cPos> = Zones<0, SlotNo>
                        Case Column EQ 'POCKET'
                            ReportRow<0, cPos> = Pockets<0, SlotNo>
                        Case Column EQ 'WM_OUT_KEY'
                            ReportRow<0, cPos> = WMOKey
                        Case Column EQ 'OUT_CASS_NO'
                            ReportRow<0, cPos> = Field(WMOKey, '*', 3)
                        Case Column EQ 'OUT_SLOT_NO'
                            ReportRow<0, cPos> = SlotNo
                        Case Column EQ 'SAP_BATCH_NO'
                            ReportRow<0, cPos> = SAPBatchNo
                        Case Otherwise$
                            If Conv EQ '' then
                                ReportRow<0, cPos> = Calculate(Column)
                            end else
                                ReportRow<0, cPos> = OConv(Calculate(Column), Conv)
                            end
                    End Case
                end
            Next Column
            PrevRDSNo      = RDSNo
            ReportData<-1> = ReportRow
        Next RDSNo
        
    Next WMOKey
    
    Swap @VM with ',' in ReportData
    Swap @FM with CRLF$ in ReportData
    OSWrite ReportData on 'D:\FITemp\EPPMetReport.csv'
    Msg(@WINDOW,MsgUp)
    
return
    
    
SelectEPP:
    
    // DateOut GT 08/31/2021 = 19602
    RDSList       = ''
    WMOList       = Database_Services('ReadDataRow', 'SYSLISTS', 'WM_OUT_401678F')
    FilterWMOList = ''
    NumWMO        = DCount(WMOList, @FM)
    For WMOIndex = 1 to NumWMO
        Done        = False$
        WMOKey      = WMOList<WMOIndex>
        ThisRDSList = Xlate('WM_OUT', WMOKey, 'RDS', 'X')
        ThisRDSList = SRP_Array('Clean', ThisRDSList, 'TrimAndMakeUnique', @VM)
        For each RDSNo in ThisRDSList using @VM
            DateOut = Xlate('RDS', RDSNo, 'DATE_OUT', 'X')
            If DateOut GT 19602 then
                FilterWMOList<-1> = WMOKey
                Done              = True$
            end
        Until Done
        Next RDSNo
    Next WMOIndex
    Database_Services('WriteDataRow', 'SYSLISTS', 'WM_OUT_401678F_20210831', FilterWMOList)
    
return


* WfrCnt:
*    
*    WOMatKey   = '171038*13'
*    WOMatRec   = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*    debug
*    CurrWfrCnt = obj_WO_Mat('CurrWaferCnt', WOMatKey:@RM:WOMatRec)
*    
*    
* return
* 
* 
* 
* RDSList:
*    
*    RDSList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL_8')
*    For each RDSNo in RDSList using @FM
*        Database_Services('ActivateRecord', 'RDS', RDSNo)
*        RejCnt1 = SUM(XLATE('NCR', {NCR_KEYS}, 'REJ_CNT', 'X'))
*        RejCnt2 = {CUST_TOT_REJ} + {LSL_TOT_REJ}
*        If RejCnt1 NE RejCnt2 then
*            debug
*        end
*        
*    Next RDSNo
*    
*    
* return


* CustScrap:
*    
*    SearchDir = 'D:\FTP\FTP_IN_REPOSITORY\Batch\2022\03 (March)\'
*    InitDir SearchDir:'*'
*    FileList  = DirList()
*    For each Filename in FileList using @FM
*        
*        OSRead FileData from SearchDir:Filename then
*            Swap TAB$ with @FM in FileData
*            If (Index(FileData, 'M015833', 1)) then
*                debug
*            end
*        end
*    Next Filename
*    
* return
    
* YieldReport:
*    
*    WafersIn  = 0
*    WafersOut = 0
*    CustScrap = 0
*    IFXScrap  = 0
*    ProdTest  = 0
*    SRPTotal  = 0
*    
*    RDSList   = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL5')
*    For each RDSNo in RDSList using @FM
*        WafersIn  += Xlate('RDS', RDSNo, 'WAFERS_IN', 'X')
*        WafersOut += Xlate('RDS', RDSNo, 'WFRS_OUT', 'X')
*        
*        // Scrap
*        ThisCustScrap  = Xlate('RDS', RDSNo, 'CUST_TOT_REJ', 'X')
*        ThisIFXScrap   = Xlate('RDS', RDSNo, 'LSL_TOT_REJ', 'X')
*        CustScrap     += ThisCustScrap
*        IFXScrap      += ThisIFXScrap
*        
*        // Prod Test
*        RDSLayerKeys  = Xlate('RDS', RDSNo, 'RDS_LAYER_KEYS', 'X')
*        RDSTestKeys   = Xlate('RDS_LAYER', RDSLayerKeys, 'RDS_TEST_KEYS', 'X')
*        ThisProdTest  = obj_RDS_Test('ProdTestCount', RDSTestKeys)
*        ProdTest     += ThisProdTest
*        
*        // SRP
*        SRPTotal += Xlate('RDS', RDSNo, 'RESEARCH_SRP_BILLABLE', 'X')
*        
*    Next RDSNo
*    
*    Debug
*    
* return


* ManRep:
*    
*    debug
*    For SK = 1667 to 1702
*        TransactionID = Database_Services('ReadDataRow', 'REPLICATION_QUEUE_LSL2_WO_MAT', SK)
*        Write_OI_To_SQL(TransactionID)
*        If Error_Services('NoError') then
*            Database_Services('DeleteDataRow', 'REPLICATION_QUEUE_LSL2_WO_MAT', SK)
*        end
*    Next SK
*    
*    
*    
* return
* 

EPPReport:
    
    OSRead Report from 'D:\FITemp\book2.csv' then
        
        Swap CRLF$ with @FM in Report
        Swap ',' with @VM in Report
        NumRows = DCount(Report, @FM)
        
        Def              = ""
        Def<MCAPTION$>   = "Updating report..."
        Def<MTYPE$>      = "GC"
        Def<MEXTENT$>    = NumRows
        Def<MTEXTWIDTH$> = 600
        MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
        Running          = Msg(@WINDOW, MsgUp, 1, MSGINSTUPDATE$) ;* Update message
        
        For RowIndex = 2 to NumRows
            Row    = Report<RowIndex>
            WONo   = Row<0, 10>
            CassNo = Row<0, 16>
            WMOKey = WONo:'*1*':CassNo
            If RowExists('WM_OUT', WMOKey) then
                SAPBatchNo       = Xlate('WM_OUT', WMOKey, 'SAP_BATCH_NO', 'X')
                Row<0, 13>       = SAPBatchNo
                Report<RowIndex> = Row
            end
            Running  = Msg(@WINDOW, MsgUp, RowIndex, MSGINSTUPDATE$) ;* Update message
        Next RowIndex
    end
    
    Swap @FM with CRLF$ in Report
    Swap @VM with ',' in Report
    OSWrite Report on 'D:\FITemp\book3.csv'
    Msg(@WINDOW,MsgUp)
    
return


* FormList:
*    
*    ReportList = ''
*    List       = Get_Repos_Entities('LSL2', 'OIWIN', '', False$)
*    For each Row in List using @FM setting fPos
*        ReportList<fPos> = Field(Row, '*', 4)
*    Next Row
*    
*    LastLaunch = 0
*    FormCounts = ''
*    EOF        = False$
*    Open 'FORM_METRICS' to hTable then
*        Select hTable
*        Loop
*            Readnext Key else EOF = True$
*        Until EOF
*            FormName = Field(Key, '*', 1)
*            If FormName EQ 'REACT_MODE_CHG' then
*                LaunchDTM = Field(Key, '*', 3)
*                If LaunchDTM GT LastLaunch then LastLaunch = LaunchDTM
*            end
*            Locate FormName in ReportList using @FM setting fPos then
*                FormCounts<fPos>    = FormCounts<fPos> + 1
*            end
*        Repeat
*    end
*    
*    debug
*    LastLaunch = OConv(LastLaunch, 'DT')
*    NumForms   = DCount(ReportList, @FM)
*    For FormIndex = 1 to NumForms
*        FormCount                = FormCounts<FormIndex>
*        If FormCount EQ '' then FormCount = 0
*        ReportList<FormIndex, 2> = FormCount
*    Next FormIndex
*    
*    ReportList = Insert(ReportList, 1, 0, 0, 'Form Name':@VM:'Launch Count')
*    Swap @VM with ',' in ReportList
*    Swap @FM with CRLF$ in ReportList
*    OSWrite ReportList on 'D:\FITemp\FormCounts.csv'
*    
* return

* Fix:
*    debug
*    RDSList = Xlate('SYSLISTS', 'TEST_DANIEL6', '', 'X')
*    Open 'RDS' to TableVar then
*        Open 'DICT.RDS' to @Dict then
*            Make.List(0, RDSList, TableVar, @Dict)
* 
*            If Get_Status(errCodes) Then
*                FSMsg(errCodes)
*            end else
*                EOF = False$
*                Loop
*                    Readnext @ID else EOF = True$
*                    
*                Until EOF
*                
*                Repeat
*            end
*        end
*    end
*    
* return
    
*    RDSList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL_BAD')
*    
*    Def              = ""
*    Def<MCAPTION$>   = "Scanning records..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = DCount(RDSList, @FM)
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message    
*        
*    For each RDSNo in RDSList using @FM setting fPos
*        RRRec         = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
*        WfrStages     = RRRec<REACT_RUN_WFR_STAGE$>
*        Locate 'PLATO' in WfrStages using @VM setting PlatoPos then
*            Locate 'CAN_PRE' in WfrStages using @VM setting CanPrePos then
*                If PlatoPos LT CanPrePos then
*                    BadList<-1> = RDSNo
*                end
*            end
*        end
*        GaNStageRoute = RRRec<REACT_RUN_GAN_STAGE_ROUTE$>
*        Locate 'PLATO' in GaNStageRoute using @VM setting PlatoPos then
*            Locate 'CAN_PRE' in GaNStageRoute using @VM setting CanPrePos then
*                If PlatoPos LT CanPrePos then
*                    Locate RDSNo in BadList using @FM setting bPos else
*                        BadList<-1> = RDSNo
*                    end
*                end
*            end
*        end
*        Running  = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
*    Next RDSNo
*    
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL_BAD', BadList)
*    Msg(@WINDOW,MsgUp)
    
* return
* 
* 
* Scan:
*    
*    debug
*    BadList = ''
*    RDSList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_GAN')
*    
    Def              = ""
    Def<MCAPTION$>   = "Scanning records..."
    Def<MTYPE$>      = "GC"
    Def<MEXTENT$>    = DCount(RDSList, @FM)
    Def<MTEXTWIDTH$> = 600
    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    
*    For each RDSNo in RDSList using @FM setting fPos
*        RRRec         = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
*        WfrStages     = RRRec<REACT_RUN_WFR_STAGE$>
*        Locate 'PLATO' in WfrStages using @VM setting PlatoPos then
*            Locate 'CAN_PRE' in WfrStages using @VM setting CanPrePos then
*                If PlatoPos LT CanPrePos then
*                    BadList<-1> = RDSNo
*                end
*            end
*        end
*        GaNStageRoute = RRRec<REACT_RUN_GAN_STAGE_ROUTE$>
*        Locate 'PLATO' in GaNStageRoute using @VM setting PlatoPos then
*            Locate 'CAN_PRE' in GaNStageRoute using @VM setting CanPrePos then
*                If PlatoPos LT CanPrePos then
*                    Locate RDSNo in BadList using @FM setting bPos else
*                        BadList<-1> = RDSNo
*                    end
*                end
*            end
*        end
*        Running  = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
*    Next RDSNo
*    
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL_BAD', BadList)
*    Msg(@WINDOW,MsgUp)
*    
* return
    
*    FormNames  = ''
*    FormCounts = ''
*    EOF        = False$
*    Open 'FORM_METRICS' to hTable then
*        Select hTable
*        Loop
*            Readnext Key else EOF = True$
*        Until EOF
*            FormName = Field(Key, '*', 1)
*            Locate FormName in FormNames using @VM setting vPos then
*                FormCounts<0, vPos> = FormCounts<0, vPos> + 1
*            end else
*                FormNames<0, -1>  = FormName
*                FormCounts<0, -1> = 1
*            end
*        Repeat
*    end
*    ReportData = FormNames:@FM:FormCounts
*    
*    Swap @VM with ',' in ReportData
*    Swap @FM with CRLF$ in ReportData
*    OSWrite ReportData on 'D:\FITemp\FormCounts.csv'
*    
* return

*    debug
*    NCRRec = Database_Services('ReadDataRow', 'NCR', 185742)
*    RejQty = obj_NCR('RejQty', 185742:@RM:NCRRec)
    
*    StationID = 'MESSA005_7300'
    
*    NumLoop   = 30
*    LoopIndex = 1
*    Loop
*        
*        Messaging_Services('SendMessage', 'RefreshSchedule', 'Response', @User4, 'DANIEL_ST', @User4, 'EventHandler', 'SCHEDULER_DEV' : ',OMNIEVENT,@MESSAGE,@ARGUMENTS')
*        LoopIndex += 1
*        Sleepery(10000)
*    Until LoopIndex EQ NumLoop
*    Repeat    
*    
* end
    
*    KeyList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL4')
*    For each Key in KeyList using @FM setting fPos
*        CurrStatus = Xlate('WO_MAT', '165242*39', 'CURR_STATUS', 'X')
*        Rec = Database_Services('ReadDataRow', 'WO_MAT', Key)
*        Database_Services('WriteDataRow', 'WO_MAT', Key, Rec, True$, False$, True$)
*    Next Key
    
    
*    Start_Window('NDW_FIND_LOCK_OWNER', '', 'RDS':@FM:511791)
    
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,NCR_ACTIONS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,COMM_DIALOG_TOOL_STATUS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,WO_DAILY_SCHED_ALL_COMM', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,NCR_ACTIONS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,COMM_WO_MAT_WFR', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_WO_MAT', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_RDS2', '', '', '')
* return
* end
*    
*    debug
*    Wfrs = Material_Services('GetAvailableMakeupWafers', 170929)
*    Start_Window('NDW_MAKEUP_WAFER_NCR', '', 4723)
    
* return

    FormNames  = ''
    FormCounts = ''
    EOF        = False$
    Open 'FORM_METRICS' to hTable then
        Select hTable
        Loop
            Readnext Key else EOF = True$
        Until EOF
            FormName = Field(Key, '*', 1)
            Locate FormName in FormNames using @VM setting vPos then
                FormCounts<0, vPos> = FormCounts<0, vPos> + 1
            end else
                FormNames<0, -1>  = FormName
                FormCounts<0, -1> = 1
            end
        Repeat
    end
    ReportData = FormNames:@FM:FormCounts
    
    Swap @VM with ',' in ReportData
    Swap @FM with CRLF$ in ReportData
    OSWrite ReportData on 'D:\FITemp\FormCounts.csv'
    
return
*    
*    Dialog_Box('NDW_FIND_LOCK_OWNER', '', 'RDS':@FM:508982)
*    debug
*    WONo = 170877
*    For CassNo = 11 to 32
*        WOMatKey   = WONo:'*':CassNo
*        WOMatQARec = Database_Services('ReadDataRow', 'WO_MAT_QA', WOMatKey)
*        If Error_Services('NoError') then
*            Stages     = WOMatQARec<WO_MAT_QA_STAGE$>
*            Props      = WOMatQARec<WO_MAT_QA_PROP$>
*            For each Stage in Stages using @VM setting vPos
*                Prop = Props<0, vPos>
*                If ( (Stage EQ 'UNLOAD' or Stage EQ 'QA') and (Prop EQ 'THICK') ) then
*                    WOMatQARec<WO_MAT_QA_MIN$, vPos> = '2.81'
*                end
*            Next Stage
*            Database_Services('WriteDataRow', 'WO_MAT_QA', WOMatKey, WOMatQARec, True$, False$, True$)
*        end else
*            ErrMsg(Error_Services('GetMessage'))
*        end
*    Next CassNo
*    
*    
*    
*    
* return
* 
*    debug
*    WONo = 170964
*    For CassNo = 1 to 30
*        WMKey = WONo:'*1*':CassNo
*        WMRec = Database_Services('ReadDataRow', 'WM_IN', WMKey)
*        Database_Services('WriteDataRow', 'WM_IN', WMKey, WMRec)
*        WMRec = Database_Services('ReadDataRow', 'WM_OUT', WMKey)
*        Database_Services('WriteDataRow', 'WM_OUT', WMKey, WMRec)
*    Next CassNo
* return
*    Counter          = 0
    Def              = ""
    Def<MCAPTION$>   = "Updating statuses..."
    Def<MTYPE$>      = "GC"
    Def<MEXTENT$>    = 3038
    Def<MTEXTWIDTH$> = 600
    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
    For RDSNo = 506000 to 509038
        Counter += 1
        Running  = Msg(@WINDOW, MsgUp, Counter, MSGINSTUPDATE$) ;* Update message
        Material_Services('UpdateRDSStatus', RDSNo)
    Next RDSNo
    Msg(@WINDOW,MsgUp)
*    List             = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL4')
*    Def              = ""
*    Def<MCAPTION$>   = "Cleaning queue..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = DCount(List, @FM)
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    For each Key in List using @FM setting fPos
*        Running       = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
*        Database_Services('DeleteDataRow', 'POST_LOG', Key)
*        
*    Next Key
*    Msg(@WINDOW,MsgUp)
* return 
*    Authenticated = False$
*    
*    If MemberOf(@USER4, 'OI_ADMIN') then
*        ParentForm = 'NDW_MAIN'
*    end else
*        ParentForm = 'LSL_MAIN2'
*    end
*    Loop
*        debug
*        Response      = Dialog_Box('NDW_VERIFY_USER', @Window, @USER4)
*        Authenticated = Response<1>
*        If Not(Authenticated) then
*            ErrorMessage = 'You must reauthenticate to continue running your old version of OpenInsight.'
*            rv           = Msg('', '', 'OK', '', 'Authentication Required':@FM:ErrorMessage)
*        end
*    Until Authenticated
*    Repeat
*    Security_Services('VerifyUserSessions')
* 
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,OBJ_NCR', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,COMM_NCR', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,RDS_UNLOAD_EVENTS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,NCR_ACTIONS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,WORK_ORDER_SERVICES', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,MATERIAL_SERVICES', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,WO_LOG_ACTIONS', '', '', '')
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,REACT_RUN_ACTIONS', '', '', '')
*    
* return
*    
*    
*    BadList          = ''
*    WOMatKeys        = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL4')
*    NumKeys          = DCount(WOMatKeys, @FM)
*    Def              = ""
*    Def<MCAPTION$>   = "Scanning WO_MAT records..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = NumKeys
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    For each WOMatKey in WOMatKeys using @FM setting fPos
*        Running       = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
*        WOMatRec      = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*        NCRNos        = WOMatRec<WO_MAT_NCR_KEYS$>
*        NCRFinalSigs  = WOMatRec<WO_MAT_NCR_FINAL_SIG$>
*        NumClosedNCRs = 0
*        For each NCRNo in NCRNos using @VM setting vPos
*            NCRStatus = Xlate('NCR', NCRNo, 'STATUS', 'X')
*            If NCRStatus EQ 'C' then NumClosedNCRs += 1
*        Next NCRNo
*        NCRNoCnt = COUNT(NCRNos,@VM) + (NCRNos NE '')
*        NCRSigCnt = COUNT(NCRFinalSigs,@VM) + (NCRFinalSigs NE '')
*        
*        If ( (NCRNoCnt NE NCRSigCnt) and (NCRNoCnt EQ NumClosedNCRs) ) then
*            BadList<-1> = WOMatKey
*        end
*    Next WOMatKey
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL4_BAD', BadList)
*    Msg(@WINDOW,MsgUp)      ;* Take message down
* return
*    
*    
*    Database_Services('ActivateRecord', 'RDS', 477390)
*    WOMatKey        = {WO_MAT_KEY}
*    WOMatRepStatus  = obj_WO_Mat('ReportStatus', WOMatKey)
*    WOMatCurrStatus = obj_WO_Mat('CurrStatus', WOMatKey)
*    WOMatRepStatus = XLATE('WO_MAT',{WO_MAT_KEY},'REP_STATUS','X')
*    RunStatus      = XLATE('REACT_RUN',@ID,'RUN_STATUS','X')
* 
*    RunStatus = OCONV(RunStatus,'[RUN_STATUS_CONV]')
* 
*    BEGIN CASE
*         CASE WOMatRepStatus NE '' AND RunStatus NE ''
*              Ans = WOMatRepStatus
*             
*          CASE WOMatRepStatus = '' AND RunStatus NE ''
*              Ans = RunStatus
*             
*          CASE WOMatRepStatus NE '' AND RunStatus = ''
*               Ans = WOMatRepStatus
*               
*           CASE 1
*                Ans = ''
*    END CASE
*    
*    
*    
*    Material_Services('UpdateRDSStatus', 477390)
*    RDSList = Xlate('WO_STEP', '170520*1', 'RDS_KEY', 'X')
*    For each RDSNo in RDSList using @VM setting vPos
*        Material_Services('UpdateRDSStatus', RDSNo)
*    Next RDSNo
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'All', 'RTP27,RDS_ACTIONS', 'Procedure', '', '')
* 
* return
*    
*    WMOList    = ''
*    WMOList<1> = 19
*    WMOList<2> = 20
*    WMOList<3> = 21
*    WMOList<4> = 22
*    WMOList<5> = 23
*    For each CassNo in WMOList using @FM
*        WMOKey = '170820*1*':CassNo
*        Material_Services('PostWMOutUpdateRequest', WMOKey)
*    Next CassNo
*    
*    RDSList     = ''
*    RDSList<1>  = 506491
*    RDSList<2>  = 506492
*    RDSList<3>  = 506499
*    RDSList<4>  = 506500
*    RDSList<5>  = 506501
*    RDSList<6>  = 506502
*    RDSList<7>  = 506519
*    RDSList<8>  = 506522
*    RDSList<9>  = 506530
*    RDSList<10> = 506532
*    RDSList<11> = 506533
*    RDSList<12> = 506537
*    RDSList<13> = 506538
*    For each RDSNo in RDSList using @FM
*        Material_Services('UpdateRDSStatus', RDSNo)
*        RunStatus = obj_React_Run('RunStatus', RDSNo)
*        RDS_React_Run(RDSNo)    
*        
* 
* 
*    Next RDSNo
*    
* return
*    
*    Counter          = 1
*    ReportData       = ''
*    ReportData<1, 1> = 'RDSNo'
*    ReportData<1, 2> = 'COMB_STATUS'
*    ReportData<1, 3> = 'COMB_STATUS_STATIC'
*    For RDSNo = 505143 to 506143
*        Counter                += 1
*        CombStatus              = Xlate('RDS', RDSNo, 'COMB_STATUS', 'X')
*        CombStatusStatic        = Xlate('RDS', RDSNo, 'COMB_STATUS_STATIC', 'X')
*        ReportData<Counter, 1>  = RDSNo
*        ReportData<Counter, 2>  = CombStatus
*        ReportData<Counter, 3>  = CombStatusStatic
*    Next RDSNo
*    Swap @FM with CRLF$ in ReportData
*    Swap @VM with ',' in ReportData
*    OSWrite ReportData on 'D:\apps\Temp\COMB_STATUS.csv'
*    
* return
* 
* 
* Process:
* 
*    debug
*    KeyList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL4')
*    KeyList = Delete(KeyList, 1, 0, 0)
*    For each Key in KeyList using @FM setting fPos
*        Database_Services('DeleteDataRow', 'SQL_BACKLOG', Key)
*    Next Key
*    
*    
*    
* return
*    debug
*    Counter      = 0
*    ErrorList    = ''
*    TableName    = 'RDS'
*    CursorVar    = ''
*    Flag         = ''
*    SortList     = '#SEQ'
*    ReduceScript = 'WITH {SEQ} LT 400000'
*    Mode         = 1 ; // Use next cursor available
*    EOF          = False$
*    
*    Reduce(ReduceScript, SortList, Mode, TableName, CursorVar, Flag)
*    If Flag then
*        Select TableName By SortList Using CursorVar then
*            Def              = ""
*            Def<MCAPTION$>   = "Populating RDS COMB_STATUS_STATIC..."
*            Def<MTYPE$>      = "GC"
*            Def<MEXTENT$>    = @RecCount
*            Def<MTEXTWIDTH$> = 600
*            MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*            Loop 
*                Readnext KeyID using CursorVar by AT else EOF = True$
*            Until EOF
*                Counter += 1
*                Running  = Msg(@WINDOW, MsgUp, Counter, MSGINSTUPDATE$) ;* Update message
*                Material_Services('UpdateRDSStatus', KeyID)
*                If Error_Services('HasError') then
*                    ErrorList<-1> = KeyID
*                end
*            Repeat
*        End else
*            status = Set_FSError()
*        end
*    end
*    Msg(@WINDOW,MsgUp)      ;* Take message down
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL4', ErrorList)
*    
* return
* 
* 
* Script:
*    
*    Def              = ""
*    Def<MCAPTION$>   = "Posting Requests..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = 77442
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    
*    Counter = 0
*    For RDSNo = 428000 to 505442
*        Counter += 1
*        Material_Services('PostRDSUpdateRequest', RDSNo)
*        Running  = Msg(@WINDOW, MsgUp, Counter, MSGINSTUPDATE$) ;* Update message
*    Next RDSNo
*    
*    Msg(@WINDOW,MsgUp)      ;* Take message down
*    
* return
* 
* 
* CompileMessage:
*    
*    Messaging_Services('SendMessage', 'RunProcedure', 'Request', '', 'DANIEL_ST', 'RTP27,NDW_TOOL_STATUS_GAN_EVENTS', 'Procedure', '', '')
*    
* return
* 
*    FormNames  = ''
*    FormCounts = ''
*    EOF        = False$
*    Open 'FORM_METRICS' to hTable then
*        Select hTable
*        Loop
*            Readnext Key else EOF = True$
*        Until EOF
*            FormName = Field(Key, '*', 1)
*            Locate FormName in FormNames using @VM setting vPos then
*                FormCounts<0, vPos> = FormCounts<0, vPos> + 1
*            end else
*                FormNames<0, -1>  = FormName
*                FormCounts<0, -1> = 1
*            end
*        Repeat
*    end
*    ReportData = FormNames:@FM:FormCounts
*    
*    Swap @VM with ',' in ReportData
*    Swap @FM with CRLF$ in ReportData
*    OSWrite ReportData on 'D:\FITemp\FormCounts.csv'
*    
* return
*    
*    LoopIndex = 0
*    Loop
*        LoopIndex += 1
*        Messaging_Services('SendMessage', 'RefreshSchedule', 'Response', @User4, 'MESSA005_15076', @User4, 'EventHandler', 'SCHEDULER_DEV' : ',OMNIEVENT,@MESSAGE,@ARGUMENTS')        
*        Sleepery(20000)
*    Until LoopIndex EQ 10
*    Repeat
*    
*    
* return
*    
*    
*    Open 'REPLICATION_QUEUE_LSL2_WO_MAT' to TableHandle then
*        Select TableHandle
*        EOF = False$
*        Loop
*            ReadNext @ID else EOF = True$
*        Until EOF
*            TransType = Field(@ID, '*', 1)
*            If TransType EQ 'WRITE' then
*                Delete TableHandle, @ID then Null
*            end
*        Repeat
*    end
*    
*    
*    
*    
*    
*    
*    
* return
* 
*    WONo     = 170528
*    CassNo   = 29
*    WOMatKey = WONo:'*':CassNo
*    WOMatRec = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*    GRProps  = obj_WO_Mat('GetGRProps', WOMatKey:@RM:WOMatRec)
*    GRWfrQty
*    ScrapQty
*    ProdTWQty
*    AvailMUWfrQty
*    MUCassIDs
*    MUCassQtys
*    
* return
* 
*    
*    483953
*    BadList     = ''
*    NextRDSKey  = 475000
*    StartRDSKey = 400000
*    StopRDSKey  = Xlate('DICT.RDS', '%SK%', '', 'X') - 1
*    NumKeys     = StopRDSKey - StartRDSKey
*    Counter     = 0
*    
*    Def              = ""
*    Def<MCAPTION$>   = "Scanning RDS records..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = NumKeys
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    
*    For RDSNo = StartRDSKey to StopRDSKey
*        Counter   += 1
*        WOMatKey   = Xlate('RDS', RDSNo, 'WO_MAT_KEY', 'X')
*        MakeupBox  = Xlate('WO_MAT', WOMatKey, 'MAKEUP_BOX', 'X')
*        If MakeupBox NE True$ then
*            InvLocs    = Xlate('WO_MAT', WOMatKey, 'INV_LOCATION', 'X')
*            InvActions = Xlate('WO_MAT', WOMatKey, 'INV_ACTION', 'X')
*            Locate 'PTO' in InvLocs using @VM setting vPos else
*                QASig     = Xlate('RDS', RDSNo, 'SUP_VER_SIG', 'X')
*                If QASig NE '' then
*                    BadList<-1> = RDSNo
*                end
*            end
*        end
*        Running = Msg(@WINDOW, MsgUp, Counter, MSGINSTUPDATE$) ;* Update message
*    Next RDSNo
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL5', BadList)
*    
*    Msg(@WINDOW,MsgUp)      ;* Take message down
*    
* return
* 
* 
* Fixit:
*    debug
*    Timestamp = Datetime()
*    ErrorList = ''
*    KeyList   = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL4')
*    NumKeys   = DCount(KeyList, @FM)
*    
*    Def              = ""
*    Def<MCAPTION$>   = "Fixing Material Log Entries..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = NumKeys
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    
*    For each RDSNo in KeyList using @FM setting fPos
*        RDSNo    = Xlate('WO_MAT', WOMatKey, 'RDS_NO', 'X')
*        WOMatKey = Xlate('RDS', RDSNo, 'WO_MAT_KEY', 'X')
*        If WOMatKey NE '' then
*            WOMatRec   = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*            InvActions = WOMatRec<WO_MAT_INV_ACTION$>
*            Locate '1QA' in InvActions using @VM setting vPos else
*                Locate 'LBLCHK' in InvActions using @VM setting vPos then
*                    QASig                          = Xlate('RDS', RDSNo, 'SUP_VER_SIG', 'X')
*                    QASigTime                      = Xlate('RDS', RDSNo, 'SUP_VER_SIG_TIME', 'X')
*                    QASigDate                      = Xlate('RDS', RDSNo, 'SUP_VER_SIG_DATE', 'X')
*                    QASigDTM                       = QASigDate + (QASigTime/86400)
*                    WOMatRec<WO_MAT_INV_ACTION$>   = Insert(WOMatRec<WO_MAT_INV_ACTION$>, 0, vPos, 0, '1QA')
*                    WOMatRec<WO_MAT_INV_WH$>       = Insert(WOMatRec<WO_MAT_INV_WH$>, 0, vPos, 0, 'CR')
*                    WOMatRec<WO_MAT_INV_LOCATION$> = Insert(WOMatRec<WO_MAT_INV_LOCATION$>, 0, vPos, 0, 'QA')
*                    WOMatRec<WO_MAT_INV_USER$>     = Insert(WOMatRec<WO_MAT_INV_USER$>, 0, vPos, 0, 'OI ADMIN')
*                    WOMatRec<WO_MAT_INV_DTM$>      = Insert(WOMatRec<WO_MAT_INV_DTM$>, 0, vPos, 0, Timestamp)
*                    WOMatRec<WO_MAT_INV_TAG$>      = Insert(WOMatRec<WO_MAT_INV_TAG$>, 0, vPos, 0, '')
*                    WOMatRec<WO_MAT_INV_TOOL_ID$>  = Insert(WOMatRec<WO_MAT_INV_TOOL_ID$>, 0, vPos, 0, '')
*                    
*    *                WOMatRec<WO_MAT_INV_ACTION$, -1>   = 'PLACE'
*    *                WOMatRec<WO_MAT_INV_WH$, -1>       = '1K'
*    *                WOMatRec<WO_MAT_INV_LOCATION$, -1> = 'PTI'
*    *                WOMatRec<WO_MAT_INV_USER$, -1>     = 'OI_ADMIN'
*    *                WOMatRec<WO_MAT_INV_DTM$, -1>      = Timestamp
*    *                WOMatRec<WO_MAT_INV_TAG$, -1>      = RDSNo
*    *                WOMatRec<WO_MAT_INV_TOOL_ID$, -1>  = ''
*                    
*                    Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRec, True$, False$, True$)
*                    If Error_Services('HasError') then
*                        ErrorList<-1> = RDSNo
*                    end
*                end
*            end
*        end else
*            ErrorList<-1> = RDSNo
*        end
*        Running = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
*    Next WOMatKey
*    
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL_ERROR', ErrorList)
*    
*    Msg(@WINDOW,MsgUp)      ;* Take message down
*    
* return
* 
*    debug
*    WOMatKey = '170542*30'
*    // Write success packaging
*    LogFile  = 'WO_MAT'               
*    Action   = 'PACK'                
*    WhCd     = 'CR'
*    LocCd    = 'PACK'
*    UserID   = @User4
*    Tag      = 'Packaging complete'
*    ToolID   = ''
*        
*    WONo    = Field(WOMatKey, '*', 1, 1)
*    CassNo  = Field(WOMatKey, '*', 2, 1)
*        
*    InvDTM		= OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')	        
*    Set_Status(0)
*    aiParms	= 'WO_MAT':@RM:WONo:@RM:CassNo:@RM:WhCd:'*':LocCd:@RM:Action:@RM:InvDTM:@RM:UserID:@RM:Tag:@RM:ToolID
*    obj_WO_Mat('AddInvTrans', aiParms)
*    If Get_Status(errCode) then
*        debug
*        Null
*    end
*    
* return
* 
* Script:
*    
*    WOMatKey = '170599*2'
*    LogFile  = 'WO_MAT'               
*    Action   = 'PLACE'                
*    WhCd     = 'CR'
*    LocCd    = 'QA'
*    UserID   = @User4
*    Tag      = '170599.2'
*    ToolID   = ''
*    errCode  = ''
*    WONo     = Field(WOMatKey, '*', 1, 1)
*    CassNo   = Field(WOMatKey, '*', 2, 1)       
*    InvDTM   = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')
*    
*    WOMLParms  = LogFile:@RM
*    WOMLParms := InvDTM:@RM
*    WOMLParms := Action:@RM
*    WOMLParms := WhCd:@RM
*    WOMLParms := LocCd:@RM
*    WOMLParms := WONo:@RM
*    WOMLParms := CassNo:@RM
*    WOMLParms := UserID:@RM
*    WOMLParms := Tag:@RM
*    WOMLParms := ToolID 
*    
*    Set_Status(0)
*    obj_WO_Mat_Log('Create',WOMLParms)
*    
*    aiParms	= 'WO_MAT':@RM:WONo:@RM:CassNo:@RM:WhCd:'*':LocCd:@RM:Action:@RM:InvDTM:@RM:UserID:@RM:Tag:@RM:ToolID
*    obj_WO_Mat('AddInvTrans', aiParms)
*    
*    errCode = ''                   
* 
*    IF Get_Status(errCode) THEN
*        debug
*    end
*    
* return
* 
* Script:
* debug
*    BadList = ''
*    RDSNos  = 482815:@FM ; //Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL_LIST')
*    For each RDSNo in RDSNos using @FM setting fPos
*        WfrIDs = Xlate('REACT_RUN', RDSNo, 'IN_WFR_ID', 'X')
*        For each WfrID in WfrIDs using @VM setting vPos
*            GaN_Services('WithdrawWfr', RDSNo, WfrID)
*        Next WfrID
*        GaN_Services('SplitSelection', RDSNo)
*        ReactRunRec = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
*        If Error_Services('NoError') then
*            ReactRunRec<REACT_RUN_DISP_COMPLETE$> = ''
*            Database_Services('WriteDataRow', 'REACT_RUN', RDSNo, ReactRunRec, True$, False$, True$)
*            If Error_Services('HasError') then
*                BadList<-1> = RDSNo
*            end
*        end else
*            BadList<-1> = RDSNo
*        end
*    Next RDSNo
* 
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL_ERROR', BadList)
*    
*    
* return
*    
* 
* 
* return
* 
*    OPEN 'SCHED_DET_NG' TO SchedDetTable then
*        OPEN 'DICT.SCHED_DET_NG' TO @DICT then
*            Today        = Datetime()
*            SchedDetKeys = ''
*            SelectSent   = 'SELECT SCHED_DET_NG WITH STOP_DTM GE ':Today:' BY REACT_NO'
* 
*            RList(SelectSent,TARGET_ACTIVELIST$,'','','')
*            IF Get_Status(errCode) THEN
*                ErrMsg(errCode)
*                RETURN
*            END
* 
*            Done = 0
*            @ID  = ''
*            LOOP
*                PrevSchedDetKey = @ID
*                READNEXT @ID ELSE Done = 1
*            UNTIL Done
*                SchedDetKeys<-1> = @ID
*            REPEAT
*            Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL2', SchedDetKeys)
*        end
*    end
*    
*    
* return
* 
*    WONo    = 170326
*    For CassNo = 1 to 76 step 1
*        WOMatKey                  = WONo:'*':CassNo
*        WOMatRec                  = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*        WOMatRec<WO_MAT_WMI_KEY$> = WONo:'*1*':CassNo
*        WOMatRec<WO_MAT_WMO_KEY$> = WONo:'*1*':CassNo
*        Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRec, True$, False$, True$)
*    Next CassNo
*    
*    
*    KeyList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL4')
*    For each RDSNo in KeyList using @FM
*        
*        RDSTestKeys = Xlate('RDS', RDSNo, 'RDS_TEST_KEYS', 'X')
*        If RDSTestKeys NE '' then
*            For each RDSTestKey in RDSTestKeys using @VM
*                RDSTestRec                             = Database_Services('ReadDataRow', 'RDS_TEST', RDSTestKey)
*                RDSTestRec<RDS_TEST_SPEC_RES_MRECIPE$> = 'LSL_8IN'
*                Database_Services('WriteDataRow', 'RDS_TEST', RDSTestKey, RDSTestRec)
*            Next RDSTestKey
*        end
*        
*    Next RDSNo
*    
*    CtrlVer = 1.2
*    Msg(@Window, '', 'OK', '', 'Control Version':@FM:CtrlVer)
*    *Version = SRP_Get_FileVersion("D:\apps\OICurrent\SRPControls.ocx")
*    Version = SRP_Get_FileVersion("C:\Program Files (x86)\RevSoft\OIClient\SRPControls.ocx")
*    
* return 
*    
*    CutoffDate = Date() - 912 ; // 2.5 years
*    RemoveList = ''
*    KeyList    = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
*    For each WOMatKey in KeyList using @FM setting fPos
*        
*        WONo      = Field(WOMatKey, '*', 1)
*        WOEntryDt = Xlate('WO_LOG', WONo, 'ENTRY_DATE', 'X')
*        If WOEntryDt LT CutoffDate then
*            RemoveList<-1> = WOMatKey
*        end
*        
*        ReactType = Xlate('WO_MAT', WOMatKey, 'REACTOR_TYPE', 'X')
*        If ReactType EQ 'EPP' then
*            
*        end else
*            RDSNo      = Xlate('WO_MAT', WOMatKey, 'RDS_NO', 'X')
*            DateOut    = Xlate('RDS', RDSNo, 'DATE_OUT', 'X')
*            CutoffDate = Date() - 730
*            If ( (DateOut LT CutoffDate) or (DateOut EQ '') ) then
*                // Old makeup cassette 
*            end
*        end
*        
*    Next WOMatKey
*    
*    Database_Services('WriteDataRow', 'SYSLISTS', 'TEST_DANIEL2', RemoveList)
*    
* return
* 
*    
*    WOMatKey = '170484*9'
*    WOMatRec = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*    debug
*    GRProps  = obj_WO_Mat('GetGRProps',WOMatKey:@RM:WOMatRec)
*    
*    WMOKey     = '170328*1*62'
*    WMORec     = Database_Services('ReadDataRow', 'WM_OUT', WMOKey)
*    CurrStatus = obj_WM_Out('CurrStatus', WMOKey:@RM:WMORec)
*    RepStatus  = Xlate('WM_OUT', WMOKey, 'REP_STATUS', 'X')
*    
*    
*    WOMatKey  = '170328*62'
*    WOMatRec  = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
*    RepStatus = obj_WO_Mat('ReportStatus', WOMatKey:@RM:WOMatRec)
* 
*    WOStepKey = '170422*1'
*    LoadCount = Sum(Xlate('WO_STEP', WOStepKey, 'ALL_RDS_WFRS_EPI_LOAD', 'X'))
*    WONo      = 170328
*    EventWfrs = 444
*    WOQty     = Xlate('WO_LOG', WONo, 'QTY', 'X')
*    FirstWfr  = (WOQty - EventWfrs) / 25
*    FirstWfr  = FirstWfr[-1, 'B.']
*    FirstWfr  = (FirstWfr * .25) + 1
*    
* return
* 
* 
*    StartDate = Date() - 1
*    EndDate   = Date() - 1
* 
*    For Date = StartDate to EndDate Step 1
*        
*        Reactor_Services('ClearWafersExpected', OConv(Date, 'D'))
*        Reactor_Services('ClearWafersProcessed', OConv(Date, 'D'))
*        Reactor_Services('CreatePerformanceTrackers', OConv(Date, 'D'), True$)
*        Reactor_Services('UpdatePerformanceTrackers', OConv(Date, 'D'), True$)
*        
*    Next Date
*    
*    
*    For Date = StartDate to EndDate Step 1
*        
*        Reactor_Services_Dev('ClearWafersExpectedDev', OConv(Date, 'D'))
*        Reactor_Services_Dev('ClearWafersProcessedDev', OConv(Date, 'D'))
*        Reactor_Services_Dev('CreatePerformanceTrackersDev', OConv(Date, 'D'), True$)
*        Reactor_Services_Dev('UpdatePerformanceTrackersDev', OConv(Date, 'D'), True$)
*        
*    Next Date
* 
*    ZombieList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
*    For each EventID in ZombieList using @FM setting fPos
*        Database_Services('DeleteDataRow', 'SCHED_DET_NG', EventID, True$, False$)
*    Next EventID
* 
* 
*    
*    RDSList     = ''
*    RDSList<-1> = 469318
*    RDSList<-1> = 469320
*    RDSKey      = Dialog_Box('NDW_RDS_QUERY', @Window, RDSList)
*    Debug
*    Messaging_Services('SendMessage', 'RefreshSchedule', 'Response', '', 'All', '', 'EventHandler', 'SCHEDULER_DEV' : ',OMNIEVENT,@MESSAGE,@ARGUMENTS')
*    EOF   = False$
*    Query = 'SELECT WO_SCHEDULE_NG WITH UNSCHED_QTY EQ 0'
*    RList(Query, TARGET_ACTIVELIST$, '', '', '')
*    Loop
*        Readnext WOLogKeyID else EOF = True$
*    Until EOF = True$
*        Database_Services('DeleteDataRow', 'WO_SCHEDULE_NG', WOLogKeyID)
*    Repeat 
*    
*    
*    WOMatKey = Xlate('RDS', 469320, 'WO_MAT_KEY', 'X')
*    WOMatKey = Xlate('RDS', 469318, 'WO_MAT_KEY', 'X')
*    
*    RType = Xlate('RDS', 469320, 'REACTOR_TYPE', 'X')
*    RType = Xlate('RDS', 469318, 'REACTOR_TYPE', 'X')
*    
*    RxList = Reactor_Services('GetReactorNumbers')
*    For each Reactor in RxList using @FM setting vPos
*        
*        ReactRec = Database_Services('ReadDataRow', 'REACTOR', Reactor)
*        If ReactRec NE '' then
*            ReactRec<REACTOR_SCHED_EVENTS$> = ''
*            Database_Services('WriteDataRow', 'REACTOR', Reactor, ReactRec, True$, False$, True$)
*        end
*        
*    Next Reactor
*    
* return
*    
*    KeyList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
*    
*    Def              = ""
*    Def<MCAPTION$>   = "Populating Test Wafer Data..."
*    Def<MTYPE$>      = "GC"
*    Def<MEXTENT$>    = Dcount(KeyList, @FM)
*    Def<MTEXTWIDTH$> = 600
*    MsgUp            = Msg(@WINDOW, Def) ;* Start gas guage message
*    
*    For each RDSNo in KeyList using @FM setting fPos
*        
*        ReactRunRec = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
*        Database_Services('WriteDataRow', 'REACT_RUN', RDSNo, ReactRunRec, True$, False$, True$)
*        Running = Msg(@WINDOW, MsgUp, fPos, MSGINSTUPDATE$) ;* Update message
*    Next RDSNo
*        
*    Msg(@WINDOW,MsgUp)      ;* Take message down
*    
* return
* 
* 
* TestRevDotNetCommon:
*   
*    //Define the dotNet version
*    RevDotNetCommon  = ''
*    DotNetHandle = StartDotNet("", '', RevDotNetCommon)
*    
*    DotNetDir = CheckDotNet('4.0'):'\'
*    SqlClientDLLPath = DotNetDir:'System.Data.dll'
*    ConnectionString = 'Password=mesa@1234@IQSDMS1!0987;Persist Security Info=True;User ID=IQSDMS1;Initial Catalog=G4Wafers_01;Data Source=messv01ec.ec.local\PROD1,53959'
*    //Specify the DLL
*    rv = Set_Property.NET(DotNetHandle, "AssemblyName", SqlClientDLLPath, RevDotNetCommon)
*    //Define the classes
*    SqlConnectionObj = Create_Class.NET(DotNetHandle, "System.Data.SqlClient.SqlConnection", 0, ConnectionString, 'System.String', RevDotNetCommon)
*    IF Get_Status(errCode) THEN
*        ErrMsg(errCode)
*    END else
*        mthds = Get_Info.Net(SqlConnectionObj, REVDOTNET_INFO_METHODS, RevDotNetCommon)
*        Set_Status(0)
*        rv = Send_Message.Net(SqlConnectionObj, "Open", RevDotNetCommon)
* 
*        IF Not(Get_Status(errCode)) THEN
*            ConnectionState = Get_Property.Net(SqlConnectionObj, "State", RevDotNetCommon)
*            
*            If ConnectionState EQ 'Open' then
*                SQLStatement  = "select [Probe_Key] from [G4Wafers_01].[dbo].[Probe3]"
*                Params        = SQLStatement:@FM:SqlConnectionObj
*                ParamTypes    = 'System.String':@FM:'RevDotNet'
*                Set_Status(0)
*                SqlCommandObj = Create_Class.NET(DotNetHandle, "System.Data.SqlClient.SqlCommand", 0, Params, ParamTypes, RevDotNetCommon)
*                If Not(Get_Status(errCode)) then
*                    SqlCommandMethods = Get_Info.Net(SqlCommandObj, REVDOTNET_INFO_METHODS)
*                    Set_Status(0)
*                    ProbeKey = Send_Message.Net(SqlCommandObj, "ExecuteScalar", RevDotNetCommon)
*                    If Not(Get_Status(errCode)) then
*                        If ( (ProbeKey NE 0) and (ProbeKey NE '') ) then
*                            NewProbeKey = ProbeKey + 1
*                            SQLStatement = 'update [G4Wafers_01].[dbo].[Probe3] set [Probe_Key] = ':NewProbeKey:' where [Probe_Key] = ':ProbeKey
*                            Set_Status(0)
*                            rv = Set_Property.NET(SqlCommandObj, "CommandText", SQLStatement, RevDotNetCommon)
*                            If Not(Get_Status(errCode)) then
*                                Set_Status(0)
*                                rv = Send_Message.Net(SqlCommandObj, "ExecuteNonQuery", RevDotNetCommon)
*                                If Not(Get_Status(errCode)) then
*                                    // Verify Probe Key was updated
*                                    SQLStatement = "select [Probe_Key] from [G4Wafers_01].[dbo].[Probe3]"
*                                    Set_Status(0)
*                                    rv = Set_Property.NET(SqlCommandObj, "CommandText", SQLStatement, RevDotNetCommon)
*                                    If Not(Get_Status(errCode)) then
*                                        Set_Status(0)
*                                        VerifyProbeKey = Send_Message.Net(SqlCommandObj, "ExecuteScalar", RevDotNetCommon)
*                                        If Not(Get_Status(errCode)) then
*                                            If VerifyProbeKey NE NewProbeKey then
*                                                // Log error 
*                                            end
*                                        end
*                                    end
*                                end
*                            end
*                        end else
*                            // Log error
*                        end
*                    end
*                end
*                rv = Send_Message.Net(SqlConnectionObj, 'Close', RevDotNetCommon)
*                ConnectionState = Get_Property.Net(SqlConnectionObj, "State", RevDotNetCommon)
*            end
*        end
*    end
*    Free_Class.Net('', RevDotNetCommon)
*    
* return
* 
* 
* Main:
* 
*    
*    objConnection = SQL_Services('GetConnectionObject', 'SPC')
*    
*    If objConnection then
*        
*        Query = "select [Probe_Key] from [G4Wafers_01].[dbo].[Probe2]"
*        SQL_Services('ExecuteQuery', objConnection, Query, True$)
*        
*        SQL_Services('DestroyConnectionObject', objConnection)
*    end
*    
*    
*    
* return
* 
* 
* 
* 
* Test5:
* 
*    ConnString = Database_Services('ReadDataRow', 'SERVERS', 'SPC')
*    ConnString = Delete(ConnString, 2, 0, 0)
*    ProviderIdx = IndexC(ConnString, 'Provider', 1)
*    ConnString = ConnString[(ProviderIdx + 1), 999]
*    ProviderEndIdx = Index(ConnString, ';', 1)
*    ConnString = ConnString[(ProviderEndIdx + 1), 999]
*    CIKey = 2409742
*    InspReq = Xlate('CLEAN_INSP', CIKey, 'SPEC_INSP_REQ', 'X')
*    If InspReq EQ '' then InspReq = Xlate('CLEAN_INSP', CIKey, 'INSP_REQ', 'X')
* 
*    InspFreq = Xlate('CLEAN_INSP', CIKey, 'INSP_INTERVAL', 'X')
*    If InspFreq NE '' then
*        // Use the stored interval
*        RDSNo        = Xlate('CLEAN_INSP', CIKey, 'RDS_NO', 'X')
*        PSNo         = Xlate('CLEAN_INSP', CIKey, 'PS_NO', 'X')
*        WONo         = Xlate('CLEAN_INSP', CIKey, 'WO_NO', 'X')
*        WOQty        = Xlate('WO_LOG', WONo, 'QTY', 'X')
*        RunNo        = Xlate('RDS', RDSNo, 'RUN_ORDER_NUM', 'X')
*        StageKey     = PSNo:'*LWI'
*        InspInterval = Xlate('PRS_STAGE', StageKey, 'INSP_INTERVAL', 'X')
*        LastRun      = ( (RunNo * 25) EQ WOQty )
*        InspReq      = ( (Mod((RunNo - 1), InspInterval) EQ 0) or LastRun )
*    end else
*        // Use the current PRS_STAGE interval
*        InspReq = Xlate('CLEAN_INSP', CIKey, 'INSP_REQ', 'X')
*    end
*    
* return
* 
* 
* Export:
*    
*    NonEppList = ''
*    WOMatList  = Database_Services('ReadDataRow', 'SYSLISTS', 'NULL_RDS_NON_EPP')
*    
*    For each WOMatKey in WOMatList using @FM setting fPos
*        
*        ReactorType = Xlate('WO_MAT', WOMatKey, 'REACTOR_TYPE', 'X')
*        If ReactorType NE 'EPP' and ReactorType NE 'GAN' then
*            NonEppList<-1> = WOMatKey
*        end
*    Next WOMatKey
*    
*    Database_Services('WriteDataRow', 'SYSLISTS', 'NULL_RDS_NON_EPP', NonEppList)
*    
*    NonEppList = Database_Services('ReadDataRow', 'SYSLISTS', 'NULL_RDS_NON_EPP')
*    Swap @FM with CRLF$ in NonEppList
*    OSWrite NonEppList on 'C:\Users\StieberD\Desktop\null-rds-non-epp.csv'
*    
*    
*    
* return
* 
* 
* 
* 
* WOMatPush:
*    
*    *    WOMatKeyList = Database_Services('ReadDataRow', 'SYSLISTS', 'FABTIME_PUSH')
*    *    
*    *    NumWOMatKeys = DCount(WOMatKeyList, @FM)
*    *    
*    *    Def               = ""
*    *    Def<MCAPTION$>    = "Updating WO_MAT..."
*    *    Def<MTYPE$>       = "GC"
*    *    Def<MEXTENT$>     = NumWOMatKeys
*    *    Def<MTEXTWIDTH$>  = 600
*    *    MsgUp             = Msg(@WINDOW, Def) ;* Start gas guage message
*    *    Table             = 'WO_MAT'
*    *    WOMatKeyListIndex = 1
*    *    NewWOMatKeyList   = WOMatKeyList
*    *    Loop
*    *        ID                 = WOMatKeyList<WOMatKeyListIndex>
*    *        Copy_Record_To_SQL(Table, ID, 1)
*    *        NewWOMatKeyList    = Delete(NewWOMatKeyList, 1, 0, 0)
*    *        WOMatKeyListIndex += 1
*    *        Database_Services('WriteDataRow', 'SYSLISTS', 'FABTIME_PUSH', NewWOMatKeyList)
*    *        Running            = Msg(@WINDOW, MsgUp, WOMatKeyListIndex, MSGINSTUPDATE$) ;* Update message
*    *    Until WOMatKeyListIndex GE NumWOMatKeys
*    *    Repeat
*    *    
*    *    Msg(@WINDOW,MsgUp)      ;* Take message down
*    
* return
*    
*    
* TaskSubmit:
*    
*    TaskID = RTI_Task_Submit('', 'TEST_DANIEL', '', '', '', '')
*    
*    If TaskID NE 0 then
*        Done         = False$
*        TaskResponse = ''
*        Loop
*            Status      = RTI_Task_Status(TaskID, TaskResponse)
*            If (Status EQ 'COMPLETED') OR (Status EQ 'ERROR') then Done = True$
*        Until Done
*        Repeat
*    end else
*        // Track if task id wasn't created at all.
*    end
*    StatusError = Get_Status(errCode)
*    If (Index(errCode, 'SHELLEXECUTE', 1)) NE 0 then StatusError = 0
* 
* 
* return
* 
*    retval = Utility("PRINTSETUP")
* 
*    IF NOT(ASSIGNED(PrinterID))		THEN PrinterID = ''
*    IF NOT(ASSIGNED(RetDefault))	THEN RetDefault = ''
* 
*    Printers	= ''
*    Default		= ''
* 
*        //PrintCount	= PrintSetupNew(Printers,Default)	;* OI routine returns printer names, driver, port information
*    //end else
*        PrintCount	= PrintSetup(PRN_GET$,'',Printers,Default)	;* OI routine returns printer names, driver, port information
*    //end
* 
*    DefPrinter	= Default[1,',']
*    DefPort		= FIELD(Default,',',3)
*    DefLine		= DefPrinter:' on ':DefPort
*    
*    If Default NE 'Microsoft XPS Document Writer,winspool,Ne00:' then
*        Null
*        PrintSetup(PRN_SET$, 'Microsoft XPS Document Writer,winspool,Ne00:')
*    end
* 
* return
* 
* 
*    // Import 6 inch Excel spreadsheet
*    
*    RetainFilepath    = 'D:\Apps\Temp\6in-IFEPI GaN Retain Inventory.xlsx'
*    RetainFilepath    = 'D:\Apps\Temp\8in-IFEpi GaN Retain Inventory.xlsx'
*    RetainFilepath    = 'D:\Apps\Temp\Sample.xlsx'
*    RetainExcelHandle = Excel_Services('OpenDocument', RetainFilepath)
*    RetainWorksheet   = 'Sheet1'
*    NumExcelRows      = Excel_Services('GetNumRows', RetainExcelHandle, RetainWorksheet)
*    
*    Open 'DICT.REACT_RUN' to @DICT then
*        For ExcelRow = 2 to NumExcelRows
* 
*            RunID        = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'A', ExcelRow) )
*            Convert @Upper.Case to @Lower.Case in RunID
*            RDSNo        = ''
*            Column       = 'GAN_RUN_ID'
*            SearchString = Column:@VM:RunID:@FM
*            Btree.Extract(SearchString, 'REACT_RUN', @DICT, RDSNo)
*            If RDSNo NE '' then
*                ReactRunRec = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
*                If Error_Services('NoError') then
*                    RRRecipe  = ReactRunRec<REACT_RUN_GAN_RECIPE$>
*                    RRPart    = Xlate('REACT_RUN', RDSNo, 'EPI_PART_NO', 'X')
*                    RRScribes = Xlate('REACT_RUN', RDSNo, 'WFR_SCRIBES', 'X')
*                    InWfrIDs  = ReactRunRec<REACT_RUN_IN_WFR_ID$>
* 
*                    * Read the data from the Excel retain spreadsheet *
*                    Recipe     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'B', ExcelRow) )                    
*                    Pocket     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'C', ExcelRow) )
*                    If Pocket _NEC 'ref' then                 
*                        Scribe     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'D', ExcelRow) )                   
*                        Grade      = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'E', ExcelRow) )                    
*                        Part       = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'F', ExcelRow) )                    
*                        WorkOrder  = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'G', ExcelRow) )
*                        RetainBox  = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'H', ExcelRow) )                   
*                        RetainSlot = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'I', ExcelRow) )
*                        Operator   = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'J', ExcelRow) )
*                        RetainDTM  = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'K', ExcelRow) )
*                        CurrLoc    = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'L', ExcelRow) )                   
*                        Status     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'M', ExcelRow) )
*                        Comment    = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'N', ExcelRow) )
* 
*                        Begin Case
*                            Case Operator _EQC 'AH'
*                                RetainSig = 'ANTHONY_H'                          
*                            Case Operator _EQC 'SB'
*                                RetainSig = 'SYEDA_B'
*                            Case Operator _EQC 'PM'
*                                RetainSig = 'PEYTON_M'
*                            Case Operator _EQC 'JL'
*                                RetainSig = 'JAVIER_L'
*                            Case Operator _EQC 'PS'
*                                RetainSig = 'PRISCILA_S'
*                            Case Operator _EQC 'NC'
*                                RetainSig = 'NIKOLAS_C'
*                            Case Operator _EQC 'HG'
*                                RetainSig = 'HECTOR_G'
*                            Case Operator _EQC 'ES'
*                                RetainSig = 'ESTEBAN_S'
*                            Case Operator _EQC 'AD'
*                                RetainSig = 'ALIYAH_D'
*                            Case Operator _EQC 'LB'
*                                RetainSig = 'LACEY_B'
*                            Case Operator _EQC 'IP'
*                                RetainSig = 'IAN_P'
*                            Case Operator _EQC 'RC'
*                                RetainSig = 'RYAN_C'
*                            Case Operator _EQC 'GR'
*                                RetainSig = 'GEORGE_R'
*                            Case Operator _EQC 'AH/JL'
*                                RetainSig = 'ANTHONY_H'
*                            Case Operator _EQC 'NC/JL'
*                                RetainSig = 'NIKOLAS_C'
*                            Case Operator _EQC 'SW'
*                                RetainSig = 'STEVEN_W'
*                            Case Otherwise$
*                                RetainSig = ''
*                        End Case
*                        
*                        // Truncate DTM to just the date, then convert to internal format
*                        RetainDate = RetainDTM[1, 'F ']
*                        RetainDate = IConv(RetainDate, 'D')
*                        
*                        * Clean the data *                    
*                        // Format the Recipe
*                        Convert @Lower.Case to @Upper.Case in Recipe
*                        // Format the Pocket                    
*                        If Pocket[1, 1] NE '0' then Pocket = '0':Pocket
*                        // Format the Scribe
*                        Convert @Lower.Case to @Upper.Case in Scribe
*                        // Format the Grade
*                        Begin Case
*                            Case Grade _EQC 'aborted'
*                                Grade = 'Aborted'
*                            Case Grade _EQC 'CT'
*                                Grade = 'CT'
*                            Case ( (Grade _EQC 'Eng  test') or (Grade _EQC 'Eng test') or (Grade _EQC 'Engtest') or (Grade _EQC 'Test') )
*                                Grade = 'Eng Test'
*                            Case Grade _EQC 'Eq Failure'
*                                Grade = 'EQ Failure'
*                            Case Grade _EQC 'Mechanical'
*                                Grade = 'Mechanical'
*                            Case Grade _EQC 'NA'
*                                Grade = 'NA'
*                            Case Grade _EQC 'retain'
*                                Grade = 'Retain'
*                            Case Grade _EQC 'scrap'
*                                Grade = 'Scrap'
*                            Case Grade _EQC 'Terminated'
*                                Grade = 'Terminated'
*                            Case Grade _EQC ''
*                                Grade = ''
*                            Case Otherwise$
*                                Null
*                        End Case
*                        // Format the Part No
*                        Convert @Lower.Case to @Upper.Case in Part
*                        // Format the Current Location
*                        Begin Case
*                            Case CurrLoc _EQC 'Cleanroom'
*                                CurrLoc = 'Cleanroom'
*                            Case ( (CurrLoc _EQC 'Wafer Destroyed') or (CurrLoc _EQC 'Wafers Destroyed') or (CurrLoc _EQC 'Wasfer Destroyed') )
*                                CurrLoc = 'Wafer Destroyed'
*                            Case CurrLoc _EQC 'Warehouse'
*                                CurrLoc = 'Warehouse'                        
*                        End Case
*                        
*                        * Write the data to the WO_WFR record *
*                        WfrIndex = Pocket + 0 ; // Convert string to integer and trim 0 padding
*                        
*                        RRScribe = RRScribes<0, WfrIndex>  
*                        WfrID = InWfrIDs<0, WfrIndex>
*                        WOWfrRec = Database_Services('ReadDataRow', 'WO_WFR', WfrID)
*                        If Error_Services('NoError') then
*                            WOWfrRec<WO_WFR_GRADE$>          = Grade
*                            WOWfrRec<WO_WFR_GAN_RUN_ID$>     = RunID
*                            WOWfrRec<WO_WFR_POCKET$>         = Pocket
*                            WOWfrRec<WO_WFR_SCRIBE$>         = Scribe
*                            WOWfrRec<WO_WFR_RETAIN_BOX$>     = RetainBox
*                            WOWfrRec<WO_WFR_RETAIN_SLOT$>    = RetainSlot
*                            WOWfrRec<WO_WFR_RETAIN_LOC$>     = CurrLoc
*                            WOWfrRec<WO_WFR_RETAIN_COMMENT$> = Comment
*                            WOWfrRec<WO_WFR_RETAIN_STATUS$>  = Status
*                            WOWfrRec<WO_WFR_RETAIN_SIG$>     = RetainSig
*                            WOWfrRec<WO_WFR_RETAIN_DT$>      = RetainDate
*                            Database_Services('WriteDataRow', 'WO_WFR', WfrID, WOWfrRec, True$, False$, True$)
*                        end                
*                    end
*                end
*            end
*        Next ExcelRow
*    end 
*    Excel_Services('CloseDocument', RetainExcelHandle)
* 
*    // Import 8 inch Excel spreadsheet
*    
*    RetainFilepath    = 'D:\Apps\Temp\8in-IFEpi GaN Retain Inventory.xlsx'
*    RetainExcelHandle = Excel_Services('OpenDocument', RetainFilepath)
*    RetainWorksheet   = 'Sheet1'
*    NumExcelRows      = Excel_Services('GetNumRows', RetainExcelHandle, RetainWorksheet)
*    
*    Open 'DICT.REACT_RUN' to @DICT then
*        For ExcelRow = 2 to NumExcelRows
* 
*            RunID        = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'A', ExcelRow) )
*            Convert @Upper.Case to @Lower.Case in RunID
*            RDSNo        = ''
*            Column       = 'GAN_RUN_ID'
*            SearchString = Column:@VM:RunID:@FM
*            Btree.Extract(SearchString, 'REACT_RUN', @DICT, RDSNo)
*            If RDSNo NE '' then
*                ReactRunRec = Database_Services('ReadDataRow', 'REACT_RUN', RDSNo)
*                If Error_Services('NoError') then
*                    RRRecipe  = ReactRunRec<REACT_RUN_GAN_RECIPE$>
*                    RRPart    = Xlate('REACT_RUN', RDSNo, 'EPI_PART_NO', 'X')
*                    RRScribes = Xlate('REACT_RUN', RDSNo, 'WFR_SCRIBES', 'X')
*                    InWfrIDs  = ReactRunRec<REACT_RUN_IN_WFR_ID$>
*                    
*                    * Read the data from the Excel retain spreadsheet *
*                    Recipe     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'B', ExcelRow) )                    
*                    Pocket     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'C', ExcelRow) )
*                    If Pocket _NEC 'ref' then                 
*                        Scribe     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'D', ExcelRow) )                   
*                        Grade      = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'E', ExcelRow) )                    
*                        Part       = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'F', ExcelRow) )                    
*                        WorkOrder  = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'G', ExcelRow) )
*                        RetainBox  = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'H', ExcelRow) )                   
*                        RetainSlot = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'I', ExcelRow) )
*                        Operator   = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'J', ExcelRow) )
*                        RetainDate = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'K', ExcelRow) )
*                        CurrLoc    = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'L', ExcelRow) )                   
*                        Status     = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'M', ExcelRow) )
*                        Comment    = Trim( Excel_Services('GetCellValue', RetainExcelHandle, RetainWorksheet, 'N', ExcelRow) )
*                        
*                        Begin Case
*                            Case Operator _EQC 'AH'
*                                RetainSig = 'ANTHONY_H'                          
*                            Case Operator _EQC 'SB'
*                                RetainSig = 'SYEDA_B'
*                            Case Operator _EQC 'PM'
*                                RetainSig = 'PEYTON_M'
*                            Case Operator _EQC 'JL'
*                                RetainSig = 'JAVIER_L'
*                            Case Operator _EQC 'PS'
*                                RetainSig = 'PRISCILA_S'
*                            Case Operator _EQC 'NC'
*                                RetainSig = 'NIKOLAS_C'
*                            Case Operator _EQC 'HG'
*                                RetainSig = 'HECTOR_G'
*                            Case Operator _EQC 'ES'
*                                RetainSig = 'ESTEBAN_S'
*                            Case Operator _EQC 'AD'
*                                RetainSig = 'ALIYAH_D'
*                            Case Operator _EQC 'LB'
*                                RetainSig = 'LACEY_B'
*                            Case Operator _EQC 'IP'
*                                RetainSig = 'IAN_P'
*                            Case Operator _EQC 'RC'
*                                RetainSig = 'RYAN_C'
*                            Case Operator _EQC 'GR'
*                                RetainSig = 'GEORGE_R'
*                            Case Operator _EQC 'AH/JL'
*                                RetainSig = 'ANTHONY_H'
*                            Case Operator _EQC 'NC/JL'
*                                RetainSig = 'NIKOLAS_C'
*                            Case Operator _EQC 'SW'
*                                RetainSig = 'STEVEN_W'
*                            Case Otherwise$
*                                RetainSig = ''
*                        End Case
*                        
*                        // Truncate DTM to just the date, then convert to internal format
*                        RetainDate = RetainDTM[1, 'F ']
*                        RetainDate = IConv(RetainDate, 'D')
*                        
*                        * Clean the data *                    
*                        // Format the Recipe
*                        Convert @Lower.Case to @Upper.Case in Recipe
*                        // Format the Pocket                    
*                        If Pocket[1, 1] NE '0' then Pocket = '0':Pocket
*                        // Format the Scribe
*                        Convert @Lower.Case to @Upper.Case in Scribe
*                        // Format the Grade
*                        Begin Case
*                            Case Grade _EQC 'aborted'
*                                Grade = 'Aborted'
*                            Case Grade _EQC 'CT'
*                                Grade = 'CT'
*                            Case ( (Grade _EQC 'Eng  test') or (Grade _EQC 'Eng test') or (Grade _EQC 'Engtest') or (Grade _EQC 'Test') )
*                                Grade = 'Eng Test'
*                            Case Grade _EQC 'Eq Failure'
*                                Grade = 'EQ Failure'
*                            Case Grade _EQC 'Mechanical'
*                                Grade = 'Mechanical'
*                            Case Grade _EQC 'NA'
*                                Grade = 'NA'
*                            Case Grade _EQC 'retain'
*                                Grade = 'Retain'
*                            Case Grade _EQC 'scrap'
*                                Grade = 'Scrap'
*                            Case Grade _EQC 'Terminated'
*                                Grade = 'Terminated'
*                            Case Grade _EQC ''
*                                Grade = ''
*                            Case Otherwise$
*                                Null
*                        End Case
*                        // Format the Part No
*                        Convert @Lower.Case to @Upper.Case in Part
*                        // Format the Current Location
*                        Begin Case
*                            Case CurrLoc _EQC 'Cleanroom'
*                                CurrLoc = 'Cleanroom'
*                            Case ( (CurrLoc _EQC 'Wafer Destroyed') or (CurrLoc _EQC 'Wafers Destroyed') or (CurrLoc _EQC 'Wasfer Destroyed') )
*                                CurrLoc = 'Wafer Destroyed'
*                            Case CurrLoc _EQC 'Warehouse'
*                                CurrLoc = 'Warehouse'                        
*                        End Case
*                        
*                        * Write the data to the WO_WFR record *
*                        WfrIndex = Pocket + 0 ; // Convert string to integer and trim 0 padding
*                        
*                        RRScribe = RRScribes<0, WfrIndex>  
*                        WfrID = InWfrIDs<0, WfrIndex>
*                        WOWfrRec = Database_Services('ReadDataRow', 'WO_WFR', WfrID)
*                        If Error_Services('NoError') then
*                            WOWfrRec<WO_WFR_GRADE$>          = Grade
*                            WOWfrRec<WO_WFR_GAN_RUN_ID$>     = RunID
*                            WOWfrRec<WO_WFR_POCKET$>         = Pocket
*                            WOWfrRec<WO_WFR_SCRIBE$>         = Scribe
*                            WOWfrRec<WO_WFR_RETAIN_BOX$>     = RetainBox
*                            WOWfrRec<WO_WFR_RETAIN_SLOT$>    = RetainSlot
*                            WOWfrRec<WO_WFR_RETAIN_LOC$>     = CurrLoc
*                            WOWfrRec<WO_WFR_RETAIN_COMMENT$> = Comment
*                            WOWfrRec<WO_WFR_RETAIN_STATUS$>  = Status
*                           WOWfrRec<WO_WFR_RETAIN_SIG$>      = RetainSig
*                           WOWfrRec<WO_WFR_RETAIN_DT$>       = RetainDate
*                           Database_Services('WriteDataRow', 'WO_WFR', WfrID, WOWfrRec, True$, False$, True$)
*                        end                
*                    end
*                end
*            end
*        Next ExcelRow
*    end 
*    Excel_Services('CloseDocument', RetainExcelHandle)
* 
* return 






