Subroutine TEST(Param1, Param2, Param3)
#pragma precomp SRP_PreCompiler

DECLARE SUBROUTINE  SEND_INFO, SEND_DYN, Utility, RList, Btree.Extract, msg, ErrMsg,Security_Err_Msg, Set_FSError, obj_Tables, Create_Table, Logging_Services, PrintSetup
DECLARE SUBROUTINE  obj_React_Run,obj_React_Run_CI,obj_RDS_Test, obj_RDS_Layer, Set_Status, BTREE.READ, obj_Post_Log, REACT_RUN_RDS, Reactor_Services, SRP_TcpClient, FTP_Services, Print_Shipment_Dev
DECLARE SUBROUTINE  Extract_SI_Keys, Btree.Extract, Set_List_Box_Data, Print_Shipment, Database_Services, Activate_Save_Select, GetTempPath, obj_Export, obj_WO_Mat, Messaging_Services, SRP_Stopwatch
DECLARE FUNCTION    obj_Popup, Dialog_Box, obj_Install, FindWindow, Security_Check, obj_rds2, obj_Tables, Get_Status, obj_ICAR, obj_Recipe, obj_JCH_Log, Min, Max, obj_Export, obj_Prod_spec
Declare function    Database_Services, Error_Services, RTI_Task_Submit, RTI_Task_Status, RTI_CreateGUID, Environment_Services, Logging_Services, MCP, PrintSetup, FTP_Services, SRP_Encode, RTI_Task_Status
Declare function    SRP_Trim, SRPLogonAPI_ValidateUser, Obj_Calendar, RTI_LH_Info, SRP_TcpClient, Date_Services, obj_WM_In, SRP_Path, RTI_IsMember, RTI_LDAP_Groups_For_User, RTI_LDAP_Groups_For_User_RTI, RTI_Task_Submit
Declare function    SQL_Services, Get_App_Info, HTTPClient_Services, NextKey, Replication_Services, Get_LH_Info
Declare subroutine  SQL_Services, Add_Repos_App, HTTPClient_Services, obj_SAP, Data_Map_Test, Fix_LH

$INSERT LOGICAL
$INSERT SEC_GROUPS_EQU
$INSERT RDS_EQU
$INSERT WO_LOG_EQU
$INSERT WO_MAT_EQUATES
$INSERT WO_STEP_EQUATES
$INSERT WM_OUT_EQUATES
$Insert COC_EQUATES
$INSERT QUOTE_SPEC_EQU
$INSERT PROD_SPEC_EQU
$INSERT RDS_TEST_EQUATES
$INSERT RDS_LAYER_EQUATES
$INSERT REACT_RUN_EQUATES
$INSERT REACT_MODE_EQUATES
$INSERT POPUP_EQUATES
$INSERT SECURITY_RIGHTS_EQU
$INSERT CLEAN_INSP_EQUATES
$insert RTI_LH_INFO_EQUATES
$insert PRINTSETUP_EQUATES
$insert REPOSITORY_EQUATES

Declare subroutine  Memory_Services

Debug

* TempList = Database_Services('ReadDataRow', 'SYSLISTS', 'TEST_DANIEL')
*    // Chomp info line
*    TempList = Delete(TempList, 1, 0, 0)
*    For each KeyID in TempList using @FM
*         Record = Database_Services('ReadDataRow', 'RUN_STAGE_WFR', KeyID)
*         Database_Services('WriteDataRow', 'RUN_STAGE_WFR', KeyID, Record, True$, False$, True$)
*    Next KeyID


Debug

A = Replication_Services('IsTableAllowedToReplicate', 'WO_MAT', 'LSL2')


Debug

QueueTable = 'COC'
TableInfo  = Get_LH_Info(QueueTable)
Fix_LH(QueueTable, 5, True$, 4)
a1         = Get_Status(StatusCode)
a2         = Status()
TableInfo  = Get_LH_Info(QueueTable)
Fix_LH(QueueTable, 5, True$, 0)
a1         = Get_Status(StatusCode)
a2         = Status()
TableInfo = Get_LH_Info(QueueTable)


Return

Debug

Value   = ''
If Num(Value) then
    a = 1
end else
    a = 0
end

Value   = Oconv(Trim(Value), 'MD0')


Debug
KeyCount    = 0
WOMATKEYIDs = Xlate('SYSLISTS', 'CRISP_TEST', '', 'X')
For Each WOMATKEYID in WOMATKEYIDs using @FM
    KeyCount   += 1
    Send_Info('KeyCount = ' : KeyCount : ', KeyID = ' : WOMatKeyID)
    Data_Map_Test('WO_MAT', WOMATKEYID)
Next WOMATKEYID

Return

OITableName = 'PROD_SPEC_REV_HIST'
OIKeyID     = '5111'

Error   = ''
Memory_Services('ReleaseHashTable')
Debug
If (OITableName NE '') AND (OIKeyID NE '') then
    OIRow   = Database_Services('ReadDataRow', OITableName, OIKeyID)
    If Error_Services('NoError') then
        SQL_Services('WriteDataRowToSQL', OITablename, OIKeyID, OIRow)
        If Error_Services('HasError') then
            Error   = Error_Services('GetMessage')
        end
    end else
        Error   = Error_Services('GetMessage')
    end
