View previous topic :: View next topic
|
Author |
Message |
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
I tried adding the code below ( inside 100-OPEN) to an existing DB2 program in order to eliminate -501s using the pattern in an IBM manual which uses "predicate' for the call: It fails at compile time with
IGYPS2121-S "READCUR" was not defined as a data-name.
But READCUR is defined in WS:
EXEC SQL
DECLARE READCUR CURSOR FOR
SELECT etc. etc.
Wondering if I can't use DB2 predicates for some reason ?
Code:
100-OPEN.
IF READCUR IS OPEN
EXEC SQL
CLOSE READCUR
END-EXEC
EXEC SQL
OPEN READCUR
END-EXEC
ELSE
EXEC SQL
OPEN READCUR
END-EXEC
END-IF |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Do you know about cursor WITH HOLD option?
Why do you want to code around-501?
Quote: |
IF READCUR IS OPEN |
This is not true you need to check SQLCODE against -501 in IF condition.
like
step1- open cursor
step2 - if <the cursor is already open> then check SQLCODE against -502 and do else do something end |
|
Back to top |
|
|
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
but my employer wants to prevent -501s and -502s..... not code logically in response to them. Why did you say "This is not true..." What is it that is not true " ? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Quote: |
but my employer wants to prevent -501s and -502s |
At first place one should not code around this sqlcode because the moment you are coding this means your programming logic is messed up badly and that needs to be fixed as ideally one should get these SQLCODES.
second "IF READCUR IS OPEN" this is not a valid COBOL sentence, it should only "IF READCUR IS TRUE" where you got to set READCUR when you get -501/-502. |
|
Back to top |
|
|
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
.... but the "OPEN" is taken from IBM's Manual on using DB2 predicates so I would think it would be right .......... |
|
Back to top |
|
|
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
........ so it just seems as though my COBOL or DB2 environment doesn't tolerate predicate usage.........although I admit throwing a '14' return code at compile time and saying that READCUR is undefined seems a weird way to make that point. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
John F Dutcher wrote: |
but my employer wants to prevent -501s and -502s..... not code logically in response to them. |
And next thing, they don't want to see +100 anymore...
Sheesh, DB2 generates these codes for a reason, why the flucking hell bend yourself backwards to avoid them?
Or is your employer in the business of cleaning fans? |
|
Back to top |
|
|
John F Dutcher
New User
Joined: 02 Apr 2008 Posts: 11 Location: Harrisburg, PA
|
|
|
|
.....that's what we do !!!
All that said...... I gather all agree...trying to test the state of the cursor
with DB2 predicates is not likely doable........ despite IBM manuals. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Quote: |
........ so it just seems as though my COBOL or DB2 environment doesn't tolerate predicate usage.........although I admit throwing a '14' return code at compile time and saying that READCUR is undefined seems a weird way to make that point. |
You are mixing COBOL and SQL statements. You need to clearly able to differentiate them. What you coded is in COBOL and not under "EXEC SQL" so you will get compilation errors and the reason is in my previous post.
Quote: |
.... but the "OPEN" is taken from IBM's Manual on using DB2 predicates so I would think it would be right .......... |
Please point us to the manual that said so. |
|
Back to top |
|
|
|