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 ibm db2 client?

523


How do you select a row using indexes in db2?

647


Hello All, We have requirment to Replace BMC Db2 Load product thru CA FAST LOADPlus product. Do anyone have JCL to for FAST LOADPLUS and what all are thing need to take in consideration.

2324


Can one database have multiple instances?

583


Is it possible to alter a table – for example adding a column, when another user is accessing or updating some columns?

630






How does cobol compile db2 program?

610


Explain in detail about buffer manager and its functionalities?

567


What is buffer pool?

616


Explain db2.

620


How to access db2 tables in mainframe?

615


What is alias in db2?

572


How can we retrieve the total number of records in RPG & CLLE?

203


Is it possible to create an Instance in DB2 using DB2 Control Center ?

631


Mention the location where the output received from explain statement is stored.

632


Why do we use cursor?

599