end else
    Error   = 'TableName or KeyID is missing.'
end


Return

Debug

Statement   = 'SELECT RETAINED_WAFERS WITH WAFER_SIZE EQ "150 mm 6 in"'
RList(Statement, 4, 'RETWAF', '', '')





Activate_Save_Select('RETWAF')

EOF = False$
Loop
    ReadNext ID else EOF = True$
Until EOF EQ True$
    Read Record from hTable, ID then
        
    end
Repeat




hDict   = Database_Services('GetTableHandle', 'DICT.RETAINED_WAFERS')
If Error_Services('NoError') then
    Query   = 'WAFER_SIZE' : @VM : '150 mm 6 in' : @FM
*    Query  := 'LOCATION' : @VM : 'Warehouse' : @VM : 'Cleanroom' : @FM
    KeyList = ''
    Option  = ''
    Flag    = ''
    Btree.Extract(Query, 'RETAINED_WAFERS', hDict, KeyList, Option, Flag)
    NumKeys = DCount(KeyList, @VM)
end


return

WOLogRow        = ''
WOLogRow<11>    = '' ; // Iconv('01/01/2030', 'D4/')
Database_Services('WriteDataRow', 'WO_LOG', 'TEST', WOLogRow, True$, False$, True$)

return


obj_SAP('GetInbound', 1)
return

Today = date() - 15
return today

Set_Status(0)
NextWO = NextKey('DUMMY')
If Error_Services('HasError') then
    ErrMesg = Error_Services('GetMessage')
end
return


Proc = 'TEST_DANIEL2'
hSysProcs = Database_Services('GetTableHandle', 'SYSPROCS')
Lock hSysProcs, Proc then
    HaveLock = True$
    Unlock hSysProcs, Proc else NULL
end else
    HaveLock = False$
end
return

SAPID = NextKey('SAP_HOLD')
return

UnloadPSNList = Database_Services('ReadDataRow', 'SYSLISTS', 'PROD_PSNS_UNLOAD')
// Chomp info line
UnloadPSNList = Delete(UnloadPSNList, 1, 0, 0)

For each PSN in UnloadPSNlist using @FM
    
    PRSStageKey = PSN:'*UNLOAD'
    PRSStageRec = Database_Services('ReadDataRow', 'PRS_STAGE', PRSStageKey)
    MetTests    = PRSStageRec<PRS_STAGE_MET_TEST$>
    Locate 'THICK_ONLY' in MetTests using @VM setting vPos then
        MetRecipes      = PRSStageRec<PRS_STAGE_MET_RECIPE$>
        ThickOnlyRecipe = MetRecipes<0, vPos>
        ThickOnlyRecipe = Trim(ThickOnlyRecipe)
        RecipeFound     = True$
        NewProdRecipe   = ''
        Begin Case
            Case ThickOnlyRecipe EQ 'PROD_thin6'
                NewProdRecipe = 'thin6inch'
            Case ThickOnlyRecipe EQ 'PROD_8inch'
                NewProdRecipe = '8inch'
            Case ThickOnlyRecipe EQ 'PROD_thin8'
                NewProdRecipe = 'thin8inch'
            Case ThickOnlyRecipe EQ 'PROD_IRC6'
                NewProdRecipe = 'IRC6in_6mm'
            Case ThickOnlyRecipe EQ 'PROD_Wack'
                NewProdRecipe = 'Wacker'
            Case ThickOnlyRecipe EQ 'PROD_INF'
                NewProdRecipe = '8IN_INF'
            Case Otherwise$
                 // Unexpected THICK_ONLY recipe name -> proceed to next PSN
                 RecipeFound = False$
        End Case
        
        If RecipeFound then
            MetRecipes<0, vPos> = NewProdRecipe
            PRSStageRec<PRS_STAGE_MET_RECIPE$> = MetRecipes
            Database_Services('WriteDataRow', 'PRS_STAGE', PRSStageKey, PRSStageRec)
        end

    end else
        // No THICK_ONLY metrology test -> proceed to next PSN
        NULL 
    end
    
    
Next PSN

Return 3


Query    = "Declare @Reactor    varchar(10) "
Query   := "Declare @RDS        varchar(10) "
Query   := "Declare @PSN        varchar(10) "
Query   := "Declare @WAFER      varchar(10) "
Query   := "Declare @Title      varchar(10) "
Query   := "Set @Reactor = '35' " 
Query   := "Set @RDS     = '246860' "
Query   := "Set @PSN     = '4249' "
Query   := "Set @Wafer   = '*09' "
Query   := "SELECT @Title = HeaderData.nvarchar1 "
Query   := "FROM [WSS_Content].[dbo].[AllUserData] HeaderData "
Query   := "WHERE HeaderData.tp_ListId IN ( SELECT AllLists.tp_ID FROM [WSS_Content].[dbo].[AllLists] AllLists WHERE AllLists.tp_Title = 'Tencor Run Header' OR AllLists.tp_Title = 'SP1 Run Header' ) AND "
Query   := "HeaderData.nvarchar6 = @Reactor AND "
Query   := "HeaderData.nvarchar7 = @RDS AND "
Query   := "HeaderData.nvarchar11 = @PSN "
Query   := "SELECT 'http://messa03ec.ec.local/Lists/Tencor Run Data/Attachments/' + cast(RunData.tp_ID as varchar) + '/image.pdf' "
Query   := "FROM [WSS_Content].[dbo].[AllUserData] RunData "
Query   := "WHERE RunData.nvarchar3 = @WAFER AND "
Query   := "RunData.tp_ListId IN ( SELECT AllLists.tp_ID FROM [WSS_Content].[dbo].[AllLists] AllLists WHERE AllLists.tp_Title = 'Tencor Run Data' OR AllLists.tp_Title = 'SP1 Run Data' ) AND "
Query   := "RunData.nvarchar1 LIKE @Title + '%'"

