Added calls to verify indexes and update indexes right after receiving and releasing material. Refactored codebase to adjust work order quantities instead of recalculate quantities.

Removing reliance on transaction queue for receive and releaase

Added unlock call in case write fails
This commit is contained in:
Infineon\StieberD
2025-09-30 13:45:55 -07:00
parent a2f61d11c9
commit beaac0d38a
17 changed files with 1272 additions and 778 deletions

View File

@ -694,17 +694,27 @@ Service ReceiveCassette(WONo, ReceiveUser, LotNo, CassQty, SubPartNo, SubVendorC
ErrCode = ''
If Not(Get_Status(ErrCode)) then
WOMatKey = WONo:'*':CassNo
WOMatKey = WONo:'*':CassNo
Locate WOMatKey in WOMatKeys by 'AR' using @VM setting NewPos else
WOMatKeys<0, CassNo> = WOMatKey
Transaction_Services('PostWriteFieldTransaction', 'WO_LOG', WONo, WO_LOG_WO_MAT_KEY$, WOMatKey, CassNo)
ErrCode = ''
If Get_Status(ErrCode) then
ErrorMsg = 'Error in ':Service:' service. Error message: ':ErrCode
Done = False$
For AttemptNo = 1 to NUM_ATTEMPTS$
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo, True$)
If HaveLock then
WOMatKeys = Database_Services('ReadDataColumn', 'WO_LOG', WONo, WO_LOG_WO_MAT_KEY$)
WOMatKeys<0, CassNo> = WOMatKey
Database_Services('WriteDataColumn', 'WO_LOG', WONo, WO_LOG_WO_MAT_KEY$, WOMatKeys, True$, False$, False$)
If Error_Services('NoError') then Done = True$
end
Until Done
Next AttemptNo
If Not(Done) then
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
Transaction_Services('PostWriteFieldTransaction', 'WO_LOG', WONo, WO_LOG_WO_MAT_KEY$, WOMatKey, CassNo)
If Error_Services('HasError') then ErrorMsg = 'Error in ':Service:' service. Error message: ':Error_Services('GetMessage')
end
end
If (ErrorMsg EQ '') then
Recipients = ''
SentFrom = ReceiveUser
@ -795,7 +805,7 @@ Service ReleaseCassette(WOMatKey, ReleaseUser, RelDtm)
RelWONo = Field(WOMatKey, '*', 1, 1)
RelCassNo = Field(WOMatKey, '*', 2, 1)
Set_Status(0)
obj_WO_Log('ReleaseCassettes',RelWONo:@RM:RelCassNo:@RM:ReleaseUser:@RM:RelDtm)
obj_WO_Log('ReleaseCassette',RelWONo:@RM:RelCassNo:@RM:ReleaseUser:@RM:RelDtm)
errCode = ''
If Get_Status(errCode) then
ErrorMsg = 'Error in ':Service:' service. Error code ':errCode:'.'
@ -830,7 +840,7 @@ end service
Service ReceiveReleaseCassette(WONo, ReceiveUser, LotNo, CassQty, SubPartNo, SubVendorCode, RecDtm)
WOMatKey = ''
ErrorMsg = ''
Begin Case
@ -1080,37 +1090,46 @@ Service UpdateReleasedQty(WONo)
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$>
If Error_Services('NoError') then
OrigRelQty = WORec<WO_LOG_REL_QTY_STATIC$>
OrigUnRelQty = WORec<WO_LOG_UNREL_QTY_STATIC$>
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
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
end else
ErrorMsg = 'Error in ':Service:' service. Failed to open the WO_LOG table.'
end
If ( (OrigRelQty NE RelQty) or (OrigUnRelQty NE UnRelQty) ) then
Done = False$
For AttemptNo = 1 to NUM_ATTEMPTS$
If AttemptNo GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo)
If HaveLock then
WORec<WO_LOG_REL_QTY_STATIC$> = RelQty
WORec<WO_LOG_UNREL_QTY_STATIC$> = UnRelQty
Database_Services('WriteDataRow', 'WO_LOG', WONo, WORec, True$, False$, False$)
If Error_Services('NoError') then
// Note: WriteDataRow will have unlocked the record
Done = True$
end else
If AttemptNo GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write released quantity ':RelQty
ErrorMsg := ' to the REL_QTY_STATIC field of WO_LOG record ':WONo:'. '
ErrorMsg := 'Failed to write unreleased quantity ':UnRelQty:' to the UNREL_QTY_STATIC '
ErrorMsg := 'field of the WO_LOG record ':WONo:'. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
Until Done
Next AttemptNo
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
@ -1132,7 +1151,7 @@ Service UpdateReleasedQty(WONo)
Logging_Services('AppendLog', objUpRelLog, LogData, @RM, @FM)
end else
LogResult = 'Failed to update WO_LOG record ':WONo:' field REL_QTY_STATIC with released quantity ':RelQty
LogResult := ' or field UNREL_QTY_STATIC with unreleased quantity ':UnRelQty:'. Error message: ':ErrorMsg
LogResult := ' and field UNREL_QTY_STATIC with unreleased quantity ':UnRelQty:'. Error message: ':ErrorMsg
LogData<3> = LogResult
Logging_Services('AppendLog', objUpRelLog, LogData, @RM, @FM)
Error_Services('Add', ErrorMsg)
@ -1168,8 +1187,9 @@ Service AdjustReleasedQty(WONo, AdjustQty)
End Case
If (ErrorMsg EQ '' ) then
If RowExists('WO_LOG', WONo) then
Done = False$
For Attempt = 1 to NUM_ATTEMPTS$
If Attempt GT 0 then Delay(Attempt)
If Attempt GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo, True$)
If HaveLock then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
@ -1182,20 +1202,28 @@ Service AdjustReleasedQty(WONo, AdjustQty)
WORec<WO_LOG_REL_QTY_STATIC$> = RelQty
WORec<WO_LOG_UNREL_QTY_STATIC$> = UnRelQty
Database_Services('WriteDataRow', 'WO_LOG', WONo, WORec, True$, False$, False$)
If Error_Services('HasError') then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':RelQty:' on REL_QTY_STATIC '
ErrorMsg := 'field and ':UnrelQty:' on UNREL_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
If Error_Services('NoError') then
Done = True$
end else
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':RelQty:' on REL_QTY_STATIC '
ErrorMsg := 'field and ':UnrelQty:' on UNREL_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
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
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
If ( Not(HaveLock) and (Attempt GE NUM_ATTEMPTS$) ) then
ErrorMsg = 'Error in ':Service:' service. Failed to lock WO_LOG ':WoNo:' for update after ':Attempt:' attempts.'
end
Until HaveLock or (ErrorMsg NE '')
Until Done
Next Attempt
end else
ErrorMsg = 'Error in ':Service:' service. ':WONo:' does not exist in the WO_LOG table.'
@ -1230,44 +1258,44 @@ 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
RXQty = ''
OrigRXQty = ''
RxQty = ''
OpenQty = ''
ErrorMsg = ''
If WONo NE '' then
If RowExists('WO_LOG', WONo) then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
WOQty = WORec<WO_LOG_WO_QTY$>
RXQty = obj_WO_Log('RxQty', WONo:@RM:WORec)
OpenQty = WOQty - RXQty
Open 'WO_LOG' to hTable then
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
If ErrorMsg EQ '' then
ReadV OrigOpenQty from hTable, WONo, WO_LOG_OPEN_QTY_STATIC$ then
If OrigOpenQty NE OpenQty then
WriteV OpenQty on hTable, WONo, WO_LOG_OPEN_QTY_STATIC$ else
WOQty = WORec<WO_LOG_WO_QTY$>
OrigRxQty = WORec<WO_LOG_RX_QTY_STATIC$>
OrigOpenQty = WORec<WO_LOG_OPEN_QTY_STATIC$>
RxQty = obj_WO_Log('RxQty', WONo:@RM:WORec)
OpenQty = WOQty - RxQty
If ( (OrigRxQty NE RxQty) or (OrigOpenQty NE OpenQty) ) then
WORec<WO_LOG_RX_QTY_STATIC$> = RxQty
WORec<WO_LOG_OPEN_QTY_STATIC$> = OpenQty
Done = False$
For AttemptNo = 1 to NUM_ATTEMPTS$
If AttemptNo GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo)
If HaveLock then
Database_Services('WriteDataRow', 'WO_LOG', WONo, WORec, True$, False$, False$)
If Error_Services('NoError') then
// Note: WriteDataRow will have unlocked the record
Done = True$
end else
If AttemptNo GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write received quantity ':RXQty
ErrorMsg := ' to the OPEN_QTY_STATIC field of WO_LOG record ':WONo:'.'
ErrorMsg := '@FILE_ERROR: ':@FILE_ERROR
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Error reading OPEN_QTY_STATIC column from WO_LOG ':WONo:'.'
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to open the WO_LOG table.'
end
ErrorMsg := ' to the RX_QTY_STATIC field of WO_LOG record ':WONo:'. '
ErrorMsg := 'Failed to write open quantity ':OpenQty
ErrorMsg := ' to the OPEN_QTY_STATIC field of WO_LOG record ':WONo:'. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
Until Done
Next AttemptNo
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
@ -1283,12 +1311,15 @@ Service UpdateReceivedQty(WONo)
LogData<1> = LoggingDtm
LogData<2> = WONo
If ErrorMsg EQ '' then
LogData<3> = 'Successfully updated WO_LOG record ':WONo:' field RX_QTY_STATIC with received quantity ':RXQty:'.'
LogMsg = 'Successfully updated WO_LOG record ':WONo:' field RX_QTY_STATIC with received quantity ':RxQty:'.'
LogMsg := 'Successfully updated WO_LOG record ':WONo:' field OPEN_QTY_STATIC with open quantity ':OpenQty:'.'
LogData<3> = LogMsg
Logging_Services('AppendLog', objUpRecLog, LogData, @RM, @FM)
end else
LogResult = 'Failed to update WO_LOG record ':WONo:' field RX_QTY_STATIC with received quantity ':RXQty
LogResult := '. Error message: ':ErrorMsg
LogData<3> = LogResult
LogMsg = 'Failed to update WO_LOG record ':WONo:' field RX_QTY_STATIC with received quantity ':RxQty:'. '
LogMsg := 'Failed to update WO_LOG record ':WONo:' field OPEN_QTY_STATIC with open quantity ':OpenQty:'. '
LogMsg := 'Error message: ':ErrorMsg
LogData<3> = LogMsg
Logging_Services('AppendLog', objUpRecLog, LogData, @RM, @FM)
Error_Services('Add', ErrorMsg)
end
@ -1322,8 +1353,9 @@ Service AdjustReceivedQty(WONo, AdjustQty)
End Case
If (ErrorMsg EQ '' ) then
If RowExists('WO_LOG', WONo) then
Done = False$
For Attempt = 1 to NUM_ATTEMPTS$
If Attempt GT 0 then Delay(Attempt)
If Attempt GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo, True$)
If HaveLock then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
@ -1331,24 +1363,32 @@ Service AdjustReceivedQty(WONo, AdjustQty)
WOQty = WORec<WO_LOG_WO_QTY$>
OrigRxQty = WORec<WO_LOG_RX_QTY_STATIC$>
RxQty = OrigRxQty + AdjustQty
OpenQty = WOQty - RXQty
OpenQty = WOQty - RxQty
WORec<WO_LOG_RX_QTY_STATIC$> = RxQty
WORec<WO_LOG_OPEN_QTY_STATIC$> = OpenQty
Database_Services('WriteDataRow', 'WO_LOG', WONo, WORec, True$, False$, False$)
If Error_Services('HasError') then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':RxQty:' on RX_QTY_STATIC field '
ErrorMsg := 'and ':OpenQty:' on OPEN_QTY_STATIC to WO_LOG ':WONo:'. Error message: '
ErrorMsg := Error_Services('GetMessage')
If Error_Services('NoError') then
Done = True$
end else
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':RxQty:' on RX_QTY_STATIC field '
ErrorMsg := 'and ':OpenQty:' on OPEN_QTY_STATIC to WO_LOG ':WONo:'. Error message: '
ErrorMsg := Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
If ( Not(HaveLock) and (Attempt GE NUM_ATTEMPTS$) ) then
ErrorMsg = 'Error in ':Service:' service. Failed to lock WO_LOG ':WoNo:' for update after ':Attempt:' attempts.'
end
Until HaveLock or (ErrorMsg NE '')
Until Done
Next Attempt
end else
ErrorMsg = 'Error in ':Service:' service. ':WONo:' does not exist in the WO_LOG table.'
@ -1374,6 +1414,170 @@ Service AdjustReceivedQty(WONo, AdjustQty)
end service
Service AdjustScrappedQty(WONo, AdjustQty)
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] : ' Adjust Scrapped Qty Log.csv'
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objAdjScrapLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
RXQty = ''
OrigRXQty = ''
ErrorMsg = ''
Begin Case
Case (WONo EQ '')
ErrorMsg = 'Error in ':Service:' service. Null WONo passed into service'
Case (AdjustQty EQ '')
ErrorMsg = 'Error in ':Service:' service. Null AdjustQty passed into service'
Case Not(Num(AdjustQty))
ErrorMsg = 'Error in ':Service:' service. AdjustQty is not a number'
Case Index(AdjustQty, '.', 1)
ErrorMsg = 'Error in ':Service:' service. AdjustQty cannot be a decimal value'
Case Otherwise$
Null
End Case
If (ErrorMsg EQ '' ) then
If RowExists('WO_LOG', WONo) then
Done = False$
For Attempt = 1 to NUM_ATTEMPTS$
If Attempt GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo, True$)
If HaveLock then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
OrigScrapQty = WORec<WO_LOG_SCRAP_QTY_STATIC$>
ScrapQty = OrigScrapQty + AdjustQty
Database_Services('WriteDataColumn', 'WO_LOG', WONo, WO_LOG_SCRAP_QTY_STATIC$, ScrapQty, True$, False$, False$)
If Error_Services('NoError') then
// Note: WriteDataColumn will release the lock
Done = True$
end else
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ScrapQty:' on SCRAP_QTY_STATIC field. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end else
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
If ( Not(HaveLock) and (Attempt GE NUM_ATTEMPTS$) ) then
ErrorMsg = 'Error in ':Service:' service. Failed to lock WO_LOG ':WoNo:' for update after ':Attempt:' attempts.'
end
Until Done
Next Attempt
end else
ErrorMsg = 'Error in ':Service:' service. ':WONo:' does not exist in the WO_LOG table.'
end
end
LogData = ''
LogData<1> = LoggingDtm
LogData<2> = WONo
If ErrorMsg EQ '' then
LogResult = 'Successfully adjusted WO_LOG ':WONo:' scrapped quantity by ':AdjustQty
LogResult := '. Updated WO_LOG record ':WONo:' field SCRAP_QTY_STATIC with scrap quantity ':ScrapQty:'.'
LogData<3> = LogResult
Logging_Services('AppendLog', objAdjScrapLog, LogData, @RM, @FM)
end else
LogResult = 'Failed to adjust WO_LOG ':WONo:' scrapped quantity by ':AdjustQty
LogData<3> = LogResult
Logging_Services('AppendLog', objAdjScrapLog, LogData, @RM, @FM)
Error_Services('Add', ErrorMsg)
end
end service
Service AdjustShippedQty(WONo, AdjustQty)
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] : ' Adjust Shipped Qty Log.csv'
Headers = 'Logging DTM' : @FM : 'WONo' : @FM : 'Notes'
objAdjShipLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
RXQty = ''
OrigRXQty = ''
ErrorMsg = ''
Begin Case
Case (WONo EQ '')
ErrorMsg = 'Error in ':Service:' service. Null WONo passed into service'
Case (AdjustQty EQ '')
ErrorMsg = 'Error in ':Service:' service. Null AdjustQty passed into service'
Case Not(Num(AdjustQty))
ErrorMsg = 'Error in ':Service:' service. AdjustQty is not a number'
Case Index(AdjustQty, '.', 1)
ErrorMsg = 'Error in ':Service:' service. AdjustQty cannot be a decimal value'
Case Otherwise$
Null
End Case
If (ErrorMsg EQ '' ) then
If RowExists('WO_LOG', WONo) then
Done = False$
For Attempt = 1 to NUM_ATTEMPTS$
If Attempt GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo, True$)
If HaveLock then
WORec = Database_Services('ReadDataRow', 'WO_LOG', WONo)
If Error_Services('NoError') then
OrigShipQty = WORec<WO_LOG_SHIP_QTY_STATIC$>
ShipQty = OrigShipQty + AdjustQty
Database_Services('WriteDataColumn', 'WO_LOG', WONo, WO_LOG_SHIP_QTY_STATIC$, ShipQty, True$, False$, False$)
If Error_Services('NoError') then
// Note: WriteDataColumn will release the lock
Done = True$
end else
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ShipQty:' on SHIP_QTY_STATIC field. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end else
If Attempt GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
If ( Not(HaveLock) and (Attempt GE NUM_ATTEMPTS$) ) then
ErrorMsg = 'Error in ':Service:' service. Failed to lock WO_LOG ':WoNo:' for update after ':Attempt:' attempts.'
end
Until Done
Next Attempt
end else
ErrorMsg = 'Error in ':Service:' service. ':WONo:' does not exist in the WO_LOG table.'
end
end
LogData = ''
LogData<1> = LoggingDtm
LogData<2> = WONo
If ErrorMsg EQ '' then
LogResult = 'Successfully adjusted WO_LOG ':WONo:' shipped quantity by ':AdjustQty
LogResult := '. Updated WO_LOG record ':WONo:' field SHIP_QTY_STATIC with scrap quantity ':ShipQty:'.'
LogData<3> = LogResult
Logging_Services('AppendLog', objAdjShipLog, LogData, @RM, @FM)
end else
LogResult = 'Failed to adjust WO_LOG ':WONo:' shipped quantity by ':AdjustQty
LogData<3> = LogResult
Logging_Services('AppendLog', objAdjShipLog, LogData, @RM, @FM)
Error_Services('Add', ErrorMsg)
end
end service
Service UpdateShippedQty(WONo)
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\WO_LOG'
@ -1384,28 +1588,34 @@ Service UpdateShippedQty(WONo)
objUpShipLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$,',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
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
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.'
end
If Error_Services('NoError') then
OrigShipQty = WORec<WO_LOG_SHIP_QTY_STATIC$>
ShipQty = obj_WO_Log('ShipQty', WONo:@RM:WORec)
If OrigShipQty NE ShipQty then
Done = False$
For AttemptNo = 1 to NUM_ATTEMPTS$
If AttemptNo GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo)
If HaveLock then
Database_Services('WriteDataColumn', 'WO_LOG', WONo, WO_LOG_SHIP_QTY_STATIC$, ShipQty, True$, False$, False$)
If Error_Services('NoError') then
Done = True$
end else
If AttemptNo GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ShipQty
ErrorMsg := ' to the SHIP_QTY_STATIC field of WO_LOG record ':WONo:'. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
end
end
end
Until Done
Next AttemptNo
If Database_Services('IsKeyIDSelfLocked', 'WO_LOG', WONo) then Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
@ -1446,7 +1656,6 @@ Service UpdateScrappedQty(WONo)
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
@ -1458,21 +1667,29 @@ Service UpdateScrappedQty(WONo)
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
OrigScrapQty = WORec<WO_LOG_SCRAP_QTY_STATIC$>
If OrigScrapQty NE ScrapQty then
Done = False$
For AttemptNo = 1 to NUM_ATTEMPTS$
If AttemptNo GT 1 then Delay(1)
HaveLock = Database_Services('GetKeyIDLock', 'WO_LOG', WONo)
If HaveLock then
Database_Services('WriteDataColumn', 'WO_LOG', WONo, WO_LOG_SCRAP_QTY_STATIC$, ScrapQty, True$, False$, False$)
If Error_Services('NoError') then
// Note: WriteDataColumn will have unlocked the record
Done = True$
end else
If AttemptNo GE NUM_ATTEMPTS$ then
ErrorMsg = 'Error in ':Service:' service. Failed to write ':ScrapQty
ErrorMsg := ' to the SCRAP_QTY_STATIC field of WO_LOG record ':WONo:'. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
Database_Services('ReleaseKeyIDLock', 'WO_LOG', WONo)
end
end
end
Until Done
Next AttemptNo
end
end else
ErrorMsg = 'Error in ':Service:' service. Failed to read record ':WONo:' from the WO_LOG table. '
ErrorMsg := 'Error message: ':Error_Services('GetMessage')
@ -1569,6 +1786,8 @@ Service ConvertRecordToJSON(WONo, Record, ItemURL)
SRP_JSON(objChildCassette, 'SetValue', 'RelDtm', Date_Services('ConvertDateTimeToISO8601', WOMatRec<WO_MAT_REL_DTM$>))
SRP_JSON(objChildCassette, 'SetValue', 'RecUser', OConv(WOMatRec<WO_MAT_RX_BY$>, '[XLATE_CONV,LSL_USERS*FIRST_LAST]'))
SRP_JSON(objChildCassette, 'SetValue', 'RelUser', OConv(WOMatRec<WO_MAT_REL_BY$>, '[XLATE_CONV,LSL_USERS*FIRST_LAST]' ))
SRP_JSON(objChildCassette, 'SetValue', 'WMInKey', WOMatRec<WO_MAT_WMI_KEY$>)
SRP_JSON(objChildCassette, 'SetValue', 'WMOutKey', WOMatRec<WO_MAT_WMO_KEY$>)
SRP_JSON(objChildCassettes, 'Add', objChildCassette)
SRP_JSON(objChildCassette, 'Release')
end