%error returns *on if an error occured in the execution of the last applicable opcode (READs, CHAINs, SETLLs, WRITEs, TESTs, and CALLs, but not EVALs, etc. - basically i/o type opcodes).
In the case of READs and CHAINs, this means actual i/o type errors and not eof or no record found (they have their own BIFs.)
Once you have an "if %error" you can use a "if %status = ..." where ... is a particular error code number to try and handle the error in your program.
i used follwoing code to check use of %error but its not showing right output i am not able to understand why is it so but if i use % found this code works well pls review the following code.
fpf1 if e k disk
c 006 CHAIN(E) PF1
C IF %ERROR
C EXSR ERR
c else
C ‘no err’ dsply
c endif
c seton lr
c err begsr
c ‘err’ dsply
c endsr
and pf1 does contain 006(eid field of pf1 (pf) ) and still it goes in to err subroutine and displays ‘err’ where as it should have gone in to else part of above code and displayed no err.becouse EID(006) field of pf1 contains this value in this pf. pls tell me why its happening wrong?
Hi,
Is the eid field defined as numeric or character? You’re chaining with a numeric value. Try putting quotes around the 006 :-
c ’006′ CHAIN(E) PF1
Regards,
Martin Gilbert.
following is the DDS for pf1 Physical file.
R REC
ENAME 10
A EID 3P 0
A ESAL 3P
A K EID
and when i am putting value 888 for eid which doesn’t exist in pf1(pf) then also it shows noerr message and goes into the err subroutine of above mentioned code.
and is chaining through numeric value not allowed?
sorry as stated earlier i would like to correct my statement that it shows ‘no err ‘msg for 888 (eid value) which doesn’t exist in pf1 (pf) and displays else part of program coding.where as here it shd hav displayed err msg by executing err subroutine but it doesn’t work in this way why so?
I’ve had the same problem with %error. I generally use %found:
006 CHAIN PF1
if %found(PF1)
or
006 CHAIN PF1
If %found
This always works
The lack of a record in the file is not an error. That ‘s why the %error is *OFF after your example. An error would occur if you tried the CHAIN and the record was locked and the lock wasn’t released before the timeout occurred. (for example).
I always use the codes together:
chain (key) file;
IF %Found and NOT %error
do something interesting
ENDIF
Phil C