debug
objConnection   = SQL_Services('GetConnectionObject', 'messa03ec.ec.local')
If Error_Services('NoError') then
    Success = True$
    SQL_Services('DestroyConnectionObject', objConnection)
end
 

* Method      = 'GET'
* URI         = 'http://messa03ec.ec.local/Lists/Tencor Run Data/Attachments/102714/image.pdf'
* User        = 'EC\ECFISysAdmin'
* Password    = 'New@IRpwd12042017'
* rv          = HTTPClient_Services('SendHTTPRequest', Method, URI, '', '', User, Password, '', '')
* Status      = HTTPClient_Services('GetResponseStatusCode')
* Body        = HTTPClient_Services('GetResponseBody')
* If Status EQ 200 then
*    OSWrite Body to 'C:\Users\ecStieberD\Desktop\Wafer.pdf'
* end

Return
Debug

* ChildApp                          = 'LSL2'
* ParentApp                         = 'FRAMEWORKS'
* AppInfo                           = Get_App_Info(ChildApp)
* AppInfo< SYSAPPS_TEMPLATE_APP$ >  = ParentApp
* Add_Repos_App(ChildApp, AppInfo, 0)


debug

* Activate_Save_Select('NEWPORT')
* EOF     = False$
* RowCnt  = 0
* Loop
*    Readnext ShipNo else EOF = True$
* Until EOF EQ True$
*    RowCnt += 1
*    ShipRec = Database_Services('ReadDataRow', 'COC', ShipNo)
*    Print_Shipment_Dev(ShipNo, ShipRec, True$, True$)
* Repeat


Debug

objConnection   = SQL_Services('GetConnectionObject', 'mesirwdb002.irworld.irf.com')
If Error_Services('NoError') then
    QueryStatement  = 'SELECT [F_MEAN] as ProcessMean,[F_SP] as ProcessSigma '
    QueryStatement := 'FROM [SPCEPIWORLD].[dbo].[CTRL_LIM] CTRL '
    QueryStatement := 'JOIN [SPCEPIWORLD].[dbo].[PART_DAT] PART ON PART.F_PART = CTRL.F_PART '
    QueryStatement := 'JOIN [SPCEPIWORLD].[dbo].[PRCS_DAT] PROCESS ON PROCESS.F_PRCS = CTRL.F_PRCS '
    QueryStatement := 'JOIN [SPCEPIWORLD].[dbo].[TEST_DAT] TEST ON TEST.F_TEST = CTRL.F_TEST '
    QueryStatement := "WHERE PART.F_NAME = '6IN_PTYPE ROTR' AND "
    QueryStatement := "PROCESS.F_NAME = '54' AND "
    QueryStatement := "TEST.F_NAME = 'Average Sum of Defects'"
    *QueryStatement := "WHERE TEST.F_NAME = 'Average Sum of Defects'"
    DataRows        = SQL_Services('ExecuteQuery', objConnection, QueryStatement, True$)
    Message         = Error_Services('GetMessage')
    SQL_Services('DestroyConnectionObject', objConnection)
end



Debug
// Must run in a separate service on the EC Database Server.
Host            = 'ecsftp.ec.local'
Username        = 'EC\ECFIFTPSVC'
Password        = 'ECTemPwd@07092018'
LocalDirectory  = ''
RemoteDirectory = '\TEMFTP_EPIMesa\Archive'
RemoteFile      = ''
ScriptPath      = Environment_Services('GetReportsRootPath') : '\ToTemeculaNew.scr'
DeleteScript    = False$
SSH             = True$
DosPath         = 'D:\apps\Ship_Data\IFX_Temeculacsv\'
InitDir         DosPath : '*.csv'
DosTables       = DirList()
For Each DosTable in DosTables using @FM
    OSRead LocalFile from DosPath : DosTable then
        EncodedData = SRP_Encode(LocalFile, 'BASE64')
        FTP_Services('PostRequest', 'put', Host, 'MESSA01EC', '', EncodedData, Username, Password, LocalDirectory, RemoteDirectory, RemoteFile, ScriptPath, DeleteScript, SSH, '', 3, False$)
    end else
        Debug
    end

Next File

Debug
Groups1     = RTI_LDAP_Groups_For_User('smunoz1')
* Groups2     = RTI_LDAP_Groups_For_User('10.64.152.171\ECrivard')
* IsMember    = RTI_IsMember('MES-APP-FabTimeAllowed', 'infineon\rivard')
* IsLocal     = RTI_IsLocalGroupMember('Administrators', 'infineon\rivard')

