If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Simple Cursor has me stumped

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-10, 22:33
Balr14 Balr14 is offline
Registered User
 
Join Date: Sep 2002
Location: Wisconsin
Posts: 37
Simple Cursor has me stumped

Here's the cursor:

EXEC SQL DECLARE CUR01 CURSOR FOR
SELECT ACCT_NBR
FROM DKLDB001.USB_ACCOUNT
WHERE CLNT_ID = :W-CLNT-ID
FOR FETCH ONLY
I verified the format and content of both fields. I displayed the value in W-CLNT-ID and it matches 4 rows in the table.

CLNT_ID CHAR(8) NOT NULL
W-CLNT-ID PIC X(8).

When I fetch, I get a SQLCODE of 100.

If I remove the WHERE clause it works fine; it's a small table. I'm completly stumped, again.
Reply With Quote
  #2 (permalink)  
Old 11-03-10, 22:40
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Did you open the cursor?

Make sure you put the Declare Cursor in the Working Storage Section and not in the Procedure Divsion.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 11-03-10, 22:51
Balr14 Balr14 is offline
Registered User
 
Join Date: Sep 2002
Location: Wisconsin
Posts: 37
I'm no expert on DB2, but I thought the Cursor declaration can go anywhere after the host variables that it uses are defined; just so it's before the open. Like I said, if I remove the where clause it runs just fine, so there's nothing wrong with where it's declared or opened.

I tried moving it to working storage just in case.... same results. I should mention this cursor is in a stored procedure driven from WLM, just in case that matters.

Last edited by Balr14; 11-03-10 at 23:07.
Reply With Quote
  #4 (permalink)  
Old 11-04-10, 03:57
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Long shot:
- the variable W-CLNT-ID must be defined within a "begin declare" and "end declare" block .
- the variable W-CLNT-ID must be filled before the OPEN CURSOR.

Please check.
Reply With Quote
  #5 (permalink)  
Old 11-04-10, 08:24
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Balr14 View Post
I displayed the value in W-CLNT-ID and it matches 4 rows in the table.
That clearly is not so, otherwise the query would return results. If, for example, you are comparing something like '1234____' and '____1234' (underscores designate spaces), they may look the same on screen but will not match when compared by a computer.
Reply With Quote
  #6 (permalink)  
Old 11-04-10, 08:59
Balr14 Balr14 is offline
Registered User
 
Join Date: Sep 2002
Location: Wisconsin
Posts: 37
Quote:
Originally Posted by dr_te_z View Post
Long shot:
- the variable W-CLNT-ID must be defined within a "begin declare" and "end declare" block .
- the variable W-CLNT-ID must be filled before the OPEN CURSOR.

Please check.
Yes! I had the open in the wrong place. If you were closer, I'd kiss you!
Reply With Quote
  #7 (permalink)  
Old 11-04-10, 20:27
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Quote:
Originally Posted by Balr14 View Post
I'm no expert on DB2, but I thought the Cursor declaration can go anywhere after the host variables that it uses are defined; just so it's before the open. Like I said, if I remove the where clause it runs just fine, so there's nothing wrong with where it's declared or opened.

I tried moving it to working storage just in case.... same results. I should mention this cursor is in a stored procedure driven from WLM, just in case that matters.
It is better to put it in the Procedure Division since you will not be tempted to check the return code of the declare cursor statement (since it will not have a return code). For those who do check the return code of a Declare Cursor in COBOL, they are really checking the return code of the previous SQL statement, and that can lead to logic errors. I have seen this happen many times.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #8 (permalink)  
Old 11-05-10, 10:31
Balr14 Balr14 is offline
Registered User
 
Join Date: Sep 2002
Location: Wisconsin
Posts: 37
When I ran into this problem it was after 17 hours of working toward a noon deadline for delivering a "proof of concept" demo. I was dead tired and probably looked at that cursor and the open 20 times and never thought to look where I opened it. This was the last part I needed to complete my demo, so I beat my deadline by 1/2 hour.
Reply With Quote
  #9 (permalink)  
Old 11-09-10, 02:43
yijianlian yijianlian is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
In murky politics of Japan, should this result WOW Gold at least two things clear: Mr. Ozawa is not the force he and his supporters held him, yet he should be able to Buy WOW Gold pull longer the strings behind the scenes. He may have helped orchestrate the party's historic victory in last September, and set in train reforms helped to WOW Power Leveling end Japan's long history of domination of one party. But personally, he is, for most voters, like a swig dirty dirty dishwater-by financial scandal, lack of Aion Gold transparency and accountability: in short, a reminder of the nature of the final fantasy gil Policy hoping they get rid of last year
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On