This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
I end up calling this function from the VLF and sometimes it fails. Through some debugging, I found that Val_Error was triggered (which would be logical in this situation) but then the code fails on the second run-through.
Is this possible? Am I missing something here? Or do you have a good suggestion how this could be done differently?
I need #SIFAK to be sequentially increased.
I don't know what I am doing, nor how I did it. If it works, luck was involved
I am assuming that the reason that your update fails is because of multiple instances of your code executing at once.
In the following code a successful Fetch Lock(*YES) serializes access to the "resource" so that only one instance at a time can:
1) Obtain the current value of #SIFAK for a particular key (#SLAND)
2) Increment #SIFAK
3) Update the record with that key.
F12: Fetch Fields(#SIFAK) From_File(FIRCSP) With_Key(#SLAND) Lock(*Yes) Io_Error(*Next)
If_Status Is_Not(*OK)
If Cond('*DBMS_RECORD_LOCKED = Y')
/* maybe do nothing or wait a second, or something else, then */
Goto Label(F12)
Else
/* Handle other I/O errors */
Endif
Endif
/* when we get to here we have the record locked and the update should be OK */
Change Field(#SIFAK) To('#SIFAK + 1')
Update Fields(#SIFAK) In_File(FIRLSP) Io_Error(*NEXT) Val_Error(*NEXT)
/* Deal with any I/O errors and Validation errors and possibly go back to F12 */
It also looks like my specific problem was solved just by the Lock(*Yes), but I have kept the checks in - as I like to know why something fails, should it again someday.
I don't know what I am doing, nor how I did it. If it works, luck was involved