abby13
22nd February 2008, 13:20
Hi I am doing an Inventory Adjustment using AFS calls for tdilc1120m000 and tdilc1121s000. Now my requirement is that if any of the inserts in tdilc1121s000
fails, all my previous inserts should get undone.However I am not able to find an API to aceive this. Can anybody help me please?
george7a
22nd February 2008, 13:52
Hi,
I have done a similar project before. I have been askedto "Check" if the given data will get into Baan successfully or not. They gave me a spec with many conditions and just if the data passed all the conditions I used AFS to insert it. When the AFS fails, they were stuck and they needed to insert the data manually and after that to to add more and more conditions to the spec.
I don't think that this is the best way (a long spec of conditions), but it did work at the end.
I hope it helps,
- George
mark_h
22nd February 2008, 15:18
There is a way to do this, but I do agree with George. I am not sure if this will work for you or not - what I do for an error in tdilc1121s000 is end session tdilc1121s000. It then falls back to tdilc1120m000, this leaves the transaction open. I then do a stpapi.delete on the open transaction. You can tell this is one of the first function servers I did because I still used the libraries created from ttstpcreatdll. Endpoint gets set based on the session that had the error (we are on A&D so we have three session to complete with the last one for pegging information)
function cleanup.processes(long end.point)
{
| Do not worry about delete messages errors above indicate the
| part will need to be reviewed.
| Variables.
string err(120)
| End.point 0 then problem with main session. No records to cleanup.
if(end.point = 0) then
tdilcf1120m000.end()
return
endif
| End.point 1 then not second session record to cleanup
if(end.point = 1) then
tdilcf1121s000.end()
|Return to main process and delete record.
tdilcf1120m000.delete(1,err)
tdilcf1120m000.end()
return
endif
| Error on third session.
f1101s10b.end()
stpapi.recover("tdilc1121s000",err)
tdilcf1121s000.end()
|
|| Delete main transaction record
tdilcf1120m000.delete(1,err)
tdilcf1120m000.end()
return
}
Now what this will not do is let you sucessfully complete other transactions in tdilc1120m000. Once they are completed there you need to do another tdilc1120m000 transaction reversing the first. This is a completely different beast to tackle.
abby13
25th February 2008, 06:27
Thanks George and Mark, I deleted the record in tdilc1120m000 if i encountered a failed insert in tdilc1121s000 and it worked.
abby13
25th February 2008, 06:29
Also one more question from my side...
which is the better approach
1 . to give direct api calls . Or
2. to generate dll that handles the api calls.
mark_h
25th February 2008, 16:02
Me - I use direct calls at this point in time. I find it better to see the actual command that is being executed. There is nothing wrong with the libraries, but originally I generated the libraries and used them. I switched a few years back because I got tired of opening the library to see what the call was - plus using the code it makes it easier to cut and paste. Just my opinion.
abby13
3rd March 2008, 11:23
Hi Mark and George,
Earlier i thought that the solution to deleted records in subsession and the main session was working but during testing i found that, in tdilc1121s000 if the third record that i insert failed then only the 2nd record is deleted and not the first one.I am posting the code for your reference.
Regards,
Abhijit
mark_h
3rd March 2008, 14:45
When falling back to tdilc1120m000 and doing a delete - doesn't that delete all the tdilc1121s000 records? If not then what you will have to do is use stpapi.browse commands to delete all the records. So for example you could do first.set, delete - then repeat until all the records are gone.
abby13
5th March 2008, 10:30
Hi,
Consider this scenario:
I have inserted two lines in the session tdilc1121s000 through AFS. Now before inserting the third line (running it in the debug mode) I block the location(say A001).Now it gives an error "Location blocked" and that record is not inserted.
Now when I try to do browse and delete by using first .view and then by ext.view then if the locations in the previous inserts is also A001. Then it does not allow to delete them.How to tackle this situation?
Thanking in advance
abby13
mark_h
5th March 2008, 15:31
Are you saying - that you insert two records successfully with A001 and then when you go to do the third record A001 is blocked? If this is correct the only thing I can think of is to lock the location record so that nobody can block it until you are through with transactions for that record. What are the odds of this happening when processing records in tdilc1121s000?
mark_h
5th March 2008, 15:52
I did think of something else - make it so 1 transaction results in 1 tdilc1121s000 records. That is how I do the transactions. Then the worst that happens is one transaction does not get posted and you do not have to worry about 3 transactions down running into an error. So for example if the total adjustment is 10 and you are not putting in 5 adjustments of 2. Treat each as a single adjustment. So my users know that if I am adjusting off 10 of a part from 5 locations the file holds 5 transactions. 1 complete transaction per location. The worst that happens is one transaction may not get processed - but I do check for blocked locations and cycle count orders first.
We actually use a session with a table to load the transactions. So the user gives us a file, we load it into the session, click process. This processes and archives the transactions. If it errors the session displays the errors. At that point we can fix the error(unblock location, etc.) and reprocess the transaction. In reality what happens is the user processes these manually.