added triggers to calculate and store the scrapped quantity of a work order and auto close the work order when the scrap quantity and ship quantity equal the total work order quantity

added performance improvements to reduce unnecessary writes to the WO_LOG table
This commit is contained in:
Infineon\StieberD
2025-07-07 17:40:32 -07:00
parent 563871008e
commit 28d5b81b30
6 changed files with 179 additions and 72 deletions

View File

@ -14,7 +14,7 @@ Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""
// Parse record into a dimensioned array for speed
Dim Rec(85)
Dim Rec(86)
MatParse Record into Rec
// List of key names and their values
@ -58,6 +58,8 @@ DataFields := "ORIGIN" :@VM:SQL_Format(Rec(WO_LOG_ORIGIN$),
DataFields := "INCO_CODE" :@VM:SQL_Format(Rec(WO_LOG_INCO_CODE$), "STR"):@FM
DataFields := "HOT_FLAG" :@VM:SQL_Format(Rec(WO_LOG_HOT_FLAG$), "BIT"):@FM
DataFields := "CURR_STATUS_STATIC" :@VM:SQL_Format(Rec(WO_LOG_CURR_STATUS_STATIC$), "STR"):@FM
DataFields := "REL_QTY" :@VM:SQL_Format(Rec(WO_LOG_REL_QTY_STATIC$), "INT"):@FM
DataFields := "UNREL_QTY" :@VM:SQL_Format(Rec(WO_LOG_UNREL_QTY_STATIC$), "INT"):@FM
// Symbolics
DataFields := "START_DT" :@VM:SQL_Format({START_DT}, "DATE"):@FM
@ -69,9 +71,7 @@ DataFields := "CYCLE_TIME_WIP" :@VM:SQL_Format({CYCLE_TIME_WIP},
DataFields := "CYCLE_TIME_DELTA" :@VM:SQL_Format({CYCLE_TIME_DELTA}, "DEC", 1):@FM
DataFields := "CYCLE_TIME_QA_SHIP" :@VM:SQL_Format({CYCLE_TIME_QA_SHIP}, "DEC", 1):@FM
DataFields := "CYCLE_TIME_REL_FIRST_VER":@VM:SQL_Format({CYCLE_TIME_REL_FIRST_VER}, "DEC", 1):@FM
DataFields := "SAP_TOT_WFR_QTY" :@VM:SQL_Format({SAP_TOT_WFR_QTY}, "STR"):@FM
DataFields := "REL_QTY" :@VM:SQL_Format({REL_QTY}, "INT"):@FM
DataFields := "UNREL_QTY" :@VM:SQL_Format({UNREL_QTY}, "INT")
DataFields := "SAP_TOT_WFR_QTY" :@VM:SQL_Format({SAP_TOT_WFR_QTY}, "STR")
// Write the data to the SQL database
Ans = SQL_Write(Connection, "WO_LOG", Keys, DataFields)

View File

@ -77,7 +77,7 @@ Declare function Database_Services, obj_NCR, obj_SAP, Environment_Services, L
Declare function obj_WO_Mat, obj_RDS, Error_Services, MemberOf, SRP_Array
Declare subroutine Error_Services, Database_Services, obj_NCR, obj_SAP, Material_Services, Work_Order_Services
Declare subroutine Logging_Services, Set_Status, obj_WO_Mat, obj_WO_Mat_Log, Schedule_Services, obj_Tables
Declare subroutine obj_RDS, SAP_Services, Pass_To_SQL, NCR_Services
Declare subroutine obj_RDS, SAP_Services, Pass_To_SQL, NCR_Services, Service_Services
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\NCR'
LogDate = Oconv(Date(), 'D4/')
@ -261,15 +261,22 @@ return
WRITE_RECORD:
// NCR quantity may have changed, so update RDS data in SCRAPE.
NCRNo = @ID
NewQty = Sum(obj_NCR('RejQty',NCRNo:@RM:Record))
OrgQty = Sum(obj_NCR('RejQty',NCRNo:@RM:OrigRecord))
WorkOrderNo = {WO_NO}
// NCR quantity may have changed, so update RDS data in SCRAPE DB as well as the total scrap qty in the work order.
RDSNos = {RDS_ID}
For each RDSNo in RDSNos using @VM setting vPos
Pass_To_SQL('WRITE', 'RDS', RDSNo)
Next RDSNo
If (OrgQty NE NewQty) then
Service_Services('PostProcedure', 'WORK_ORDER_SERVICES', 'UpdateScrappedQty':@VM:WorkOrderNo)
end
// On the write of the record, read then write associated WM_IN and WM_OUT records to trigger the WM_MFS.
// This will update their current status within the associated WO_MAT record.
WorkOrderNo = {WO_NO}
ReactorType = XLATE('WO_LOG', WorkOrderNo, 'REACT_TYPE', 'X')
ReactorType = Field(ReactorType, @VM, 1)
CassNo = {WO_MAT_CASS_NO}
@ -302,14 +309,10 @@ WRITE_RECORD:
CassStatus = Xlate('RDS', RDSNo, 'CURR_STATUS', 'X')
END
// add SAP transaction
NCRNo = @ID
NewQty = Sum(obj_NCR('RejQty',NCRNo:@RM:Record))
// Add SAP transaction
IF OrigRecord = '' THEN
TransQty = NewQty
END ELSE
OrgQty = Sum(obj_NCR('RejQty',NCRNo:@RM:OrigRecord))
TransQty = NewQty - OrgQty
END
IF TransQty NE 0 THEN
@ -662,7 +665,6 @@ WRITE_RECORD:
end
end
end
return
DELETE_RECORD_PRE:
@ -743,6 +745,8 @@ DELETE_RECORD:
Pass_To_SQL('WRITE', 'RDS', RDSNo)
Next RDSNo
Service_Services('PostProcedure', 'WORK_ORDER_SERVICES', 'UpdateScrappedQty':@VM:WorkOrderNo)
return
@ -808,3 +812,4 @@ LogRecord:
return

View File

@ -870,12 +870,12 @@ WRITE_RECORD:
Service_Services('PostProcedure', 'RDS_SERVICES', 'PushSigProfileToWoMat':@VM:Name)
WONo = Record<RDS_WO$>
OrigDateOut = OrigRecord<RDS_DATE_OUT$>
NewDateOut = Record<RDS_DATE_OUT$>
If ( ( (OrigDateOut EQ '') and (NewDateOut NE '') ) ) then
// Mark this cassette as processed in the schedule event record
WONo = Record<RDS_WO$>
DatetimeOut = {DATETIME_OUT}
ReactType = Xlate('WO_LOG', WONo, 'REACT_TYPE', 'X')
EpiPro = (ReactType EQ 'EPP')
@ -891,6 +891,12 @@ WRITE_RECORD:
end
end
OrigPocketChar = OrigRecord<RDS_POCKET_CHAR$>
NewPocketChar = Record<RDS_POCKET_CHAR$>
If (OrigPocketChar NE NewPocketChar) then
Service_Services('PostProcedure', 'WORK_ORDER_SERVICES', 'UpdateScrappedQty':@VM:WONo)
end
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)

View File

@ -920,37 +920,42 @@ end service
Service UpdateReleasedQty(WONo)
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\WO_LOG'
LogDate = Oconv(Date(), 'D4/')
LogTime = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Update Released Qty Log.csv'
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objUpRelLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
ErrorMsg = ''
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\WO_LOG'
LogDate = Oconv(Date(), 'D4/')
LogTime = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Update Released Qty Log.csv'
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objUpRelLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
RelQty = ''
UnRelQty = ''
OrigRelQty = ''
OrigUnRelQty = ''
ErrorMsg = ''
If WONo NE '' then
If RowExists('WO_LOG', WONo) then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
RelQty = obj_WO_Log('RelQty', WONo:@RM:WORec)
WOQty = WORec<WO_LOG_QTY$>
RelQty = obj_WO_Log('RelQty', WONo:@RM:WORec)
WOQty = WORec<WO_LOG_QTY$>
If RelQty GT WOQty then
UnRelQty = 0
end else
UnRelQty = WOQty - RelQty
end
Open 'WO_LOG' to hTable then
WriteV RelQty on hTable, WONo, WO_LOG_REL_QTY_STATIC$ then
WriteV UnRelQty on hTable, WONo, WO_LOG_UNREL_QTY_STATIC$ else
ErrorMsg = 'Error in ':Service:' service. Failed to write unreleased quantity ':UnRelQty
ErrorMsg := ' to the UNREL_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
Read WORec from hTable, WONo then
OrigRelQty = WORec<WO_LOG_REL_QTY_STATIC$>
OrigUnRelQty = WORec<WO_LOG_UNREL_QTY_STATIC$>
If ( (OrigRelQty NE RelQty) or (OrigUnRelQty NE UnRelQty) ) then
WORec<WO_LOG_REL_QTY_STATIC$> = RelQty
WORec<WO_LOG_UNREL_QTY_STATIC$> = UnRelQty
Write WORec on hTable, WONo else
ErrorMsg = 'Error in ':Service:' service. Failed to write unreleased quantity ':UnRelQty
ErrorMsg := ' and/or UNREL_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to write released quantity ':RelQty
ErrorMsg := ' to the REL_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to open the WO_LOG table.'
@ -994,18 +999,25 @@ Service UpdateReceivedQty(WONo)
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objUpRecLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
ErrorMsg = ''
RXQty = ''
OrigRXQty = ''
ErrorMsg = ''
If WONo NE '' then
If RowExists('WO_LOG', WONo) then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
RXQty = obj_WO_Log('RxQty', WONo:@RM:WORec)
Open 'WO_LOG' to hTable then
WriteV RXQty on hTable, WONo, WO_LOG_RX_QTY_STATIC$ else
ErrorMsg = 'Error in ':Service:' service. Failed to write received quantity ':RXQty
ErrorMsg := ' to the RX_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
ReadV OrigRXQty from hTable, WONo, WO_LOG_RX_QTY_STATIC$ then
If OrigRXQty NE RXQty then
WriteV RXQty on hTable, WONo, WO_LOG_RX_QTY_STATIC$ else
ErrorMsg = 'Error in ':Service:' service. Failed to write received quantity ':RXQty
ErrorMsg := ' to the RX_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Error reading RX_QTY_STATIC column from WO_LOG ':WONo:'.'
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to open the WO_LOG table.'
@ -1047,18 +1059,25 @@ Service UpdateShippedQty(WONo)
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objUpShipLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
ErrorMsg = ''
ShipQty = ''
OrigShipQty = ''
ErrorMsg = ''
If WONo NE '' then
If RowExists('WO_LOG', WONo) then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
ShipQty = obj_WO_Log('ShipQty', WONo:@RM:WORec)
Open 'WO_LOG' to hTable then
WriteV ShipQty on hTable, WONo, WO_LOG_SHIP_QTY_STATIC$ else
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ShipQty
ErrorMsg := ' to the SHIP_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
ReadV OrigShipQty from hTable, WONo, WO_LOG_SHIP_QTY_STATIC$ then
If OrigShipQty NE ShipQty then
WriteV ShipQty on hTable, WONo, WO_LOG_SHIP_QTY_STATIC$ else
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ShipQty
ErrorMsg := ' to the SHIP_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Error reading SHIP_QTY_STATIC column from WO_LOG ':WONo:'.'
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to open the WO_LOG table.'
@ -1093,6 +1112,73 @@ Service UpdateShippedQty(WONo)
end service
Service UpdateScrappedQty(WONo)
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\WO_LOG'
LogDate = Oconv(Date(), 'D4/')
LogTime = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' Update Scrapped Qty Log.csv'
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objUpScrapLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime
ScrapQty = ''
OrigScrapQty = ''
ErrorMsg = ''
If WONo NE '' then
If RowExists('WO_LOG', WONo) then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
EpiProFlag = Xlate('WO_LOG', WONo, 'EPI_PRO_FLAG', 'X')
If EpiProFlag then
ScrapQty = Xlate('WO_STEP', WONo:'*1', 'TOT_REJ_TOTAL', 'X')
end else
ScrapQty = Sum(Xlate('WO_LOG', WONo, 'WO_MAT_SAP_CONFIRM_SCRAP', 'X'))
end
Open 'WO_LOG' to hTable then
ReadV OrigScrapQty from hTable, WONo, WO_LOG_SCRAP_QTY_STATIC$ then
If OrigScrapQty NE ScrapQty then
WriteV ScrapQty on hTable, WONo, WO_LOG_SCRAP_QTY_STATIC$ else
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ScrapQty
ErrorMsg := ' to the SCRAP_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Error reading SCRAP_QTY_STATIC column from WO_LOG ':WONo:'.'
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to open the WO_LOG table.'
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
end
end else
ErrorMsg = 'Error in ':Service:' service. ':WONo:' does not exist in the WO_LOG table.'
end
end else
ErrorMsg = 'Error in ':Service:' service. Null WONo passed into service'
end
LogData = ''
LogData<1> = LoggingDtm
LogData<2> = WONo
If ErrorMsg EQ '' then
LogResult = 'Successfully updated WO_LOG record ':WONo:' field SCRAP_QTY_STATIC '
LogResult := 'with scrapped quantity ':ScrapQty:'.'
LogData<3> = LogResult
Logging_Services('AppendLog', objUpScrapLog, LogData, @RM, @FM)
end else
LogResult = 'Failed to update WO_LOG record ':WONo:' field SCRAP_QTY_STATIC with scrapped quantity '
LogResult := ScrapQty:'. Error message: ':ErrorMsg
LogData<3> = LogResult
Logging_Services('AppendLog', objUpScrapLog, LogData, @RM, @FM)
Error_Services('Add', ErrorMsg)
end
end service
Service ConvertRecordToJSON(WONo, Record, ItemURL)
jsonRecord = ''

View File

@ -1,6 +1,4 @@
Function WO_LOG_Actions(Action, CalcColName, FSList, Handle, Name, FMC, Record, Status, OrigRecord, Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10)
#pragma precomp SRP_PreCompiler
/***********************************************************************************************************************
This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
@ -43,7 +41,7 @@ Function WO_LOG_Actions(Action, CalcColName, FSList, Handle, Name, FMC, Record,
03/26/11 dmb Add logic to save and restore @FILE.ERROR
***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
$insert APP_INSERTS
$insert FILE.SYSTEM.EQUATES
$insert ACTION_SETUP
@ -56,7 +54,7 @@ $insert SCHED_DET_NG_EQUATES
Equ Comma$ to ','
Declare function Error_Services, Database_Services, Environment_Services, Logging_Services, obj_WO_Mat, Datetime
Declare function GaN_Services, obj_WO_Log
Declare function GaN_Services, obj_WO_Log, SRP_Date
Declare subroutine Error_Services, Database_Services, Environment_Services, Logging_Services, Obj_SAP
Declare subroutine Logging_Services, Set_Status, Schedule_Services, Work_Order_Services, obj_Notes
Declare subroutine Schedule_Services
@ -225,6 +223,17 @@ WRITE_RECORD_PRE:
SaveRecord = Record
end
EntryDate = Record<WO_LOG_ENTRY_DATE$>
Today = Date()
YearsOpen = SRP_Date('YearSpan', EntryDate, Today, True$)
ScrapQty = Record<WO_LOG_SCRAP_QTY_STATIC$>
ShipQty = Record<WO_LOG_SHIP_QTY_STATIC$>
If ( ( (ScrapQty + ShipQty) GE NewQty ) or (YearsOpen GE 3) ) then
// Auto-close the work order
Record<WO_LOG_CURR_STATUS_STATIC$> = 'CL'
SaveRecord = Record
end
return
WRITE_RECORD:
@ -457,27 +466,27 @@ return
DELETE_RECORD_PRE:
// Log which user and computer station attempted to delete the record
LogData = ''
LogData<1> = LoggingDTM
LogData<2> = Name
LogData<3> = @User4
Logging_Services('AppendLog', objDeleteLog, LogData, @RM, @FM)
// Log which user and computer station attempted to delete the record
LogData = ''
LogData<1> = LoggingDTM
LogData<2> = Name
LogData<3> = @User4
Logging_Services('AppendLog', objDeleteLog, LogData, @RM, @FM)
// Send an LSL message to FI admins to alert them
Recipients = Xlate('SEC_GROUPS', 'OI_ADMIN', 'USER', 'X')
SentFrom = 'SYSTEM'
Subject = 'WO_LOG Delete Attempt'
Message = 'An attempt to delete WO_LOG record ':Name:' was made by ':@User4:'.'
AttachWindow = 'NDW_WO_LOG'
AttachKey = Name
SendToGroup = ''
// Send an LSL message to FI admins to alert them
Recipients = Xlate('SEC_GROUPS', 'OI_ADMIN', 'USER', 'X')
SentFrom = 'SYSTEM'
Subject = 'WO_LOG Delete Attempt'
Message = 'An attempt to delete WO_LOG record ':Name:' was made by ':@User4:'.'
AttachWindow = 'NDW_WO_LOG'
AttachKey = Name
SendToGroup = ''
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
// Stop the system from deleting the record
ActionFlow = ACTION_STOP$
// Stop the system from deleting the record
ActionFlow = ACTION_STOP$
return

View File

@ -95,4 +95,5 @@ Equ WO_LOG_SHIP_QTY_STATIC$ To 82
Equ WO_LOG_RX_STAMPS$ To 83
Equ WO_LOG_REL_STAMPS$ To 84
Equ WO_LOG_CURR_STATUS_STATIC$ To 85
Equ WO_LOG_SCRAP_QTY_STATIC$ To 86