Debug

Host                = 'sFTPNA.extra.infineon.com'
Username            = 'DNAMesaFI-FTP'
Password            = 'OpenInsight2018....!'
Data                = ''    ; // SRP_Encode('Hello World!', 'BASE64')
LocalFile           = 'D:\Apps\NXP 07-10-17 Pack list 141151.pdf'
RemoteFile          = 'HelloWorld.txt'
RemoteDirectory     = '/Newport'
SSH                 = True$
ProcessDirectory    = 'D:\Temp'
FTPRequestID        = FTP_Services('PostRequest', 'send', Host, 'MESSA005', LocalFile, Data, Username, Password, '', RemoteDirectory, RemoteFile, '', True$, True$, ProcessDirectory)
If Error_Services('NoError') then
*    FTP_Services('ProcessRequest', FTPRequestID)
end




return

Debug
SRP_Stopwatch('Reset')
SRP_Stopwatch('Start', 'Update WO_MAT')
hWOMat      = Database_Services('GetTableHandle', 'WO_MAT')
Activate_Save_Select('WO_MAT')
EOF         = False$
RowCount    = 0
TotalRows   = @RecCount
Loop
    Readnext KeyID else EOF = True$
Until EOF
    RowCount   += 1
    Send_Info(' Updating ' : RowCount : ' out of ' : TotalRows : ' rows. KeyID: ' : KeyID)
    WOMatRow    = Database_Services('ReadDataRow', 'WO_MAT', KeyID, '', '', False$)
    If (WOMatRow EQ '') OR (WOMatRow[1, 87] EQ (Str(@FM, 86) : '0')) then
        Database_Services('DeleteDataRow', 'WO_MAT', KeyID, '', False$)
    end else
        If (WOMatRow<WO_MAT_SAP_BATCH_NO$> EQ 0) then
            WOMatRow<WO_MAT_SAP_BATCH_NO$>  = ''
            Database_Services('WriteDataRow', 'WO_MAT', KeyID, WOMatRow, True$, False$, True$)
        end
    end
Repeat
SRP_Stopwatch('Stop', 'Update WO_MAT')
SRP_Stopwatch('ShowAll')

Debug


* Messaging_Services('SendMessage', 'GetLoggedInUsers', 'Request', '', 'STIEBERD', '', 'Procedure', 'TEST2,@MESSAGE,@ARGUMENTS', False$)
rv  = MCP('MESSAGING', 'SendMessage', 'GetLoggedInUsers', 'Request', '', 'CRISP', '', 'Procedure', 'TEST2,@MESSAGE,@ARGUMENTS', False$)
* call MCP('FLATFINDER', 'ImportFlatFinderFiles')

Return

Debug

Groups1     = RTI_LDAP_Groups_For_User('na\mescatxmuser')
Groups2     = RTI_LDAP_Groups_For_User('na\ddailey1')


Return


VolumePath  = 'LSL\REVMEDIA.LK'
If SRP_Path('IsRelative', VolumePath) then
    RevbootDrive    = Drive()
    VolumePath      = SRP_Path('Combine', RevbootDrive, VolumePath)
end
VolumePath  = SRP_Path('RemoveFilename', VolumePath)
// Make sure there is a backslash since the RTI_LH_INFO API seems to use this.
VolumePath  = SRP_Path('AddBackslash', VolumePath)

Return

Debug
CustNo = 7125
CustName = XLATE( 'COMPANY', CustNo, 'ABBREV_OR_CO_NAME', 'X' )

return

Argu    = '"foo",     "foo1"'
Argu    = Trim(Argu)

Debug

