Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Variable for cursor names

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
ravikumar15

New User


Joined: 27 Mar 2006
Posts: 64

PostPosted: Sun Jul 17, 2016 7:08 am    Post subject: Variable for cursor names
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Sun Jul 17, 2016 12:54 pm    Post subject: Reply to: Variable for cursor names
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: 1715
Location: UK

PostPosted: Sun Jul 17, 2016 2:57 pm    Post subject:
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: 64

PostPosted: Sun Jul 17, 2016 10:49 pm    Post subject:
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

Senior Member


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

PostPosted: Mon Jul 18, 2016 10:53 am    Post subject:
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: 1529
Location: Andromeda Galaxy

PostPosted: Mon Jul 18, 2016 1:57 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts OPC JCL Variable passion_sujesh IBM Tools 5 Fri Jul 01, 2016 4:21 am
No new posts Using Field names in FILEAID Batch CO... Atul Banke Compuware & Other Tools 2 Wed Jun 29, 2016 9:54 pm
No new posts JOINKEYs and Variable files migusd SYNCSORT 8 Fri Jun 17, 2016 3:16 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us