Return to the RPG Tips
Eliminating I/O Indicator in ILE RPG
As of V4R2, you can totally eliminate the use of resulting indicators, such as ER (error), on your ILE RPG I/O statements.
Here's what you need to do:
a. Code the (E) opcode extender on the I/O statement, and do NOT code anything in the resulting indicator positions (71-76).
b. IMMEDIATELY after the I/O statement, code one or more tests or assignments using the following built-in functions (BIFs):
%Error -- instead of the ER indicator
%Eof(filename) -- instead of the EOF or BOF indicator
%Found(filename) -- instead of the NR indicator (the "found" condition is the opposite of the "no record" condition)
%Equal(filename) -- instead of the EQ indicator
These BIFs all return '1' if the condition is true or '0' if it's false. You can test or save this value.
The filename argument is optional for all the BIFs except %Error, which takes no argument. The following describes which opcode each BIF applies to when you don't specify a filename argument:
%Error -- the most recently executed opcode that specified the (E) opcode extender
%Eof -- the most recently executed Read, ReadC, ReadE, ReadP, ReadPE, or Write
%Found -- the most recently executed Chain, Delete, SetGT, SetLL, Check, CheckR, Scan, or Lookup
%Equal -- the most recently executed SetLL or Lookup
I recommend you always code an explicit filename argument where allowed to avoid checking the wrong file (or opcode) and to provide clearer documentation. Here's an example that uses two of these BIFs (view this code in fixed font):
*...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 MasterErr C EndSlYou can also use the following BIFs to get other I/O information:
%Open(filename) -- returns '1' if the file is open or '0' if the file is closed
%Status(filename) -- returns the most recent status for the specified file (same as the *Status field of the INFDS)
[report a broken link by clicking here]