Cursors can be declared in both working-storage & procedure
division, Agreed.
But is there any difference? If could you please suggest
what is the difference.
TIA

Answer Posted / arthi

Please refer the answer by Marcus_A here:
http://www.dbforums.com/db2/896592-cursor-declaration.html

This is the most concise answer I could find on the net, and it proves that there is no difference in the placement of the declare cursor.

Quoting from the page:

==============
The Declare Cursor SQL statement is not a procedural SQL statement. It is actually part of the Open statement for the Cursor it refers to, and can be placed anywhere in program source code as long as it is physically before the Open SQL statement. It can actually be placed in the Identification Division, although traditionally it is placed in the Working Storage Section.

If you were to examine the compile listing of your program, you will see that the DB2 pre-compiler did not generate a separate call to DB2 for the Declare Cursor (since it is really part of the Open statement for that Cursor).

The problem with placing the Declare Cursor in the Procedure Division is that programmers invariably place code right after the Declare Cursor to check the SQL return code. So what ends up happening is that the SQL code of a previously executed SQL statement gets checked by the program, and if a non-zero return code is acceptable (not an abend condition) for a previous Select statement (such as return code +100), then the program will get confused and often think an abend condition has occurred.

So, if you do put the Declare cursor in the Procedure Division (not a good idea in my opinion) then make absolutely sure that no user code is executed to check the SQL return code for Declare Cursor.

==============

Is This Answer Correct ?    11 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the maximum size of varchar data type in db2?

645


How to compare data between two tables in db2?

658


what is the sqlcode -501

11303


How can you do the explain of a dynamic sql statement?

635


What is catalog database in db2?

646






Which isolation level provides maximum concurrency?

666


How to execute stored procedures?

620


What is db2? Explain.

606


What are the full forms of spufi and dclgen and why are they used?

656


How and when does the db2 enforces the unique key?

615


Explain about rct.

648


Hi Everyone... Under the Logical files, when am working on multiple rec format logical file, I have joined two pf's using the multiple record format logical file concept, but when i run queried the LF only the first mentioned pf records are reflecting and I am not able to see any of the field records specified under the second pf. Kindly let me know whats the reason behind this. Below is the str of LF., R rec PFILE(LOGICAA) CUSTNO CUSTNAME BILL K CUSTNO R rec1 PFILE(LOGICAA1) CUSTNO ADD K CUSTNO .....

1897


What is the use of value function?

627


Explain about open switch business continuity software?

563


What is deadlock in db2?

579