View previous topic :: View next topic
|
Author |
Message |
mahi
New User
Joined: 04 Apr 2006 Posts: 86 Location: Hyderabad
|
|
|
|
Hi All,
I am trying to declare a cursor in the procedure division, but it is giving error.
I have declared the same cursor in the Working storage section and it is working fine.
Can any body pls tell me the reason. |
|
Back to top |
|
|
Krishna Velamur
New User
Joined: 22 Aug 2008 Posts: 22 Location: Hyderabad
|
|
|
|
Hi Mahi,
You should be able to declare cursor in procedure division as well as working storage section. Could you please provide more details reg the error. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you probably have your open or fetch sql phyically before the cursor declaration
even though you maybe performing the declare before you perform the open. |
|
Back to top |
|
|
mahi
New User
Joined: 04 Apr 2006 Posts: 86 Location: Hyderabad
|
|
|
|
No.. I have the open fetch statements after the Declare only...I am getting the error CURSOR "PROD-LDCACCT" WAS NOT DECLARED
... |
|
Back to top |
|
|
mahi
New User
Joined: 04 Apr 2006 Posts: 86 Location: Hyderabad
|
|
|
|
hi dICK,
Sorry...
Yes ...Physically the declare statement is after the OPen statement...
How does this effects the Cursor declaration |
|
Back to top |
|
|
rpuhlman
New User
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
|
|
|
|
Hi Mahi,
Quote: |
How does this effects the Cursor declaration
|
Exactly as the results have shown:
Quote: |
CURSOR "PROD-LDCACCT" WAS NOT DECLARED
|
It is not an executable statement.
As Dick indicated, the cursor declaration must be PHYSICALLY located above/before the OPEN cursor statement. Best practices are to either declare the cursor in working storage OR immediately before your open cursor statement. Just be consistent and/or follow your shop standards.
Rick |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
The db2 pre-compiler builds its 'working table information' based on a first come first served.
I does not 'look ahead' or take program logic into consideration
therefore, suggest you follow Rick's advice. |
|
Back to top |
|
|
mahi
New User
Joined: 04 Apr 2006 Posts: 86 Location: Hyderabad
|
|
|
|
Thank You all... I have changed the code as per Dick's Suggesion & is working fine..
Thank You Dick.... |
|
Back to top |
|
|
|