Are repeated Val_Errors a problem?

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.
Post Reply
User avatar
HMJust
Posts: 51
Joined: Wed May 11, 2016 7:23 pm
Contact:

Are repeated Val_Errors a problem?

Post by HMJust » Thu Jan 03, 2019 9:27 pm

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.
I don't know what I am doing, nor how I did it. If it works, luck was involved :geek:

KevinW
Posts: 25
Joined: Thu May 26, 2016 11:18 am

Re: Are repeated Val_Errors a problem?

Post by KevinW » Fri Jan 04, 2019 9:27 am

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

User avatar
HMJust
Posts: 51
Joined: Wed May 11, 2016 7:23 pm
Contact:

Re: Are repeated Val_Errors a problem?

Post by HMJust » Fri Jan 04, 2019 10:00 pm

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.
I don't know what I am doing, nor how I did it. If it works, luck was involved :geek:

Post Reply