* Ans     = RTI_LH_Info(CMD_LOCK_INFO$, 'E:\APPS\OICURRENT\LSL\', 'REV43432', 'ABOUT', 'REV43432')
* Ans     = RTI_LH_Info(CMD_SESSION_INFO$)
* Ans     = RTI_LH_Info(CMD_LOCKS_INFO$, '')
* Ans     = RTI_LH_Info(CMD_TABLE_INFO$, 'APP_INFO')
Ans     = RTI_LH_Info(CMD_UNLOCK$, 'E:\APPS\OICURRENT\', 'REVREPOS', 'LSL2*STPROC**DATABASE_SERVICES', 'REVREPOS')

Return

Debug

ScheduleDate    = Iconv('05/25/2018', 'D')
NextMonday  = ScheduleDate + 3
NextSunday  = ScheduleDate + 9
* For ScheduleDate = NextMonday to NextSunday
*    Reactor_Services('CreatePerformanceTrackers', ScheduleDate, False$)
* Next ScheduleDate
// Create the weekly performance report based on the daily performance tracking data.
YearWeekNo = Date_Services('GetISOWeekDate', NextMonday)
YearWeekNo = Field(YearWeekNo, '-', 1, 2)
Reactor_Services('CreateWeeklyPerformanceReport', YearWeekNo)

Debug

Command = "RUN DATABASE_SERVICES 'GetUserLocks'"
// Call the SRPEngineService and pass it the command
Server              = Environment_Services('GetServer')
TCPServerSettings@  = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_TCPIP_SETTINGS_' : Server)
TcpClientHandle     = 0
If SRP_TcpClient(TcpClientHandle, 'CONNECT', TCPServerSettings@<1>, TCPServerSettings@<2>) then
    SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
    SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
end


Return

Debug

TableName   = 'WO_MAT'
DictVar     = Database_Services('GetTableHandle', 'DICT.' : TableName)
PartNo      = '13511'
SearchString    = ''
IF TableName = 'WO_MAT' THEN
    If @User4 EQ 'DANIEL_ST' then
        SearchString := 'MAKEUP_BOX' : @VM : 1 : @FM
        SearchString := 'PART_NO' : @VM : PartNo : @FM
    end else
        SearchString  = 'MU_PART_NO' : @VM : PartNo : @FM
    end
    SearchString := 'CURR_STATUS':@VM:'RTU':@FM
END ELSE
    SearchString = 'MU_PART_NO':@VM:PartNo:@FM
END
    
Set_Status(0)

OpenRecordIDs = ""
Option = ""
Flag = ""
Btree.Extract(SearchString, TableName, DictVar, OpenRecordIDs, option, flag)


Debug

WOMatKey        = '165570*9'
RDSNo           = '214802'
WOMatRow        = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
WOMatRow<12>    = ''        ; // Clear the RDS No so the index will be forced to recalculate.
WOMatRow<23>    = False$    ; // Clear the MakeUp box flag so the index will be forced to recalculate.
Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRow, True$, False, True$)
WOMatRow<12>    = RDSNo     ; // Restore the RDS No so the index on RDS_FINAL_SIG will be forced to recalculate with the most recent value.
WOMatRow<23>    = True$     ; // Restore the MakeUp box flag so the index will be forced to recalculate.
Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRow, True$, False, True$)
call Update_Index('WO_MAT', 'MU_PART_NO', False$, True$)
call Update_Index('WO_MAT', 'CURR_STATUS', False$, True$)



Debug

LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\Fiscal'
LogDate         = Oconv(Date(), 'D4/')
LogTime         = Oconv(Time(), 'MTS')
LogFileName     = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '.csv'
Headers         = 'WeekNo' : @FM : 'Start Date' : @FM : 'End Date' : @FM : 'Period'
ColumnWidths    = 10 : @FM : 20 : @FM : 20 : @FM : 20
objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
LoggingDTM      = LogDate : ' ' : LogTime   ; // Logging DTM

StartDate   = Iconv('10/01/2016', 'D')
EndDate     = Iconv('09/30/2018', 'D')
For Date = StartDate to EndDate
    FYInfo  = Obj_Calendar('IRFiscalWeek2', Oconv(Date, 'D4/'))
    Logging_Services('AppendLog', objLog, FYInfo, CRLF$, @FM, True$)
Next Date


Debug

* Username    = 'ddailey1'
* Domain      = 'mes.infineon.com'
* Password    = 'blahblahblah'
Username    = 'bakke'
Domain      = 'na'
Password    = 'TasRGvznjd87Jvi'
ValidUser   = SRPLogonAPI_ValidateUser(Username, Password, Domain)




Debug

TableName       = 'WO_MAT'
DictVar         = Database_Services('GetTableHandle', 'DICT.' : TableName)
SearchString    = 'MAKEUP_BOX':@VM:'1':@FM
SearchString   := 'CURR_STATUS':@VM:'RTU':@FM
rv              = Set_Status(0)
OpenRecordIDs   = ''
Option          = ''
Flag            = ''
Btree.Extract(SearchString, TableName, DictVar, OpenRecordIDs, option, flag)
For Each WOMatKeyID in OpenRecordIDs using @VM
 	WOMatRow        = Database_Services('ReadDataRow', 'WO_MAT', WOMatKeyID)
 	RDSNo           = WOMatRow<12>
 	If RDSNo NE '' then
        WOMatRow<12>    = ''    ; // Clear the RDS No so the index will be forced to recalculate.
        Database_Services('WriteDataRow', 'WO_MAT', WOMatKeyID, WOMatRow, True$, False, True$)
        WOMatRow<12>    = RDSNo ; // Restore the RDS No so the index on RDS_FINAL_SIG will be forced to recalculate with the most recent value.
        Database_Services('WriteDataRow', 'WO_MAT', WOMatKeyID, WOMatRow, True$, False, True$)
    end
Next WOMatKeyID


Debug

WOMatKey    = '165518*1'
RDSNo       = '210351'

WOMatRow        = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
WOMatRow<12>    = ''
Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRow, True$, False, True$)
WOMatRow<12>    = RDSNo
Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRow, True$, False, True$)


obj_WO_Mat('ChangeFlag',WOMatKey:@RM:12:@RM:'')                 ; // Clear the RDS No so the index will be forced to recalculate.
obj_WO_Mat('ChangeFlag',WOMatKey:@RM:12:@RM:RDSNo)              ; // Restore the RDS No so the index on RDS_FINAL_SIG will be forced to recalculate with the most recent value.


*
Debug
OSRead Log from 'E:\apps\LogFiles\GaNWIP\2018-03-06.csv' then
    NewLog  = ''
    Swap \0D0A\ with @FM in Log
    For Each Line in Log using @FM setting LineNum
        If LineNum EQ 1 then
            NewLog  := Line : \0D0A\
        end else
            If Index(Line, '165199*7*20', 1) then
                NewLog  := Line : \0D0A\
            end
        end
    Next Line
    NewLog[-2, 2]   = ''
    OSWrite NewLog to 'E:\apps\LogFiles\GaNWIP\2018-03-06-Review.csv'
