Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Database cursor being automatically closed after COMMIT

Database cursor being automatically closed after COMMIT


A program that used to run fine under Net Express has been recompiled using Visual COBOL.
The program uses OpenESQL to do a EXEC SQL OPEN on a declared cursor and then proceeds into a loop that fetches each row from the cursor, potentially updating that row and executing an EXEC SQL COMMIT.

In Net Express this worked fine but in Visual COBOL the commit statement appears to be closing the cursor because the next fetch after the commit results in a sqlcode = -10000 Function Sequence Error.

What can I do to fix this? 


In Net Express the default setting for the SQL(BEHAVIOR) directive was UNOPTIMIZED while in Visual COBOL the default is now MAINFRAME.

When BEHAVIOR=MAINFRAME is used the default cursor handling is to close a cursor at the end of a transaction, which is signaled by a COMMIT or ROLLBACK.

To change this you can set BEHAVIOR to either UNOPTIMIZED or ANSI and the cursors will no longer be closed.

An alternative to this is to use the WITH HOLD phrase when declaring the cursor and then it will always keep the cursor open even when BEHAVIOR is set to MAINFRAME.





Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2014-04-25 20:59
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.