Page 1 of 1

Are repeated Val_Errors a problem?

Posted: Thu Jan 03, 2019 9:27 pm
by HMJust
Running on iSeries in an RDML function I have

Code: Select all

FI2: Fetch Fields(#SIFAK) From_File(FIRCSP) With_Key(#SLAND)
Change Field(#SIFAK) To('#SIFAK + 1')
Update Fields(#SIFAK) In_File(FIRLSP) Io_Error(FI2) Val_Error(FI2)
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.

Re: Are repeated Val_Errors a problem?

Posted: Fri Jan 04, 2019 9:27 am
by KevinW
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.

Code: Select all

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 */   

Re: Are repeated Val_Errors a problem?

Posted: Fri Jan 04, 2019 10:00 pm
by HMJust
It appears to have solved my problem. Thank you!

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.