For non-ILE program calls, the close SQL cursor (CLOSQLCSR) parameter
allows you to specify the scope of the following:
- The cursors
- The prepared statements
- The locks
When used properly, the CLOSQLCSR parameter can reduce the number
of SQL OPEN, PREPARE, and LOCK statements needed. It can also simplify applications
by allowing you to retain cursor positions across program calls.
- *ENDPGM
- This is the default for all non-ILE precompilers. With this option, a
cursor remains open and accessible only while the program that opened it is
on the call stack. When the program ends, the SQL cursor can no longer be
used. Prepared statements are also lost when the program ends. Locks, however,
remain until the last SQL program on the call stack has completed.
- *ENDSQL
- With this option, SQL cursors and prepared statements that are created
by a program remain open until the last SQL program on the call stack has
completed. They cannot be used by other programs, only by a different call
to the same program. Locks remain until the last SQL program in the call stack
completes.
- *ENDJOB
- This option allows you to keep SQL cursors, prepared statements, and locks
active for the duration of the job. When the last SQL program on the stack
has completed, any SQL resources created by *ENDJOB programs are still active.
The locks remain in effect. The SQL cursors that were not explicitly closed
by the CLOSE, COMMIT, or ROLLBACK statements remain open. The prepared statements
are still usable on subsequent calls to the same program.