IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

Variable for cursor names


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

New User


Joined: 27 Mar 2006
Posts: 66

PostPosted: Sun Jul 17, 2016 7:08 am
Reply with quote

I have a requirement where I need to declare a cursor for the same table in two different conditions.

Condition 1:
With Where clause having only one column,

Condition 2:
When the date field in the input file is having value then include additional date field also in the where clause.

For this, I would like to pass the Cursor name to a variable and using that variable, declare the cursor after checking the date field from input file.

If the date field is blank declare, open, fetch, close Cursor-A
if the date field is non blank declare, open, fetch, close Cursor-B

Code:
If IN-DATE-1 = SPACES
   Move 'CURSOR-A' to WS-CURSOR-NAME
ELSE
   Move 'CURSOR-B' to WS-CURSOR-NAME

DECLARE :WS-CURSOR-NAME
where column-1 = :ws-column1

DECLARE :WS-CURSOR-NAME
where column-1 = :ws-column1
    and date-1 = :IN-DATE-1


Can the cursor name in DECLARE statement be a field which contains a value?

Is there any other option for this.

Any suggestion would be of great help.

Thanks in advance
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7312
Location: Inside the Matrix

PostPosted: Sun Jul 17, 2016 12:54 pm
Reply with quote

Have you considered consulting a manual for DB2 SQL?

How. Would. That. Work. ?

How would it even give you anything useful (you've missed any reasoning for why you want this)?

What problem is declaring two cursors giving you?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2432
Location: Hampshire, UK

PostPosted: Sun Jul 17, 2016 2:57 pm
Reply with quote

A similar question was asked a few months ago - did you search the forum? OK - it may have been another forum but a Google search may have thrown up the topic.
Back to top
View user's profile Send private message
ravikumar15

New User


Joined: 27 Mar 2006
Posts: 66

PostPosted: Sun Jul 17, 2016 10:49 pm
Reply with quote

I tried to search in Google, but I did not get anything. If you can provide me the link, that would be great.

Thanks
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2508
Location: NY,USA

PostPosted: Mon Jul 18, 2016 10:53 am
Reply with quote

If you try with what you did then you would know if works or gives error. Explore more on dynamic SQL.
But simple UNION will do what you want in a single cursor and if it gives any type of performance issue then follow Bills way of simply declaring two separate cursors.
Please prefer using code tags.
Back to top
View user's profile Send private message
Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1566
Location: Andromeda Galaxy

PostPosted: Mon Jul 18, 2016 1:57 pm
Reply with quote

Why not have two different cursor?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts Unable to display comp variable COBOL Programming 4
No new posts IWS/TWS build dinamic or variable APp... IBM Tools 0
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 Determine what library member is in, ... JCL & VSAM 9

Back to Top