end


Debug

COCKeyIDs   = Xlate('SYSLISTS', 'COC', '', 'X')
For Each COCKeyID in COCKeyIDs using @FM
    call obj_Shipment('SendTechnical', COCKeyID : @RM : 1)
Next COCKeyID

Debug

* 
* LogPath         = Environment_Services('GetApplicationRootPath') : '\LogFiles\MUBox'
* LogDate         = Oconv(Date(), 'D4/')
* LogTime         = Oconv(Time(), 'MTS')
* LogFileName     = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '.csv'
* Headers         = 'Logging DTM' : @FM : 'Service Step' : @FM : 'Service Description'
* ColumnWidths    = 20 : @FM : 40 : @FM : 150
* objLog          = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ' ', Headers, ColumnWidths, False$, False$)
* LoggingDTM      = LogDate : ' ' : LogTime   ; // Logging DTM
* Logging_Services('AppendLog', objLog, LoggingDTM : @FM : '  1' : @FM : '.', @RM, @FM)
* 
* Debug
* 
* 
* ShipNo  = '145090'
* RDSNos  = Xlate('COC', ShipNo, 'RDS_NO', 'X')
* KeyList = RDSNos
* 
* IF KeyList = '' THEN
*    ErrMsg('There are no RDS records attached to this shipment.  No data will be sent to the customer. (EpiPRO process)')
*    obj_Tables('UnlockRec',OtParms)
*    
*    RETURN
* END
* 
* SentFlag = 1
* 
* 	DosTable = 'C:\OIReports\W':ShipNo:'.csv'
* DosTable = Environment_Services('GetReportsRootPath') : '\W':ShipNo:'.csv'
* 
* ExportID = 'WALES_SYSTEM_RDS_DATA'
* NoHeader = 1	
* 
* obj_Export('ExportDelimited','Comma':@RM:KeyList:@RM:ExportID:@RM:DosTable:@RM:@RM:@RM:NoHeader, AutoFlag)
* 
* 
* Debug
* 
* StartDate   = Iconv('02/25/2018', 'D')
* EndDate     = Iconv('03/03/2018', 'D')
* 
* For ScheduleDate = StartDate to EndDate
*    Reactor_Services('CreatePerformanceTrackers', ScheduleDate)
*    Reactor_Services('UpdatePerformanceTrackers', ScheduleDate)
* Next ScheduleDate
* 
* Debug
* CSVList         = Database_Services('ReadDataRow', 'SYSLISTS', 'AD_USERS')
* ADtoLSLUserMap  = ''
* Convert ',' to @VM in CSVList
* Pos             = 0
* For Each User in CSVList using @FM
*    WindowsUser = User<0, 5>
*    If Trim(WindowsUser) NE 'Windows' AND WindowsUser NE '' then
*        Pos    += 1
*        ADtoLSLUserMap<1, Pos>  = User<0, 5>
*        ADtoLSLUserMap<2, Pos>  = User<0, 2>
*    end
* Next User
* Database_Services('WriteDataRow', 'APP_INFO', 'AD_TO_LSL_USER_MAP', ADtoLSLUserMap)
* 
* Return



Declare function RTI_IsMember, RTI_LDAP_Groups_For_User, RTI_IsLocalGroupMember

* Volume          = 'LSL'
* Table           = 'BANG_WO_MAT'
* Attributes      = ''
* Attributes<1>   = 1500000
* Attributes<2>   = 100
* Attributes<3>   = 3
* Attributes<4>   = 4096
* Attributes<5>   = 80
* rv              = Set_Status(0)
* Create_Table(Volume, Table, False$, 'LSL2', Attributes, False$)
* Status          = Get_Status(StatusCode)
* 
* Debug
* 
* hDictWOMat  = Database_Services('GetTableHandle', 'DICT.WO_MAT')
* Select hDictWOMat
* EOF = False$
* Loop
*    ReadNext DictKeyID else EOF = True$
* Until EOF
*    If DictKeyID[1, 1] NE '%' then
*        DictRow = Database_Services('ReadDataRow', 'DICT.WO_MAT', DictKeyID)
*        If DictRow<6> EQ 1 then
*            DictRow<6>  = ''
*            Database_Services('WriteDataRow', 'DICT.WO_MAT', DictKeyID, DictRow, True$, '', True$)
*        end
*    end
* Repeat
* 
Debug

Groups1     = RTI_LDAP_Groups_For_User('na\rbraini1')
* Groups2     = RTI_LDAP_Groups_For_User('10.64.152.171\ECrivard')
* IsMember    = RTI_IsMember('MES-APP-FabTimeAllowed', 'infineon\rivard')
* IsLocal     = RTI_IsLocalGroupMember('Administrators', 'infineon\rivard')
* 
* 
* infineon.com/IFX-Groups/NA/SecGrp/MES-APP-FabTimeAllowed 
* 
* Debug
* NumFields   = DCount(@Station, '_')
* Station     = Field(@Station, '_', 1, NumFields - 1)
* 
* Debug
*a           = RTI_CreateGUID()
* TempPath    = Str(\00\, 1024)
* GetTempPath(Len(TempPath), TempPath)
* Convert \00\ to '' in TempPath
* Transfer TempPath to b


