IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Cursor Declaration


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sunojsm
Warnings : 1

New User


Joined: 21 Jun 2004
Posts: 33
Location: Andorra

PostPosted: Wed Jun 08, 2011 3:24 pm
Reply with quote

Hi,

Consider the following example.

EXEC SQL
DECLARE CURSOR1 CURSOR FOR
SELECT
COL_ONE
COL_TWO,
COL_THREE,
COL_FOUR
COL_FIVE

FROM TABLE1

WHERE EMPSEC =:WS-EMPSEC

WITH UR
END-EXEC.

EXEC SQL
FETCH CURSOR1
INTO
:WS-COL-ONE
,:WS-COL-TWO
,:WS-COL-THREE
,:WS-COL-FOUR ---> DECIMAL(2,0)
,:WS-COL-FIVE ---> DECIMAL(3,0)
END-EXEC.


In above statements,you can see there is no comma between COL_FOUR and COL_FIVE in DECLARE.

I noted this while debugging the program which is there in production.

Is that declaration is valid ?
How it went fine with out showing any syntax error during precompilation process?

When i checked the value in WS-COL-FOUR it shows as 3 which was correct(value same as in table1),but in WS-COL-FIVE ,
it shows 000 instead of '2' which is the value in table1 for that column. Could anyone let me know what exactly happening here.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Jun 08, 2011 4:38 pm
Reply with quote

select col1 col2 from
is the same as
select col1 as col2 from
it doesn't matter that col2 is also a column name.

I would have thought that the precompiler would say something like "number of columns in fetch are not equal to columns in cursor". but I'm not sure.
Back to top
View user's profile Send private message
sunojsm
Warnings : 1

New User


Joined: 21 Jun 2004
Posts: 33
Location: Andorra

PostPosted: Wed Jun 15, 2011 2:58 pm
Reply with quote

hi GuyC,

The AS concept is correct and i didnt get any error or warning for this while binding or compiling. Still finding an answer for this.


Thanks
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Is SQLCODE -811 possible while fetchi... DB2 1
No new posts Restart logic by using cursor name in... DB2 1
No new posts Seeking Resolution for SQKCODE -991 o... DB2 2
No new posts Multiple rows within Cursor when Coun... DB2 14
No new posts Dynamic cursor name in Cobol program COBOL Programming 1
Search our Forums:

Back to Top