Midrange News for the IBM i Community


Posted by: deepthi
Cursors in SQLRPGLE
has no ratings.
Published: 29 May 2012
Revised: 23 Jan 2013 - 4104 days ago
Last viewed on: 19 Apr 2024 (8236 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Cursors in SQLRPGLE Published by: deepthi on 29 May 2012 view comments(1)

I am using cursor in one of my SQLRPGLE program; after I 'OPEN'ed the cursor, 'FETCH' the record and now if I don't specify the 'CLOSE' cursor command then what will be the result, will everything go fine at the end of the program (when *inlr is set to '1') or would it result in error?

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: DaleB
Premium member *
Reading, PA
Comment on: Cursors in SQLRPGLE
Posted: 11 years 10 months 20 days 22 hours 36 minutes ago
Edited: Tue, 29 May, 2012 at 12:46:30 (4343 days ago)

Not an error, exactly. It depends on your close cursor option, and whether or not you try to reuse the cursor. Typically I do a SET OPTION near the start of my code, along the lines of:

      /FREE
       // SQL "H-spec"
       Exec SQL SET OPTION CLOSQLCSR = *ENDMOD,
                           COMMIT    = *NONE,
                           DATFMT    = *ISO;

The other way is the CLOSQLCSR keyword on the CRTSQLRPGI command.

I should add that SQL cursor names are not local to a module; it's kind of, sort of, like a shared access path. I started including the module or procedure name as part of my cursor names, to ensure uniqueness. Of course, there may be times when you want to use the same cursor, but if you don't realize it's in play, it can be a real headache to debug.