Debug
EOF         = False$
NumChanged  = 0
Activate_Save_Select('WO_LOG')
Loop
    Readnext WorkOrderNo else EOF = True$
Until EOF
    WOLogRow    = Database_Services('ReadDataRow', 'WO_LOG', WorkOrderNo)
    WOMatKeyIDs = WOLogRow<31>
    For Each WOMatKeyID in WOMatKeyIDs using @VM
        WOMatRow        = Database_Services('ReadDataRow', 'WO_MAT', WOMatKeyID)
        CustPartNo      = WOMatRow<WO_MAT_CUST_PART_NO$>
        CassNo          = WOMatKeyID[-1, 'B*']
        CustNo          = Xlate('WO_MAT', WorkOrderNo : '*' : CassNo, 'CUST_NO', 'X')
        CassShipQty     = Xlate('CUST_EPI_PART', CustNo : '*' : CustPartNo, 'CASS_SHIP_QTY', 'X')
        If (WOMatRow<WO_MAT_CASS_SHIP_QTY$> NE CassShipQty) AND (WOMatRow<WO_MAT_CASS_SHIP_QTY$> EQ 23) then
            WOMatRow<WO_MAT_CASS_SHIP_QTY$> = CassShipQty
            NumChanged += 1
            Database_Services('WriteDataRow', 'WO_MAT', WOMatKeyID, WOMatRow, True$)
        end
    Next WOMatKeyID
Repeat
Debug

Return



// This method uses the missing SAP batch numbers and converts them into product order numbers and then searches
// WO_LOG for a match. From here, all shipments (COC table) are searched for a matching SAP batch number which will
// then allow the associated RDS number to be derived.
UnmatchedShippingNos    = ''
RDSNos                  = ''
EOF                     = False$
Activate_Save_Select('WO_LOG')
Loop
    Readnext WorkOrderNo else EOF = True$
Until EOF
    RDSFound    = False$
    ShipmentNos = Database_Services('SearchIndex', 'COC', 'WO', WorkOrderNo, False$)
    If Error_Services('NoError') then
        For Each ShipmentNo in ShipmentNos using @FM
            If ShipmentNo NE '' then
                COCRow  = Database_Services('ReadDataRow', 'COC', ShipmentNo)
                CassNos = COCRow<COC_CASS_NO$>
                For Each CassNo in CassNos using @VM setting vPos
                    WOMatRow        = Database_Services('ReadDataRow', 'WO_MAT', WorkOrderNo : '*' : CassNo)
                    If WOMatRow<WO_MAT_SHIP_NO$> EQ '' then
                        WOMatRow<WO_MAT_SHIP_NO$>   = ShipmentNo
                        Database_Services('WriteDataRow', 'WO_MAT', WorkOrderNo : '*' : CassNo, WOMatRow, True$, '', True$)
                        UnmatchedShippingNos    := WorkOrderNo : '*' : CassNo : @VM : ShipmentNo : @FM
                    end
                Next CassNo
            end
        Next ShipmentNo
    end
Repeat
UnmatchedShippingNos[-1, 1] = ''
Database_Services('WriteDataRow', 'SYSLISTS', 'UMATCHED_SHIPPING_NOS', UnmatchedShippingNos, True$)
Debug


Return


hCustEpiPart    = Database_Services('GetTableHandle', 'CUST_EPI_PART')
Select hCustEpiPart
EOF = 0
Loop
    ReadNext ID else EOF = 1
Until EOF = 1
    CustEpiPartRow  = Database_Services('ReadDataRow', 'CUST_EPI_PART', ID)
    CustEpiPartRow<47>  = CustEpiPartRow<27>
    Database_Services('WriteDataRow', 'CUST_EPI_PART', ID, CustEpiPartRow, 1, '', 1)
Repeat


return

Open 'DICT.WO_MAT' to hDict then
    WONos       = ''
    GoodSAPs    = ''
    BadSAPs     = ''
    SAPBatchNos = Xlate('SYSLISTS', 'SAP_BATCH_NO', '', 'X')
*    SAPBatchNos = 'M007868.1'
    For Each SAPBatchNo in SAPBatchNos using @FM
        Btree.Extract('SAP_BATCH_NO' : @VM : SAPBatchNo : @FM, 'WO_MAT', hDict, Keys, 'E', Flag)
        If (Flag EQ 0) AND (Keys NE '') then
            WONos      := Keys : @FM
            GoodSAPs   := SAPBatchNo : @FM
        end else
            BadSAPs    := SAPBatchNo : @FM
        end
    Next SAPBatchNo
end

Database_Services('WriteDataRow', 'SYSLISTS', 'SAP_GOOD', GoodSAPs, True$)
Database_Services('WriteDataRow', 'SYSLISTS', 'SAP_BAD', BadSAPs, True$)
Database_Services('WriteDataRow', 'SYSLISTS', 'SAP_WO_MATS', WONos, True$)

Debug

