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

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: 68

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: 7309
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: 2455
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: 68

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: 3048
Location: NYC,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

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top