Return to the RPG Tips
RPG IV Warning! Check %ERROR or %STATUS before other I/O BIFs
Here's an important piece of advice for RPG IV database programming. When you use RPG IV built-in functions (BIFs) to check the result of an I/O operation, be sure you check the %Error or %Status BIF first. If %Error is true ('1'), the value of the %Found, %Equal, and %Eof BIFs should be ignored. For example, if you attempt to read a record that's locked by another job, %Error returns true, but %Found returns false ('0'). Here's an example of properly sequenced tests:
*...1....+....2....+....3....+....4....+....5....+....6....+.... C SlcKey Chain (E) Master C Select C When %Error C ExSr MasterIOErr C When Not %Found( Master ) C ExSr MasterNFnd C Other C ExSr ProcMaster C EndSl Here's a different approach using the %Status BIF: *...1....+....2....+....3....+....4....+....5....+....6....+.... D FStsOK C Const( 0 ) D FStsNoKey C Const( 12 ) . . . C SlcKey Chain (E) Master C Select C When %Status( Master ) = FStsOK C ExSr ProcMaster C When %Status( Master ) = FStsNoKey C ExSr MasterNFnd C Other C ExSr MasterIOErr C EndSlA tip published by Wim van den Heuvel on the AS400 Network.
[report a broken link by clicking here]