* StartDate   = Iconv('01/11/2018', 'D')
* EndDate     = Iconv('01/11/2018', 'D')
* 
* For ScheduleDate = StartDate to EndDate
*    Reactor_Services('ClearWafersExpected', ScheduleDate)
*    Reactor_Services('ClearWafersProcessed', ScheduleDate)
* Next ScheduleDate
* 
* For ScheduleDate = StartDate to EndDate
*    Reactor_Services('CreatePerformanceTrackers', ScheduleDate)
*    Reactor_Services('UpdatePerformanceTrackers', ScheduleDate)
* Next ScheduleDate
* 
* Debug
* 
* 
* Return
* 
* Debug
* 
* Log     = ''
* WONos   = '161483'
* For Each WONo in WONos using ','
*    ShipNos = Xlate('WO_LOG', WONo, 'SHIP_NO', 'X')
*    For Each ShipNo in ShipNos using @VM
*        COCRow      = Database_Services('ReadDataRow', 'COC', ShipNo)
*        Cassettes   = COCRow<COC_CASS_NO$>
*        For Each Cassette in Cassettes using @VM
*            WOMatKeyID  = WONo : '*' : Cassette
*            WOMatRow    = Database_Services('ReadDataRow', 'WO_MAT', WOMatKeyID)
*            If WOMatRow<WO_MAT_SHIP_NO$> EQ '' then
*                Log    := WONo : @VM : Cassette : @VM : ShipNo : @FM
*                WOMatRow<WO_MAT_SHIP_NO$>   = ShipNo
*                Database_Services('WriteDataRow', 'WO_MAT', WOMatKeyID, WOMatRow)
*            end
*        Next Cassette
*    Next ShipNo
* Next WONo
* 
* Debug
* 
* Return
* 
* 
* Debug
* call Activate_Save_Select('COC')
* EOF = False$
* Loop
*    ReadNext ShipNo else EOF = True$
* Until EOF
*    ShipRec = Database_Services('ReadDataRow', 'COC', ShipNo)
*    Database_Services('WriteDataRow', 'FTP_QUEUE', ShipNo, ShipRec<21>, True$, '', True$)
* Repeat
* 
* return

Debug

* SAPDelNos       = '81159268,81159269,81159270,81159484,81162527,87052828,87056093,87057263,87057268,87057302,87057826,87057828,87057829,87057994,87058617,87058704,87058709,97059199,97059200'
* SAPDelNos       = '87057263'
* MissingDelNos   = ''
* For Each SAPDelNo in SAPDelNos using ','
*    call Activate_Save_Select('COC')
*    Sentence    = 'SELECT COC WITH SAP_DEL_NO EQ ' : SAPDelNo
*    ClearSelect 0
*    rv  = Set_Status(0)
*    RList(Sentence, 5, '', '', '')
*    If @List_Active EQ 3 AND @RecCount GT 0 then
*        EOF = False$
*        Loop
*            ReadNext ShipNo else EOF = True$
*        Until EOF
*            ShipRec = Database_Services('ReadDataRow', 'COC', ShipNo)
*            If Error_Services('NoError') then
* 
*                eMailShipRec = ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DT')
*                sqParms = 'SHIP_EMAIL_QUEUE':@RM:ShipNo:@RM:@RM:eMailShipRec
*                obj_Tables('WriteRec',sqParms)
*                IF Get_Status(errCode) THEN
*                    obj_Tables('UnlockRec',sqParms)
*                END
*                cocParms    = 'COC':@RM:ShipNo
*        *        ShipRec     = obj_Tables('ReadRec',cocParms)
*                If Not(Get_Status(errCode)) then
*                    SendReason = 'Resubmit COC'
*                    SendDtm 	= ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DT')
*                    SendUser	= @User4
*                    TaskID      = RTI_Task_Submit('', 'PRINT_SHIPMENT_DEV', ShipNo, ShipRec, 1, True$)
*                    If TaskID NE 0 then
*                        Done    = False$
*                        Loop
*                            Status      = RTI_Task_Status(TaskID, TaskResponse)
*                            If (Status EQ 'COMPLETED') OR (Status EQ 'ERROR') then Done = True$
*                        Until Done
*                        Repeat
*                    end
*                    StatusError = Get_Status(errCode)
*                    If (Index(errCode, 'SHELLEXECUTE', 1)) NE 0 then StatusError = 0
*                    If Not(StatusError) then
*                        CurrTxCnt   = COUNT(ShipRec<COC_EMAIL_DTM$>,@VM) + (ShipRec<COC_EMAIL_DTM$> NE '')
*                        NewTxPos    = CurrTxCnt + 1
*                        ShipRec<COC_EMAIL_DTM$,NewTxPos>	= SendDtm
*                        ShipRec<COC_EMAIL_USER$,NewTxPos>	= SendUser
*                        ShipRec<COC_EMAIL_REASON$,NewTxPos>	= SendReason
*                        cocParms = FIELDSTORE(cocParms,@RM,4,0,ShipRec)
*                        obj_Tables('WriteOnlyRec',cocParms)
*                    end
*                end
*                
*            end
*        Repeat
*    end else
*        MissingDelNos  := SAPDelNo : ','
*    end
* Next SAPDelNo

Debug
        
Return


