Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003

    Unanswered: cursor declaration...

    I have a small doubt regarding declaration of cursor.

    1. Can one declare cursor in procedure division :?:
    2. If one can declare a cursor in procedure division then does it differ from one which is declared in working storage :?: ...if differs how :?:

  2. #2
    Join Date
    Sep 2003
    Yes, U can Declare the Cursor either in Working Storage/Procedure division and it does not matter where you define and there is no difference

  3. #3
    Join Date
    May 2003
    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.
    Last edited by Marcus_A; 09-02-03 at 19:20.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts