%ERROR function in RPG

1520 pts.
Tags:
%ERROR function
CHAIN(E)
RPG
RPG error handling
How to use % error built in function in rpgle program any code example please?

Answer Wiki

Thanks. We'll let you know when a new response is added.

%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.

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • 6r
    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?
    1,520 pointsBadges:
    report
  • Gilly400
    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.
    23,730 pointsBadges:
    report
  • 6r
    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.
    1,520 pointsBadges:
    report
  • 6r
    and is chaining through numeric value not allowed?
    1,520 pointsBadges:
    report
  • 6r
    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?
    1,520 pointsBadges:
    report
  • TopKat
    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
    135 pointsBadges:
    report
  • Pcatlin
    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
    200 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following