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
 

 

Getting error while Declaring Cursor in COBOL
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 3:24 pm    Post subject: Getting error while Declaring Cursor in COBOL
Reply with quote

Hi,

I am trying to declare below cursor in my cobol program :

Code:
EXEC SQL                                                       
   DECLARE FSU-CSR1 CURSOR WITH HOLD FOR                       
   SELECT DISTINCT                                             
          CUST_NUM                                             
   FROM CUD_CUD_IP_TCL_RTY                                     
   WHERE CLASS_REGIME_CDE  =       :LS-TAX-CLASS-REGIME-CODE   
   AND   RQSTR_ID          =       :LS-REQUESTOR-ID             
   AND   MSG_STAT_CDE      =       :LS-MSG-STATUS-CODE         
   AND   INDC_SRCH_RQST_TS <       :LS-INDICIA-SRCH-RQST-TS     
   AND   CUST_NUM          BETWEEN :WW-DB2-START-CUST-NO       
                           AND     :WW-DB2-END-CUST-NO         
   ORDER BY CUST_NUM ASC                                       
   FOR READ ONLY                                               
END-EXEC


When I am trying to open the same cursor via OPEN statment I am getting below error :

DSNH520I DSNHSMUD LINE 6450 COL 9 THE OPEN STATEMENT FOR CURSOR
"FSU-CSR1" IS INVALID BECAUSE THE CURSOR WAS DEFINED BY AN ALLOCATE
CURSOR STATEMENT

My OPEN Statement is

Code:
EXEC SQL
    OPEN FSU-CSR1     
END-EXEC   


Could someone please suggest why Cobol compiler treating this as a ALLOCATE statement rather than DECLARE and why it is giving this error?
Back to top
View user's profile Send private message

Naish

New User


Joined: 07 Dec 2006
Posts: 82
Location: UK

PostPosted: Wed Apr 11, 2012 3:45 pm    Post subject:
Reply with quote

Could you try renaming the cursor-name (removing hyphens) ?
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 3:47 pm    Post subject: Reply to: Getting error while Declaring Cursor in COBOL
Reply with quote

Hi,

I have already tried that and infact i could see another successful module having cursor name with hypens.

It should be to do with something else.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1738
Location: Bloomington, IL

PostPosted: Wed Apr 11, 2012 3:48 pm    Post subject:
Reply with quote

As the fine manual indicates, the declaration of the cursor is bad, so when you refer to it, DB2 assumes that you must have defined through ALLOCATE.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Wed Apr 11, 2012 3:48 pm    Post subject:
Reply with quote

Apparently, the problem is in the DECLARE:

Quote:
********************* Text Below Copyright (c) 2012, IBM *********************
DSNH520I

E csectname THE OPEN STATEMENT FOR CURSOR cursor-name IS INVALID BECAUSE THE
CURSOR WAS DEFINED BY AN ALLOCATE CURSOR STATEMENT

Explanation

The cursor was not successfully declared, so it was assumed to be defined by
an ALLOCATE CURSOR statement
. A cursor defined by an ALLOCATE CURSOR
statement is open after successful completion of the statement. Attempting to
OPEN an allocated cursor is an error.


However, I see nothing wrong with your query (but I'm not a DB2 expert).
Did you cut and paste the text ? Did you correct a typo on the way ?
Back to top
View user's profile Send private message
Naish

New User


Joined: 07 Dec 2006
Posts: 82
Location: UK

PostPosted: Wed Apr 11, 2012 4:18 pm    Post subject:
Reply with quote

DB2 @ our shop doesn't allow hyphens. This looks interesting; need to find out more.

Info here http://www.idug.org/p/fo/et/thread=22442 is for DB2 V8 Compatibility Mode. See if this helps.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Apr 11, 2012 4:23 pm    Post subject:
Reply with quote

nazishmirekar,

You have pickled your link. You should use the Preview button and click on the link before posting. I know, because I have done it myself. You have to replace the
http://your_URL.com bit with the URL you want.

I've no idea if your link would be considered on to a "competitor site".
Back to top
View user's profile Send private message
Naish

New User


Joined: 07 Dec 2006
Posts: 82
Location: UK

PostPosted: Wed Apr 11, 2012 4:35 pm    Post subject:
Reply with quote

icon_redface.gif

Moderators,

If this violates any of the rules could you please edit this? Now that its already more than "10 minutes" icon_wink.gif it doesn't allow me to edit my post.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Wed Apr 11, 2012 4:40 pm    Post subject: Reply to: Getting error while Declaring Cursor in COBOL
Reply with quote

Competitor or not, it provides a plausible reason for the error icon_smile.gif

And it reminded me why I always put my DECLARE CURSORs before the PROCEDURE DIVISION.
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 4:46 pm    Post subject: Reply to: Getting error while Declaring Cursor in COBOL
Reply with quote

Guys,

I have defined two cursors defined in the same module.


EXEC SQL
DECLARE FSUUSBCD-CSR CURSOR FOR
SELECT PRM_DATA
FROM CUD_PROG_PRM
WHERE PROC_ID = :CUD038-PROC-ID
END-EXEC

EXEC SQL
OPEN FSUUSBCD-CSR
END-EXEC

this is working fine

But

EXEC SQL
DECLARE FSU_CSR1 CURSOR WITH HOLD FOR
SELECT DISTINCT
CUST_NUM
FROM CUD_CUD_IP_TX_RPTY
WHERE CLASS_REGIME_CDE = :WW-DB2-REGIME-CODE
AND RQSTR_ID = :WW-DB2-RQSTR-ID
AND MSG_STAT_CDE = :WW-DB2-MSG-STS-CODE
AND INDC_SRCH_RQST_TS < :WW-DB2-IND-SRCH-TS
AND (CUST_NUM BETWEEN :WW-DB2-START-CUST-NO
AND :WW-DB2-END-CUST-NO)
ORDER BY CUST_NUM ASC
FOR READ ONLY
END-EXEC

gives error whild opening the cursor as below:

EXEC SQL

DSNH520I DSNHSMUD LINE 6452 COL 8 THE OPEN STATEMENT FOR CURSOR
"FSU_CSR1" IS INVALID BECAUSE THE CURSOR WAS DEFINED BY AN ALLOCATE
CURSOR STATEMENT

OPEN FSU_CSR1
END-EXEC
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 6:38 pm    Post subject:
Reply with quote

Hi Guys,

This cursor was declared in the procedure division.

Looking at a closer look i found that my COBOL program is structured in a way ( incorrect) that FETCH statement for above cursor is coming in the order prior to DECLARE.

The Execution order was proper i.e. DECLARE (which is not executable) then OPEN and Then FETCH.

But the sections were written a way that FETCH statement was prior in COBOL line ordering then DECLARE and OPEN.

Not sure if this was causing issue. Does COBOL compiler need code Liner number of DECLARE and OPEN lesser than that of FETCH ? and does this create similar issue if we not follow it ?

Any suggestions most welcome !
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 11, 2012 6:43 pm    Post subject:
Reply with quote

why don't you read the manuals?

yes the order matters,
and it is not for the cobol compiler, (come on at least pretend to think!)
it is for the db2 pre-compiler.

Declare must come first, physically, in a program.

after that, does not matter (open/fetch/close)
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 6:50 pm    Post subject:
Reply with quote

Hi,

Thanks for the reply.

I meant DB2-precompiler , (sorry, I should have been specific) was referring to the compilation of COBOL-DB2 program.

Could you please, direct me to the manual which says the DECLARE should PHYSICALLY come first for compilation of COBOL-DB2 program if a cursor is defined ?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Apr 11, 2012 7:00 pm    Post subject: Reply to: Getting error while Declaring Cursor in COBOL
Reply with quote

If I can wade through the material in the link that was posted for your benefit, I'm sure you can/should.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 11, 2012 7:53 pm    Post subject:
Reply with quote

here's the link: Cursors in COBOL and Fortran programs
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 8:06 pm    Post subject:
Reply with quote

Thanks a lot,

It makes sense. a limitation of a single pass COBOL precompiler!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 11, 2012 8:09 pm    Post subject:
Reply with quote

by the way vishalbshah,
there are about a dozen regulars here,
that have 20-30 years experience,
which means when we learned (60's, 70's)
there was only hardcopy manuals,
they cost,
so there was usually just 1 copy in the entire organization,
and a rookie had no business with one on his desk,
so we had to hide,and read read read read read
turn pages, read,, and hopefully remember
but we learned how to navigate thru ibm's manuals,

so if we say that the manual states such and such,
it is because we read it while inflicting paper cuts on our fingers
as we turned the pages.
not something you forget.

you need to spend a week-end each on cics, db2, cobol, z/os
just reading the manuals / not so much as to learn all of it
but remember that you saw something about a subject in this manual,
so you can go back later, if you need, and learn about it in detail.

not knowing the syntax for an sql as well as any restrictions,
gotcha's or whatever,
shows me someone who is not prepared to take this skill as a life course seriously,
or well.
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 8:11 pm    Post subject:
Reply with quote

Thanks a Lot,

it makes sense !

A typical one pass Precompiler limitation for Cursors in COBOL and Fortran programs.
Back to top
View user's profile Send private message
vishalbshah

New User


Joined: 01 Dec 2006
Posts: 61
Location: Pune

PostPosted: Wed Apr 11, 2012 8:19 pm    Post subject:
Reply with quote

Yes Sir,

I agree with you and I was dying to read something on this subject.
I think there was an issue with the link mentioned in the Forum which was not getting opened for some reason so i could not read it through which is why I have asked the link again.

I am only a beginner in this arena (moved out of world of electronics to Mainframe) and want to read and learn more!

I appreciate your help !

Thanks Again!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 11, 2012 8:21 pm    Post subject:
Reply with quote

thx,
but you don't have to quote the manual for anyone (especially twice).
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 -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts S922 Error yuvan ABENDS & Debugging 3 Fri Dec 02, 2016 6:58 pm
No new posts Invoke Webservice Fails with DFHPI100... divated CICS 2 Thu Nov 24, 2016 5:57 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


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