Hi,
Sorry for the long post.
I am having a problem in my NetTalk Web App and wonder how everyone else is handling it.
This is what i have now:
In my stock program branches can request stock and a field (StkRequested) in the stock record is updated with the quantity.
The main store can also book in stock and the Quantity (InStock) is updated.
Stock can also be booked out to the branches and the “InStock” is updated as well as the “StkRequested”.
What I have seen is that when multiple branches are requesting stock and the store is booking stock in and out at the same time most of the time the “InStock” & “StkRequested” quantities goes completely wrong.
When the stock is booked in/requested I think it still uses the current value in memory and the addition and deduction is done on the currently loaded values.
My thinking is the record is loaded when the form opens and with multiple forms open by all the users I will have to use some sort of Record Locking (HOLD)
At this stage my code looks like this when I update the record:
StoreStock:Guid = BranchStoItmReq:StoreStockGuid
IF ACCESS:StoreStock.FETCH(StoreStock:Guid_Key) = LEVEL:BENIGN
StoreStock:QNTYForBookout -= p_web.GSV('OrgQNTYRequested')
StoreStock:QNTYForBookout += BranchStoItmReq:QNTYRequested
ACCESS:StoreStock.UPDATE()
END
I have read section in the manual on HOLD.
This is how I think I need to do it but any advice/correction would be appreciated.
LOOP !Loop to avoid "deadly embrace"
HOLD(StoreStock,1) !Arm Hold on view, primary record only,try for 1 second
StoreStock:Guid = BranchStoItmReq:StoreStockGuid
ACCESS:StoreStock.FETCH(StoreStock:Guid_Key) !Get and hold the record
IF ERRORCODE() = 43 !If someone else has it
CYCLE ! try again
ELSIF ACCESS:StoreStock.FETCH(StoreStock:Guid_Key) = LEVEL:BENIGN
StoreStock:QNTYForBookout -= p_web.GSV('OrgQNTYRequested')
StoreStock:QNTYForBookout += BranchStoItmReq:QNTYRequested
ACCESS:StoreStock.UPDATE()
BREAK !Break if not held
END
END
RELEASE(StoreStock)
Regards
Johan de Klerk